-
Notifications
You must be signed in to change notification settings - Fork 130
/
listview-swipe-disable.component.ts
97 lines (79 loc) · 3.07 KB
/
listview-swipe-disable.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { Component, OnInit, ViewChild } from "@angular/core";
import { ObservableArray } from "tns-core-modules/data/observable-array";
import { DataItem } from "../dataItem";
import { DataItemService } from "../dataItem.service";
import { ListViewEventData, SwipeActionsEventData, RadListView } from "nativescript-ui-listview";
import { RadListViewComponent } from "nativescript-ui-listview/angular";
import { View } from 'tns-core-modules/ui/core/view';
@Component({
moduleId: module.id,
selector: "tk-listview-swipe-disable",
providers: [DataItemService],
templateUrl: "listview-swipe-disable.component.html",
styleUrls: ["listview-swipe-disable.component.css"]
})
export class ListViewSwipeDisableComponent implements OnInit {
private _dataItems: ObservableArray<DataItem>;
private _enabled: boolean = true;
private _currentStatus: string;
constructor(private _dataItemService: DataItemService) {
}
get dataItems(): ObservableArray<DataItem> {
return this._dataItems;
}
get enabled(): boolean {
return this._enabled;
}
set enabled(value: boolean) {
this._enabled = value;
this.updateStatusText();
}
get currentStatus(): string {
return this._currentStatus;
}
set currentStatus(value: string) {
this._currentStatus = value;
}
@ViewChild("myListView", { read: RadListViewComponent, static: false }) myListViewComponent: RadListViewComponent;
ngOnInit() {
this._dataItems = new ObservableArray(this._dataItemService.getPostDataItems());
this.enabled = true;
}
public onCellSwiping(args: SwipeActionsEventData) {
const swipeLimits = args.data.swipeLimits;
const currentItemView = args.swipeView;
if (args.data.x > 200) {
console.log("Notify perform left action");
} else if (args.data.x < -200) {
console.log("Notify perform right action");
}
}
public onSwipeCellStarted(args: SwipeActionsEventData) {
const swipeLimits = args.data.swipeLimits;
const swipeView = args.swipeView;
const leftItem = swipeView.getViewById<View>('mark-view');
const rightItem = swipeView.getViewById<View>('delete-view');
swipeLimits.left = leftItem.getMeasuredWidth();
swipeLimits.right = rightItem.getMeasuredWidth();
swipeLimits.threshold = leftItem.getMeasuredWidth() / 2;
}
public onSwipeCellFinished(args: SwipeActionsEventData) {
}
public onLeftSwipeClick(args: ListViewEventData) {
console.log("Left swipe click");
this.myListViewComponent.listView.notifySwipeToExecuteFinished();
}
public onRightSwipeClick(args) {
console.log("Right swipe click");
this.dataItems.splice(this.dataItems.indexOf(args.object.bindingContext), 1);
}
public onDisableEnableTap() {
this.enabled = !this.enabled;
}
public onItemSwiping(args) {
args.returnValue = this.enabled;
}
private updateStatusText() {
this.currentStatus = !this.enabled ? "ENABLE" : "DISABLE";
}
}