mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Merge pull request #629 from NativeScript/scrollToIndex-
scrollToIndex added to ListView
This commit is contained in:
@ -459,6 +459,26 @@ export function test_loadMoreItems_not_raised_when_showing_many_items() {
|
||||
helper.buildUIAndRunTest(listView, testAction);
|
||||
}
|
||||
|
||||
export function test_loadMoreItems_is_raised_when_scroll_to_last_item() {
|
||||
var listView = new listViewModule.ListView();
|
||||
listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber);
|
||||
|
||||
function testAction(views: Array<viewModule.View>) {
|
||||
var loadMoreItemsCount = 0;
|
||||
listView.items = MANY_ITEMS;
|
||||
listView.on(listViewModule.ListView.loadMoreItemsEvent, function (data: observable.EventData) {
|
||||
loadMoreItemsCount++;
|
||||
});
|
||||
|
||||
listView.scrollToIndex(MANY_ITEMS.length - 1);
|
||||
|
||||
TKUnit.wait(ASYNC);
|
||||
TKUnit.assertEqual(loadMoreItemsCount, 1, "loadMoreItemsCount");
|
||||
};
|
||||
|
||||
helper.buildUIAndRunTest(listView, testAction);
|
||||
}
|
||||
|
||||
export function test_usingAppLevelConvertersInListViewItems() {
|
||||
var listView = new listViewModule.ListView();
|
||||
|
||||
|
@ -101,6 +101,10 @@ export class ListView extends view.View implements definition.ListView {
|
||||
//
|
||||
}
|
||||
|
||||
public scrollToIndex(index: number) {
|
||||
//
|
||||
}
|
||||
|
||||
public _getItemTemplateContent(index: number): view.View {
|
||||
var v;
|
||||
|
||||
|
@ -102,6 +102,12 @@ export class ListView extends common.ListView {
|
||||
(<ListViewAdapter>this.android.getAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public scrollToIndex(index: number) {
|
||||
if (this._android) {
|
||||
this._android.setSelection(index);
|
||||
}
|
||||
}
|
||||
|
||||
public _onDetached(force?: boolean) {
|
||||
super._onDetached(force);
|
||||
|
||||
|
8
ui/list-view/list-view.d.ts
vendored
8
ui/list-view/list-view.d.ts
vendored
@ -85,6 +85,14 @@ declare module "ui/list-view" {
|
||||
*/
|
||||
refresh();
|
||||
|
||||
/**
|
||||
* Scrolls the specified item with index into view.
|
||||
* [iOS](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/scrollToRowAtIndexPath:atScrollPosition:animated:)
|
||||
* [Android](http://developer.android.com/reference/android/widget/ListView.html#setSelection(int))
|
||||
* @param index - Item index.
|
||||
*/
|
||||
scrollToIndex(index: number);
|
||||
|
||||
/**
|
||||
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
||||
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
|
||||
|
@ -173,6 +173,13 @@ export class ListView extends common.ListView {
|
||||
return this._ios;
|
||||
}
|
||||
|
||||
public scrollToIndex(index: number) {
|
||||
if (this._ios) {
|
||||
this._ios.scrollToRowAtIndexPathAtScrollPositionAnimated(NSIndexPath.indexPathForItemInSection(index, 0),
|
||||
UITableViewScrollPosition.UITableViewScrollPositionTop, true);
|
||||
}
|
||||
}
|
||||
|
||||
public refresh() {
|
||||
if (this.isLoaded) {
|
||||
this._ios.reloadData();
|
||||
|
Reference in New Issue
Block a user