Detect ScrollView has reached the end

前端 未结 7 1067
栀梦
栀梦 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 22:10

    @Henrik R's right. But you should use Math.ceil() too.

    function handleInfinityScroll(event) {
            let mHeight = event.nativeEvent.layoutMeasurement.height;
            let cSize = event.nativeEvent.contentSize.height;
            let Y = event.nativeEvent.contentOffset.y;
    
            if(Math.ceil(mHeight + Y) >= cSize) return true;
            return false;
    }
    

    enter image description here

提交回复
热议问题