Get current scroll position of ScrollView in React Native

后端 未结 11 1529
遇见更好的自我
遇见更好的自我 2020-11-27 11:10

Is it possible to get the current scroll position, or the current page of a component in React Native?

So something like:

<         


        
11条回答
  •  一个人的身影
    2020-11-27 11:44

    This is how ended up getting the current scroll position live from the view. All I am doing is using the on scroll event listener and the scrollEventThrottle. I am then passing it as an event to handle scroll function I made and updating my props.

     export default class Anim extends React.Component {
              constructor(props) {
                 super(props);
                 this.state = {
                   yPos: 0,
                 };
               }
    
            handleScroll(event){
                this.setState({
                  yPos : event.nativeEvent.contentOffset.y,
                })
            }
    
            render() {
                return (
              
        )
        }
        }
    

提交回复
热议问题