/
scroll-to-index-model-horizontal.ts
67 lines (58 loc) · 1.99 KB
/
scroll-to-index-model-horizontal.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
import { ObservableArray } from "tns-core-modules/data/observable-array";
import { Observable } from "tns-core-modules/data/observable";
import frameModule = require("tns-core-modules/ui/frame");
import { DataItem } from "./data-item";
export class ViewModel extends Observable {
private _options: Array<string> = ["Auto", "Start", "Center", "End"];
private _selectionInfo;
constructor() {
super();
let selectedIndex = 2;
this._selectionInfo = {
options: this._options,
index: selectedIndex
};
this.set("myScrollPosition", this._options[selectedIndex]);
this.dataItems = new ObservableArray<DataItem>();
for (var i = 0; i < 100; i++) {
this.dataItems.push(new DataItem(i, "Item " + i));
}
}
get dataItems(): ObservableArray<DataItem> {
return this.get("_dataItems");
}
set dataItems(value: ObservableArray<DataItem>) {
this.set("_dataItems", value);
}
public updateViewModel() {
var index: number = this._selectionInfo.index;
switch (index) {
case 0:
this.set("myScrollPosition", this._options[0]);
break;
case 1:
this.set("myScrollPosition", this._options[1]);
break;
case 2:
this.set("myScrollPosition", this._options[2]);
break;
case 3:
this.set("myScrollPosition", this._options[3]);
break;
default:
break;
}
}
public onOptionsTapped(args: any) {
if (frameModule.topmost().ios) {
var navigationEntry = {
moduleName: "navigation/options-menu/options",
context: this._selectionInfo,
animated: true
};
frameModule.topmost().navigate(navigationEntry);
} else {
this.set('myScrollPosition', args.object.text);
}
}
}