From 4898c33a04b101c53319824ce868e9ca57a517ce Mon Sep 17 00:00:00 2001 From: Manol Donev Date: Fri, 23 Feb 2018 16:46:49 +0200 Subject: [PATCH] fix-next(modal) fix crash when closing modal dialog with root tabview inside (#5446) --- tests/app/ui/page/page-tests-common.ts | 55 +++++++++++++++++++ tests/app/ui/tab-view/tab-view-tests.ts | 6 +- tns-core-modules/ui/core/view/view.android.ts | 15 ++--- .../ui/tab-view/tab-view.android.ts | 4 ++ 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/tests/app/ui/page/page-tests-common.ts b/tests/app/ui/page/page-tests-common.ts index 3ed63cb6f..3e344fe6b 100644 --- a/tests/app/ui/page/page-tests-common.ts +++ b/tests/app/ui/page/page-tests-common.ts @@ -22,6 +22,7 @@ import { View, PercentLength, Observable, unsetValue, EventData, isIOS } from "t import { Frame, stack } from "tns-core-modules/ui/frame"; import { Label } from "tns-core-modules/ui/label"; import { Color } from "tns-core-modules/color"; +import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view/tab-view"; export function addLabelToPage(page: Page, text?: string) { const label = new Label(); @@ -460,6 +461,60 @@ export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() { helper.goBack(); } +export function test_WhenRootTabViewShownModallyItCanCloseModal() { + let modalClosed = false; + + const modalCloseCallback = function (returnValue: any) { + modalClosed = true; + } + + const createTabItems = function(count: number) { + var items = new Array(); + + for (var i = 0; i < count; i++) { + var label = new Label(); + label.text = "Tab " + i; + var tabEntry = new TabViewItem(); + tabEntry.title = "Tab " + i; + tabEntry.view = label; + + items.push(tabEntry); + } + + return items; + } + + const tabViewShownModallyEventHandler = function(args: ShownModallyData) { + args.closeCallback("return value"); + } + + const hostNavigatedToEventHandler = function(args) { + const page = args.object; + page.off(Page.navigatedToEvent, hostNavigatedToEventHandler); + + const tabView = new TabView(); + tabView.items = createTabItems(2); + tabView.on(View.shownModallyEvent, tabViewShownModallyEventHandler); + + page.showModal(tabView, {}, modalCloseCallback, false, false); + } + + const masterPageFactory = function(): Page { + const masterPage = new Page(); + masterPage.id = "masterPage_test_WhenRootTabViewShownModallyItCanCloseModal"; + masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler); + + const label = new Label(); + label.text = "Text"; + masterPage.content = label; + return masterPage; + }; + + helper.navigate(masterPageFactory); + + TKUnit.waitUntilReady(() => modalClosed); +} + export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() { // if (platform.device.os === platform.platformNames.android // && android.os.Build.VERSION.SDK_INT === android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 diff --git a/tests/app/ui/tab-view/tab-view-tests.ts b/tests/app/ui/tab-view/tab-view-tests.ts index 6ee5d9703..2c2853d1b 100644 --- a/tests/app/ui/tab-view/tab-view-tests.ts +++ b/tests/app/ui/tab-view/tab-view-tests.ts @@ -2,9 +2,9 @@ import { UITest } from "../../ui-test"; import { Label } from "tns-core-modules/ui/label"; import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout"; import { unsetValue } from "tns-core-modules/ui/core/view"; -import TKUnit = require("../../TKUnit"); -import helper = require("../helper"); -import tabViewTestsNative = require("./tab-view-tests-native"); +import * as TKUnit from "../../TKUnit"; +import * as helper from "../helper"; +import * as tabViewTestsNative from "./tab-view-tests-native"; // Using a TabView requires the "ui/tab-view" module. // >> article-require-tabview-module diff --git a/tns-core-modules/ui/core/view/view.android.ts b/tns-core-modules/ui/core/view/view.android.ts index 7584e2e9b..a96090764 100644 --- a/tns-core-modules/ui/core/view/view.android.ts +++ b/tns-core-modules/ui/core/view/view.android.ts @@ -175,15 +175,7 @@ function initializeDialogFragment() { this._shownCallback(); } - - public onStop(): void { - super.onStop(); - const owner = this.owner; - if (owner.isLoaded) { - owner.callUnloaded(); - } - } - + public onDismiss(dialog: android.content.IDialogInterface): void { super.onDismiss(dialog); const manager = this.getFragmentManager(); @@ -191,6 +183,11 @@ function initializeDialogFragment() { removeModal(this.owner._domId); this._dismissCallback(); } + + const owner = this.owner; + if (owner.isLoaded) { + owner.callUnloaded(); + } } public onDestroy(): void { diff --git a/tns-core-modules/ui/tab-view/tab-view.android.ts b/tns-core-modules/ui/tab-view/tab-view.android.ts index cde0073ca..1c6ade69f 100644 --- a/tns-core-modules/ui/tab-view/tab-view.android.ts +++ b/tns-core-modules/ui/tab-view/tab-view.android.ts @@ -461,6 +461,10 @@ export class TabView extends TabViewBase { } private shouldUpdateAdapter(items: Array) { + if (!this._pagerAdapter) { + return false; + } + const currentPagerAdapterItems = (this._pagerAdapter).items; // if both values are null, should not update