-
Notifications
You must be signed in to change notification settings - Fork 130
/
listview-scroll-to-index-initial.component.ts
56 lines (49 loc) · 2.19 KB
/
listview-scroll-to-index-initial.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
import { OptionsExampleBase } from "../../options-example-base";
import { Component, OnInit, Injectable, ViewChild } from "@angular/core";
import { Router } from '@angular/router';
import { Page, NavigatedData } from "tns-core-modules/ui/page";
import { OptionsService } from "../../navigation/options/options.service";
import { topmost } from "tns-core-modules/ui/frame";
import { ObservableArray } from "tns-core-modules/data/observable-array";
import { DataItem } from "../dataItem";
import { DataItemService } from "../dataItem.service";
import { RadListViewComponent } from "nativescript-ui-listview/angular";
import { EventData } from "tns-core-modules/data/observable";
import { ios as isIOS } from "tns-core-modules/application";
import { RadListView, ListViewItemSnapMode } from "nativescript-ui-listview";
@Component({
moduleId: module.id,
providers: [DataItemService],
selector: "tk-listview-scroll-to-index-initial",
templateUrl: "listview-scroll-to-index-initial.component.html",
styleUrls: ["listview-scroll-to-index.component.css"]
})
@Injectable()
export class ListViewScrollToIndexInitialComponent extends OptionsExampleBase implements OnInit {
private _dataItems: ObservableArray<DataItem>;
private timer;
constructor(private _page: Page, private _dataItemService: DataItemService, private _optionsService: OptionsService, private _router: Router) {
super();
}
get dataItems(): ObservableArray<DataItem> {
return this._dataItems;
}
ngOnInit() {
this._dataItems = new ObservableArray(this._dataItemService.getIdenticalDataItems(100));
}
private scrollFunc(listView: RadListView) {
listView.scrollToIndex(20, false, ListViewItemSnapMode.Start);
}
public onDataPopulated(args: EventData) {
const listView = args.object as RadListView;
// Uses "setTimeout()" to only execute scrollToIndex when the RadListView on iOS has finished populating its native objects
if (isIOS) {
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(this.scrollFunc, 10, listView);
} else {
this.scrollFunc(listView);
}
}
}