Enable item swiping for certain rows in RadListView

161 views Asked by At

is there a way how to enable left / right rows swipe only for certain elements in list when using RadListView in nativescript + angular?

Thanks

2

There are 2 answers

0
Manoj On

You can, for every swipe you will hit itemSwipeProgressStarted event where you will have to return swipeLimits. Set left / right limits to zero (0) when you want to disable swipe actions on specific item.

0
Chris G. On

Here is an example for left view based on items statuses.

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...');
    }    
}

But I'm not sure this will work on iOS.

Maybe you should rather redifine views in onCellSwiping method, here is another example where you can replace swipe views based on isItemVisible param :

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

I haven't tested it on iOS yet but this should work on Android and iOS.