0

本机脚本 rad-list-view 未检测是向上滑动还是向下滑动项目列表。

通过使用本机脚本滑动事件,将获得左、右、上和下的 4 个值,即 1、2、4、8。但滑动操作不适用于 rad-list-view。

        <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 上的向上或向下滑动事件。

4

1 回答 1

1

比较scrollOffsetbetweenscrollStartedscrollEndedevent,如果开始位置小于结束位置,则用户向上滚动,否则向下滚动。

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;
}

游乐场样本

于 2019-02-06T18:55:44.423 回答