Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复swiper在item数量太少时无法循环的问题 #16737

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class SwiperInner extends React.Component<SwiperProps, SwiperState> {
}

const loopAdditionalSlides = this.getLoopAdditionalSlides()
const centeredSlides = parseFloat(String(displayMultipleItems)) === 1
const centeredSlides = displayMultipleItems === 1 && this.getNeedFixLoop()
const slidesPerView = parseFloat(String(displayMultipleItems)) === 1 ? 'auto' : displayMultipleItems
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that = this
Expand Down Expand Up @@ -461,11 +461,7 @@ class SwiperInner extends React.Component<SwiperProps, SwiperState> {
const defaultIndicatorActiveColor = indicatorActiveColor || '#000'
const [pM, nM] = this.parseMargin()
const cls = classNames(`taro-swiper-${this._id}`, className)
const sty = Object.assign({}, style)
const hasMargin = pM || nM
if (hasMargin) {
sty.overflow = 'hidden'
}
const sty = Object.assign({ overflow: 'hidden' }, style)
if (this.props.full) {
sty.height = '100%'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Swiper events 1`] = `
<taro-swiper-core class="taro-swiper-6">
<taro-swiper-core class="taro-swiper-6" style="overflow: hidden;">
<!---->
<div class="swiper-container">
<style type="text/css">
Expand Down Expand Up @@ -30,7 +30,7 @@ exports[`Swiper events 1`] = `
`;

exports[`Swiper props 1`] = `
<taro-swiper-core class="taro-swiper-0">
<taro-swiper-core class="taro-swiper-0" style="overflow: hidden;">
<!---->
<div class="swiper-container">
<style type="text/css">
Expand Down Expand Up @@ -59,7 +59,7 @@ exports[`Swiper props 1`] = `
`;

exports[`Swiper should autoplay 1`] = `
<taro-swiper-core class="taro-swiper-1">
<taro-swiper-core class="taro-swiper-1" style="overflow: hidden;">
<!---->
<div class="swiper-container">
<style type="text/css">
Expand Down Expand Up @@ -88,7 +88,7 @@ exports[`Swiper should autoplay 1`] = `
`;

exports[`Swiper should be circular 1`] = `
<taro-swiper-core class="taro-swiper-2">
<taro-swiper-core class="taro-swiper-2" style="overflow: hidden;">
<!---->
<div class="swiper-container">
<style type="text/css">
Expand Down Expand Up @@ -117,7 +117,7 @@ exports[`Swiper should be circular 1`] = `
`;

exports[`Swiper should be vertical 1`] = `
<taro-swiper-core class="taro-swiper-3">
<taro-swiper-core class="taro-swiper-3" style="overflow: hidden;">
<!---->
<div class="swiper-container">
<style type="text/css">
Expand Down Expand Up @@ -146,7 +146,7 @@ exports[`Swiper should be vertical 1`] = `
`;

exports[`Swiper should display multi items within screen width 1`] = `
<taro-swiper-core class="taro-swiper-5">
<taro-swiper-core class="taro-swiper-5" style="overflow: hidden;">
<!---->
<div class="swiper-container">
<style type="text/css">
Expand Down
20 changes: 8 additions & 12 deletions packages/taro-components/src/components/swiper/swiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
}
}
const loopAdditionalSlides = this.getLoopAdditionalSlides()
const centeredSlides = displayMultipleItems === 1
const centeredSlides = displayMultipleItems === 1 && this.getNeedFixLoop()
const slidesPerView = displayMultipleItems === 1 ? 'auto' : displayMultipleItems
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that = this
Expand Down Expand Up @@ -458,26 +458,22 @@
indicatorActiveColor
} = this

const [pM, nM] = this.parseMargin()
const hasMargin = pM || nM
const hostStyle: Record<string, string> = {}
if(hasMargin) {
hostStyle.overflow = 'hidden'
}
if (this.full) {
hostStyle.height = '100%'
}

const [pM, nM] = this.parseMargin()
const swiperContainerStyleList: string [] = [
'overflow: visible;',
vertical ? `margin-top: ${pM}px; margin-bottom: ${nM}px;` : `margin-right: ${nM}px; margin-left: ${pM}px;`,
this.full ? 'height: 100%;' : '',
]

const swiperPaginationStyleList: string [] = [
indicatorDots ? 'opacity: 1;' : 'display: none;',
'font-size: 0;'
]
const hostStyle: Record<string, string> = { overflow: 'hidden' }

if (this.full) {
hostStyle.height = '100%'

Check warning on line 474 in packages/taro-components/src/components/swiper/swiper.tsx

View check run for this annotation

Codecov / codecov/patch

packages/taro-components/src/components/swiper/swiper.tsx#L474

Added line #L474 was not covered by tests
}


return (
<Host class={`taro-swiper-${this.#id}`} style={hostStyle}>
Expand Down
Loading