Detect ScrollView has reached the end

前端 未结 7 1108
栀梦
栀梦 2020-12-23 21:32

I have a Text with long text inside a ScrollView and I want to detect when the user has scrolled to the end of the text so I can enable a button.

7条回答
  •  独厮守ぢ
    2020-12-23 21:54

    As an addition to the answer of Henrik R:

    If you need to know wether the user has reached the end of the content at mount time (if the content may or may not be too long, depending on device size) - here is my solution:

    
        
            {/*...*/}
        
    
    

    in combination with

    onLayout(wrapper, { nativeEvent }) {
        if (wrapper) {
            this.setState({
                wrapperHeight: nativeEvent.layout.height,
            });
        } else {
            this.setState({
                contentHeight: nativeEvent.layout.height,
                isCloseToBottom:
                  this.state.wrapperHeight - nativeEvent.layout.height >= 0,
            });
        }
    }
    

提交回复
热议问题