mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Merge pull request #2263 from NativeScript/nnikoilov/ListViewUsedInAModalDialogCrash
Fixed crash when ListView is used in a modal dialog (Android).
This commit is contained in:
@ -558,6 +558,38 @@ export class ListViewTest extends testModule.UITest<listViewModule.ListView> {
|
||||
}
|
||||
}
|
||||
|
||||
public test_RemovingChildViewsBeforeListView() {
|
||||
var listView = this.testView;
|
||||
var converterCalledCounter = 0;
|
||||
|
||||
var testConverter = function (value) {
|
||||
converterCalledCounter++;
|
||||
return value;
|
||||
}
|
||||
|
||||
app.resources["testConverter"] = testConverter;
|
||||
|
||||
var listViewModel = new observable.Observable();
|
||||
listViewModel.set("items", [1, 2, 3]);
|
||||
listView.bindingContext = listViewModel;
|
||||
|
||||
listView.bind({ sourceProperty: "items", targetProperty: "items" });
|
||||
listView.itemTemplate = "<StackLayout><Label id=\"testLabel\" text=\"{{ $value, $value | testConverter }}\" /></StackLayout>";
|
||||
|
||||
this.waitUntilListViewReady();
|
||||
|
||||
if (platform.isAndroid) {
|
||||
// simulates Angular way of removing views
|
||||
(<any>listView)._realizedItems.forEach((view, nativeView, map) => {
|
||||
console.log("view: " + view);
|
||||
listView._removeView(view);
|
||||
});
|
||||
this.tearDown();
|
||||
// should not crash
|
||||
TKUnit.assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
public test_no_memory_leak_when_items_is_regular_array() {
|
||||
let weakRef = new WeakRef<listViewModule.ListView>(this.testView);
|
||||
weakRef.get().items = FEW_ITEMS;
|
||||
|
@ -108,7 +108,10 @@ export class ListView extends common.ListView {
|
||||
callback(view);
|
||||
}
|
||||
else {
|
||||
callback(view.parent);
|
||||
// in some cases (like item is unloaded from another place (like angular) view.parent becomes undefined)
|
||||
if (view.parent) {
|
||||
callback(view.parent);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -124,12 +127,13 @@ export class ListView extends common.ListView {
|
||||
private clearRealizedCells(): void {
|
||||
// clear the cache
|
||||
this._realizedItems.forEach((view, nativeView, map) => {
|
||||
// This is to clear the StackLayout that is used to wrap non LayoutBase & ProxyViewContainer instances.
|
||||
if (!(view.parent instanceof ListView)) {
|
||||
this._removeView(view.parent);
|
||||
if (view.parent) {
|
||||
// This is to clear the StackLayout that is used to wrap non LayoutBase & ProxyViewContainer instances.
|
||||
if (!(view.parent instanceof ListView)) {
|
||||
this._removeView(view.parent);
|
||||
}
|
||||
view.parent._removeView(view);
|
||||
}
|
||||
|
||||
view.parent._removeView(view);
|
||||
});
|
||||
|
||||
this._realizedItems.clear();
|
||||
|
Reference in New Issue
Block a user