【发布时间】:2020-07-30 17:21:18
【问题描述】:
在 nativescript + angular 中使用 RadListView 时,有没有办法只为列表中的某些元素启用左/右行滑动?
谢谢
【问题讨论】:
标签: angular nativescript swipe radlistview
在 nativescript + angular 中使用 RadListView 时,有没有办法只为列表中的某些元素启用左/右行滑动?
谢谢
【问题讨论】:
标签: angular nativescript swipe radlistview
你可以,每次滑动你都会点击itemSwipeProgressStarted事件,你必须返回swipeLimits。当您想要禁用对特定项目的滑动操作时,将左/右限制设置为零 (0)。
【讨论】:
这是一个基于项目状态的左视图示例。
dataItems: ObservableArray<any>;
...
onSwipeCellStarted(args: any) {
let status = this.dataItems.getItem(args.index).data.status;
const swipeLimits = args.data.swipeLimits;
const swipeView = args.object;
const deleteView: View = swipeView.getViewById('delete-view');
const editView: View = swipeView.getViewById('edit-view');
const disabledView: View = swipeView.getViewById('disabled-view');
if (status === 1) {
swipeLimits.left = editView.getMeasuredWidth() + deleteView.getMeasuredWidth();
swipeLimits.right = 0;
} else {
swipeLimits.left = 0;
swipeLimits.right = 0;
console.warn(' forbidden swipe...');
}
}
但我不确定这是否适用于 iOS。
也许您应该在 onCellSwiping 方法中重新定义视图,这是另一个示例,您可以根据 isItemVisible 参数替换滑动视图:
onCellSwiping(args: ListViewEventData) {
const swipeLimits = args.data.swipeLimits;
const swipeView = args['swipeView'];
this.mainView = args['mainView'];
this.leftItem = swipeView.getViewById('edit-view');
this.disabledItem = swipeView.getViewById('disabled-view');
let isVisible = this.mainView.bindingContext.isItemVisible;
if (isVisible) {
View.layoutChild(<View>this.disabledItem.parent, this.disabledItem, this.mainView.getMeasuredWidth(), 0, this.mainView.getMeasuredWidth(), 0);
} else {
View.layoutChild(<View>this.leftItem.parent, this.leftItem, this.mainView.getMeasuredWidth(), 0, this.mainView.getMeasuredWidth(), 0);
}
}
我还没有在 iOS 上测试过,但这应该可以在 Android 和 iOS 上运行。
【讨论】: