From 0df6b30fb401453b2c0a2e8e4dfa37de99f018d8 Mon Sep 17 00:00:00 2001 From: jinjinjin0731 <709899428@qq.com> Date: Mon, 17 Dec 2018 22:15:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(taro-components):=20=20H5=20Swiper=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20close=20#1528?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-components/package.json | 1 + .../src/components/swiper/index.js | 16 +++++++++------- .../src/components/swiper/style/index.scss | 3 +++ .../taro-components/src/components/view/index.js | 4 +++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json index e0bb87593ba2..b435bf5f786f 100644 --- a/packages/taro-components/package.json +++ b/packages/taro-components/package.json @@ -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", diff --git a/packages/taro-components/src/components/swiper/index.js b/packages/taro-components/src/components/swiper/index.js index 4972576d444f..8888b253d555 100644 --- a/packages/taro-components/src/components/swiper/index.js +++ b/packages/taro-components/src/components/swiper/index.js @@ -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) @@ -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) @@ -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 () { diff --git a/packages/taro-components/src/components/swiper/style/index.scss b/packages/taro-components/src/components/swiper/style/index.scss index 3474bca074b4..02168c6e7305 100644 --- a/packages/taro-components/src/components/swiper/style/index.scss +++ b/packages/taro-components/src/components/swiper/style/index.scss @@ -1,3 +1,6 @@ .swiper-container { height: 150px; +} +.swiper-pagination { + font-size: 0; } \ No newline at end of file diff --git a/packages/taro-components/src/components/view/index.js b/packages/taro-components/src/components/view/index.js index 67ce8f885c9e..e7e02d6822b3 100644 --- a/packages/taro-components/src/components/view/index.js +++ b/packages/taro-components/src/components/view/index.js @@ -19,7 +19,8 @@ class View extends Nerv.Component { onTouchEnd, className, hoverStartTime = 50, - hoverStayTime = 400 + hoverStayTime = 400, + ...other } = this.props const cls = classNames( '', @@ -69,6 +70,7 @@ class View extends Nerv.Component { 'hoverStartTime', 'hoverStayTime' ])} + {...other} className={cls} onTouchStart={_onTouchStart} onTouchEnd={_onTouchEnd}