Nativescript + Angular ScrollView滚动到结束侦听器

Dan*_*iel 4 nativescript angular2-nativescript nativescript-angular angular

是否有任何回调可用于识别何时ScrollView滚动到最底部?在Nativescript文档中,仅scroll提及事件,但它仅提供有关当前滚动的X或Y线的信息.不确定这个事件是否对我有帮助,因为我的ScrollView身高是动态的.

Man*_*noj 5

您仍然可以监听scroll事件并查看当前verticalOffset是否等于您location的最后一个组件ScrollView.

就像是,

 // Attached to layoutChange event of your container element inside scroll view
 onLayoutChanged(event: EventData) {
    const containerLyt = <StackLayout>event.object,
        length = containerLyt.getChildrenCount(),
        lastItem = containerLyt.getChildAt(length - 1);

    this.lastItemY = lastItem.getLocationRelativeTo(containerLyt).y;
}

onScroll(event: EventData) {
    const scrollView = <ScrollView>event.object,
        verticalOffset = scrollView.getActualSize().height + scrollView.verticalOffset;

    if (verticalOffset >= this.lastItemY) {
        console.log("Reached end of scroll");
    }
}
Run Code Online (Sandbox Code Playgroud)

游乐场示例