如何检测是否向上滚动或radlistview向下滚动

问题描述 投票:0回答:1

本地脚本RAD-列表视图不检测是否向上滑动或者向下滑动项目列表。

通过使用本地脚本刷卡事件一会就搞定4个值的左,右,上,下即1,2,4,8。但刷卡动作不工作的RAD-列表视图。

        <lv:RadListView pullToRefresh="true" pullToRefreshInitiated="{{onPullToRefreshInitiated}}"
        scrolled="onScrolled" scrollOffset="scrollOffset" scrollStarted="onScrollStarted" scrollEnded="onScrollEnded"
        id="id_content" row="1" items="{{ source }}" loaded="onLoaded" backgroundColor="transparent"
        itemLoading="onItemLoading" itemTap="onItemTap">

            <lv:RadListView.itemTemplate>
                <StackLayout orientation="vertical" 
                backgroundColor="antiquewhite" margin="5" padding="10" borderWidth="1">

                    <Label fontSize="20" text="{{ name }}"/>
                    <Label fontSize="14" text="{{ name }}"/>

                </StackLayout>
            </lv:RadListView.itemTemplate>

            <lv:RadListView.listViewLayout>
                <lv:ListViewStaggeredLayout scrollDirection="Vertical" spanCount="2"/>
            </lv:RadListView.listViewLayout>

            <lv:RadListView.pullToRefreshStyle>
                <lv:PullToRefreshStyle indicatorColor="red" indicatorBackgroundColor="antiquewhite"/>
            </lv:RadListView.pullToRefreshStyle>

        </lv:RadListView>

    </GridLayout>

如何检测上radlistview刷卡向上或向下的事件。

nativescript gesture radlistview
1个回答
0
投票

比较scrollOffsetscrollStarted事件之间的scrollEnded,如果起始位置小于结束位置,然后用户滚动起来,否则向下。

let lastOffset;

export function onScrollStarted(args) {
    lastOffset = args.object.getScrollOffset();
}

export function onScrollEnded(args) {
    let currentOffset = args.object.getScrollOffset();
    console.log(currentOffset < lastOffset ? "Up" : "Down");
    lastOffset = currentOffset;
}

Playground Sample

© www.soinside.com 2019 - 2024. All rights reserved.