Skip to content

Commit

Permalink
fix(taro-compoents): 修复swiper自动轮播问题,修复switch返回值问题,修复slider touch事件问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongxin committed Jun 13, 2018
1 parent a5b0a0a commit a95c33f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/taro-components/src/components/slider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Slider extends Nerv.Component {

parseType(this.props)

this.sliderInsRef = ''

this.state = {
value: this.props.value ? this.props.value : 0,
controlled: typeof this.props.value !== 'undefined',
Expand Down Expand Up @@ -119,7 +121,7 @@ class Slider extends Nerv.Component {

handleTouchStart (e) {
if (this.state.touching || this.props.disabled) return
let barDOM = Nerv.findDOMNode(this.refs.bar)
let barDOM = Nerv.findDOMNode(this.sliderInsRef)
this.setState({
touching: true,
touchId: e.targetTouches[0].identifier,
Expand Down Expand Up @@ -217,7 +219,7 @@ class Slider extends Nerv.Component {
return (
<div className={cls}>
<div className='weui-slider'>
<div className='weui-slider__inner' style={innerStyles} ref='bar'>
<div className='weui-slider__inner' style={innerStyles} ref={c => (this.sliderInsRef = c)}>
<div style={trackStyles} className='weui-slider__track' />
<div
style={handlerStyles}
Expand Down
11 changes: 11 additions & 0 deletions packages/taro-components/src/components/swiper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Swiper extends Nerv.Component {
current: this.props.current
}
this.isSliding = false
this.SwiperTimer = null
}

initSwiper (nextProps) {
Expand Down Expand Up @@ -326,6 +327,16 @@ class Swiper extends Nerv.Component {
this.initSwiper()
}

componentWillReceiveProps (nextProps) {
const {interval, autoplay} = nextProps
this.pauseAutoPlay()
if (!autoplay) return

this.SwiperTimer = setInterval(() => {
this.slideNext('aotuplay')
}, interval)
}

componentWillUnmount () {
this.pauseAutoPlay()
this.removeEvent()
Expand Down
16 changes: 14 additions & 2 deletions packages/taro-components/src/components/switch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ class Switch extends Nerv.Component {
this.state = {
checked: this.props.checked
}
this.switchChange = this.switchChange.bind(this)
}

switchChange (e) {
const { onChange } = this.props
Object.defineProperty(e, 'detail', {
enumerable: true,
value: {
value: e.target.checked
}
})
onChange(e)
}

render () {
const { onChange, type = 'switch', className } = this.props
const { type = 'switch', className } = this.props
const cls = classNames(
{
[`weui-${parseType(type)}`]: true
Expand All @@ -32,7 +44,7 @@ class Switch extends Nerv.Component {
className={cls}
checked={this.state.checked}
type='checkbox'
onChange={onChange}
onChange={this.switchChange}
/>
)
}
Expand Down

0 comments on commit a95c33f

Please sign in to comment.