FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(UI): Added animated scroll to index for ListView (#6077) · NativeScript/NativeScript@1fac718 · GitHub

Commit 1fac718

Browse files
authored andcommitted
feat(UI): Added animated scroll to index for ListView (#6077)
* feat(UI): Added animated scroll to index for ListView * Update list-view.d.ts
1 parent 20e1d78 commit 1fac718

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎tns-core-modules/ui/list-view/list-view-common.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export abstract class ListViewBase extends View implements ListViewDefinition, T
9090
//
9191
}
9292

93+
public scrollToIndexAnimated(index: number) {
94+
//
95+
}
96+
9397
public _getItemTemplate(index: number): KeyedTemplate {
9498
let templateKey = "default";
9599
if (this.itemTemplateSelector) {

‎tns-core-modules/ui/list-view/list-view.android.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ export class ListView extends ListViewBase {
124124
}
125125
}
126126

127+
public scrollToIndexAnimated(index: number) {
128+
const nativeView = this.nativeViewProtected;
129+
if (nativeView) {
130+
nativeView.smoothScrollToPosition(index);
131+
}
132+
}
133+
127134
get _childrenCount(): number {
128135
return this._realizedItems.size;
129136
}

‎tns-core-modules/ui/list-view/list-view.d.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export class ListView extends View {
9797
*/
9898
scrollToIndex(index: number);
9999

100+
/**
101+
* Scrolls the specified item with index into view with animation.
102+
* [iOS](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated:)
103+
* [Android](https://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int))
104+
* @param index - Item index.
105+
*/
106+
scrollToIndexAnimated(index: number);
107+
100108
/**
101109
* Checks if Specified item with index is visible.
102110
* @param index - Item index.

‎tns-core-modules/ui/list-view/list-view.ios.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,13 @@ export class ListView extends ListViewBase {
261261
}
262262
}
263263

264+
public scrollToIndexAnimated(index: number) {
265+
if (this._ios) {
266+
this._ios.scrollToRowAtIndexPathAtScrollPositionAnimated(NSIndexPath.indexPathForItemInSection(index, 0),
267+
UITableViewScrollPosition.Top, true);
268+
}
269+
}
270+
264271
public refresh() {
265272
// clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate
266273
this._map.forEach((view, nativeView, map) => {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL