feat(UI): Added animated scroll to index for ListView (#6077)

* feat(UI): Added animated scroll to index for ListView

* Update list-view.d.ts
This commit is contained in:
Shiva Prasad
2018-07-19 19:10:59 +05:30
committed by Martin Yankov
parent 20e1d78f7d
commit 1fac718a58
4 changed files with 26 additions and 0 deletions

View File

@ -90,6 +90,10 @@ export abstract class ListViewBase extends View implements ListViewDefinition, T
// //
} }
public scrollToIndexAnimated(index: number) {
//
}
public _getItemTemplate(index: number): KeyedTemplate { public _getItemTemplate(index: number): KeyedTemplate {
let templateKey = "default"; let templateKey = "default";
if (this.itemTemplateSelector) { if (this.itemTemplateSelector) {

View File

@ -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 { get _childrenCount(): number {
return this._realizedItems.size; return this._realizedItems.size;
} }

View File

@ -97,6 +97,14 @@ export class ListView extends View {
*/ */
scrollToIndex(index: number); 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. * Checks if Specified item with index is visible.
* @param index - Item index. * @param index - Item index.

View File

@ -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() { public refresh() {
// clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate // clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate
this._map.forEach((view, nativeView, map) => { this._map.forEach((view, nativeView, map) => {