Skip to content

Commit

Permalink
feat(UI): Added animated scroll to index for ListView (#6077)
Browse files Browse the repository at this point in the history
* feat(UI): Added animated scroll to index for ListView

* Update list-view.d.ts
  • Loading branch information
shiv19 authored and MartoYankov committed Jul 19, 2018
1 parent 20e1d78 commit 1fac718
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tns-core-modules/ui/list-view/list-view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export abstract class ListViewBase extends View implements ListViewDefinition, T
//
}

public scrollToIndexAnimated(index: number) {
//
}

public _getItemTemplate(index: number): KeyedTemplate {
let templateKey = "default";
if (this.itemTemplateSelector) {
Expand Down
7 changes: 7 additions & 0 deletions tns-core-modules/ui/list-view/list-view.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ export class ListView extends ListViewBase {
}
}

public scrollToIndexAnimated(index: number) {
const nativeView = this.nativeViewProtected;
if (nativeView) {
nativeView.smoothScrollToPosition(index);
}
}

get _childrenCount(): number {
return this._realizedItems.size;
}
Expand Down
8 changes: 8 additions & 0 deletions tns-core-modules/ui/list-view/list-view.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ export class ListView extends View {
*/
scrollToIndex(index: number);

/**
* Scrolls the specified item with index into view with animation.
* [iOS](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated:)
* [Android](https://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int))
* @param index - Item index.
*/
scrollToIndexAnimated(index: number);

/**
* Checks if Specified item with index is visible.
* @param index - Item index.
Expand Down
7 changes: 7 additions & 0 deletions tns-core-modules/ui/list-view/list-view.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ export class ListView extends ListViewBase {
}
}

public scrollToIndexAnimated(index: number) {
if (this._ios) {
this._ios.scrollToRowAtIndexPathAtScrollPositionAnimated(NSIndexPath.indexPathForItemInSection(index, 0),
UITableViewScrollPosition.Top, true);
}
}

public refresh() {
// clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate
this._map.forEach((view, nativeView, map) => {
Expand Down

0 comments on commit 1fac718

Please sign in to comment.