mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 21:01:34 +08:00
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:

committed by
Martin Yankov

parent
20e1d78f7d
commit
1fac718a58
@ -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) {
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
8
tns-core-modules/ui/list-view/list-view.d.ts
vendored
8
tns-core-modules/ui/list-view/list-view.d.ts
vendored
@ -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.
|
||||||
|
@ -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) => {
|
||||||
|
Reference in New Issue
Block a user