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

view parent exposed in itemLoading event by enchev · Pull Request #221 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 29 additions & 0 deletions apps/tests/ui/list-view/list-view-tests.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import helper = require("../helper");
import viewModule = require("ui/core/view");
import observable = require("data/observable");
import types = require("utils/types");
import platform = require("platform");

// <snippet module="ui/list-view" title="list-view">
// # ListView
Expand Down Expand Up @@ -128,6 +129,34 @@ export function test_set_items_to_array_loads_all_items() {
helper.buildUIAndRunTest(listView, testAction);
}

export function test_set_native_item_exposed() {
var listView = new listViewModule.ListView();

function testAction(views: Array<viewModule.View>) {
var indexes = {};
var colors = ["red", "green", "blue"];
listView.items = colors;
listView.on(listViewModule.ListView.itemLoadingEvent, function (args: listViewModule.ItemEventData) {
if (platform.device.os === platform.platformNames.ios) {
indexes[args.index] = args.ios;
} else if (platform.device.os === platform.platformNames.android) {
indexes[args.index] = args.android;
}
});

TKUnit.wait(ASYNC);
for (var item in indexes) {
if (platform.device.os === platform.platformNames.ios) {
TKUnit.assert(indexes[item] instanceof UITableViewCell, "itemLoading not called for index " + item);
} else if (platform.device.os === platform.platformNames.android) {
TKUnit.assert(indexes[item] instanceof android.view.ViewGroup, "itemLoading not called for index " + item);
}
}
};

helper.buildUIAndRunTest(listView, testAction);
}

export function test_set_items_to_array_creates_native_views() {
var listView = new listViewModule.ListView();
listView.on(listViewModule.ListView.itemLoadingEvent, loadViewWithItemNumber);
Expand Down
9 changes: 7 additions & 2 deletions ui/list-view/list-view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import stackLayout = require("ui/layouts/stack-layout");
import proxy = require("ui/core/proxy");
import dependencyObservable = require("ui/core/dependency-observable");
import color = require("color");
import definition = require("ui/list-view");

var ITEMLOADING = common.ListView.itemLoadingEvent;
var LOADMOREITEMS = common.ListView.loadMoreItemsEvent;
Expand Down Expand Up @@ -181,13 +182,17 @@ class ListViewAdapter extends android.widget.BaseAdapter {
return true;
}

public getView(index: number, convertView: android.view.View, parent: any): android.view.View {
public getView(index: number, convertView: android.view.View, parent: android.view.ViewGroup): android.view.View {
if (!this._listView) {
return null;
}

var view = this._listView._getRealizedView(convertView, index);
var args = { eventName: ITEMLOADING, object: this._listView, index: index, view: view };
var args = <definition.ItemEventData>{
eventName: ITEMLOADING, object: this._listView, index: index, view: view,
android: parent,
ios: undefined
};
this._listView.notify(args);

if (!args.view) {
Expand Down
10 changes: 10 additions & 0 deletions ui/list-view/list-view.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,15 @@ declare module "ui/list-view" {
* The view that is associated to the item, for which the event is raised.
*/
view: view.View;

/**
* Gets the native [iOS view](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/) that represents the user interface where the view is hosted. Valid only when running on iOS.
*/
ios: UITableViewCell;

/**
* Gets the native [android widget](http://developer.android.com/reference/android/view/ViewGroup.html) that represents the user interface where the view is hosted. Valid only when running on Android OS.
*/
android: android.view.ViewGroup;
}
}
17 changes: 4 additions & 13 deletions ui/list-view/list-view.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ require("utils/module-merge").merge(common, exports);

var infinity = utils.layout.makeMeasureSpec(0, utils.layout.UNSPECIFIED);

class ListViewCell extends UITableViewCell {
static new(): ListViewCell {
return <ListViewCell>super.new();
}
static class(): any {
return ListViewCell;
}
}

function notifyForItemAtIndex(listView: definition.ListView, cell: any, eventName: string, indexPath: NSIndexPath) {
var args = <definition.ItemEventData>{ eventName: eventName, object: listView, index: indexPath.row, view: cell.view };
var args = <definition.ItemEventData>{ eventName: eventName, object: listView, index: indexPath.row, view: cell.view, ios: cell, android: undefined };
listView.notify(args);
return args;
}
Expand All @@ -54,7 +45,7 @@ class DataSource extends NSObject implements UITableViewDataSource {

public tableViewCellForRowAtIndexPath(tableView: UITableView, indexPath: NSIndexPath): UITableViewCell {
// We call this method because ...ForIndexPath calls tableViewHeightForRowAtIndexPath immediately (before we can prepare and measure it).
var cell = tableView.dequeueReusableCellWithIdentifier(CELLIDENTIFIER) || ListViewCell.new();
var cell = tableView.dequeueReusableCellWithIdentifier(CELLIDENTIFIER) || UITableViewCell.new();
this._owner._prepareCell(cell, indexPath);

var cellView: view.View = cell.view;
Expand Down Expand Up @@ -115,7 +106,7 @@ class UITableViewDelegateImpl extends NSObject implements UITableViewDelegate {
// in iOS 7.1 this method is called before tableViewCellForRowAtIndexPath so we need fake cell to measure its content.
var cell = this._measureCell;
if (!cell) {
this._measureCell = tableView.dequeueReusableCellWithIdentifier(CELLIDENTIFIER) || ListViewCell.new();
this._measureCell = tableView.dequeueReusableCellWithIdentifier(CELLIDENTIFIER) || UITableViewCell.new();
cell = this._measureCell;
}

Expand Down Expand Up @@ -157,7 +148,7 @@ export class ListView extends common.ListView {
super();

this._ios = new UITableView();
this._ios.registerClassForCellReuseIdentifier(ListViewCell.class(), CELLIDENTIFIER);
this._ios.registerClassForCellReuseIdentifier(UITableViewCell.class(), CELLIDENTIFIER);
this._ios.autoresizesSubviews = false;
this._ios.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;

Expand Down

Back | FazBrowse Home | New Git URL