美文网首页
react-native-swiper使用onIndexChan

react-native-swiper使用onIndexChan

作者: 4999f4b4f3c4 | 来源:发表于2023-06-24 11:47 被阅读0次

react-native-swiper v1.6.0

react-native-swiper使用onIndexChanged时

onIndexChanged={index => {changeIndex(index);}}

滑动数据错误

iOS修改:

添加loadMinimal={true}

Android修改index.js文件

UNSAFE_componentWillUpdate(nextProps, nextState) {

// If the index has changed, we notify the parent via the onIndexChanged callback

  if (this.state.index !== nextState.index){

this.setState({index:nextState.index})//添加

this.props.onIndexChanged(nextState.index)}

}

//componentDidUpdate修改

componentDidUpdate(prevProps) {

// If autoplay props updated to true, autoplay immediately

  if (this.props.autoplay && !prevProps.autoplay) {

this.autoplay()

}

if (this.props.children !== prevProps.children) {

if (this.props.loadMinimal ) {

this.setState({ ...this.props, index:this.state.index })

}

}

}

相关文章

网友评论

      本文标题:react-native-swiper使用onIndexChan

      本文链接:https://www.haomeiwen.com/subject/tllbydtx.html