mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
The unloaded event of view in the ListView's itemTemplate will now be called when its underlying native view is removed from the visual tree. When this happens is beyond our control.
This commit is contained in:
@@ -36,6 +36,7 @@ export class ListView extends common.ListView {
|
||||
private _android: android.widget.ListView;
|
||||
public _realizedItems = {};
|
||||
private _androidViewId: number;
|
||||
public _attachStateChangeListener: android.view.View.OnAttachStateChangeListener;
|
||||
|
||||
public _createUI() {
|
||||
this._android = new android.widget.ListView(this._context);
|
||||
@@ -90,6 +91,28 @@ export class ListView extends common.ListView {
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
this._attachStateChangeListener = new android.view.View.OnAttachStateChangeListener({
|
||||
get owner() {
|
||||
return that.get();
|
||||
},
|
||||
|
||||
onViewAttachedToWindow: function (view: android.view.View) {
|
||||
//
|
||||
},
|
||||
onViewDetachedFromWindow: function (androidView: android.view.View) {
|
||||
var owner = that.get();
|
||||
if (!owner) {
|
||||
return;
|
||||
}
|
||||
|
||||
var view: viewModule.View = this.owner._realizedItems[androidView.hashCode()];
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
view.onUnloaded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
get android(): android.widget.ListView {
|
||||
@@ -213,6 +236,10 @@ class ListViewAdapter extends android.widget.BaseAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
if (!this._listView._realizedItems[convertView.hashCode()]) {
|
||||
convertView.addOnAttachStateChangeListener(this._listView._attachStateChangeListener);
|
||||
}
|
||||
|
||||
this._listView._realizedItems[convertView.hashCode()] = args.view;
|
||||
// cache the realized index (used to raise the ItemLoading event upon scroll stop)
|
||||
args.view[REALIZED_INDEX] = index;
|
||||
@@ -222,4 +249,5 @@ class ListViewAdapter extends android.widget.BaseAdapter {
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,14 @@ class ListViewCell extends UITableViewCell {
|
||||
static new(): ListViewCell {
|
||||
return <ListViewCell>super.new();
|
||||
}
|
||||
|
||||
public removeFromSuperview(): void {
|
||||
super.removeFromSuperview();
|
||||
var view: view.View = (<any>this).view;
|
||||
if (view) {
|
||||
view.onUnloaded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function notifyForItemAtIndex(listView: definition.ListView, cell: any, eventName: string, indexPath: NSIndexPath) {
|
||||
|
||||
Reference in New Issue
Block a user