本文共 1103 字,大约阅读时间需要 3 分钟。
a RN component make list come back to top.
---
npm install --save react-native-scrolltotop
see the example/example.js for a more detailed example.
import ScrollTopView from 'react-native-scrolltotop'; //first set default state in your constructor constructor(props) { //... this.state = { isShowToTop: false, }; } //then bind a method to detect the scroll distance of your listView //set ref with 'listview' this._onScroll(e)} style={ styles.listView} renderScrollComponent={(props)=>{ return }}/> //here is the _onScrol method _onScroll(e) { var offsetY = e.nativeEvent.contentOffset.y; if(offsetY > 100) { this.setState({ isShowToTop: true }) } else { this.setState({ isShowToTop: false }) } }//use it with your listView together 消息列表 {listView} { this.state.isShowToTop? :null}
转载地址:http://vyeni.baihongyu.com/