Skip to content

Commit

Permalink
fix(taro-components): H5 Swiper问题 close #1528
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjinjin0731 authored and luckyadam committed Dec 17, 2018
1 parent 10a27fc commit 0df6b30
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/taro-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"types"
],
"scripts": {
"local-dev": "webpack-dev-server --config webpack.config.js --env development",
"dev": "webpack --config webpack.prod.config.js --watch",
"deploy": "webpack --config webpack.config.js",
"build": "webpack --config webpack.prod.config.js",
Expand Down
16 changes: 9 additions & 7 deletions packages/taro-components/src/components/swiper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ class Swiper extends Nerv.Component {
slidesPerView: parseInt(displayMultipleItems, 10),
initialSlide: parseInt(current, 10),
speed: parseInt(duration, 10),
observer: true,
on: {
slideChange () {
let e = new TouchEvent('touchend')
Object.defineProperty(e, 'detail', {
enumerable: true,
value: {
current: this.activeIndex
current: this.realIndex
}
})
onChange && onChange(e)
Expand All @@ -59,7 +60,7 @@ class Swiper extends Nerv.Component {
Object.defineProperty(e, 'detail', {
enumerable: true,
value: {
current: this.activeIndex
current: this.realIndex
}
})
onAnimationfinish && onAnimationfinish(e)
Expand All @@ -79,14 +80,15 @@ class Swiper extends Nerv.Component {
this.mySwiper = new Swipers(this.$el, opt)
}

componentDidUpdate () {
this.mySwiper.updateSlides() // 更新子元素
componentWillReceiveProps (nextProps) {
const nextCurrent = nextProps.current || 0
// 是否衔接滚动模式
if (this.props.circular) {
this.mySwiper.slideToLoop(parseInt(this.props.current, 10)) // 更新下标
if (nextProps.circular) {
this.mySwiper.slideToLoop(parseInt(nextCurrent, 10)) // 更新下标
} else {
this.mySwiper.slideTo(parseInt(this.props.current, 10)) // 更新下标
this.mySwiper.slideTo(parseInt(nextCurrent, 10)) // 更新下标
}
this.mySwiper.update() // 更新子元素
}

componentWillUnmount () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.swiper-container {
height: 150px;
}
.swiper-pagination {
font-size: 0;
}
4 changes: 3 additions & 1 deletion packages/taro-components/src/components/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class View extends Nerv.Component {
onTouchEnd,
className,
hoverStartTime = 50,
hoverStayTime = 400
hoverStayTime = 400,
...other
} = this.props
const cls = classNames(
'',
Expand Down Expand Up @@ -69,6 +70,7 @@ class View extends Nerv.Component {
'hoverStartTime',
'hoverStayTime'
])}
{...other}
className={cls}
onTouchStart={_onTouchStart}
onTouchEnd={_onTouchEnd}
Expand Down

0 comments on commit 0df6b30

Please sign in to comment.