Skip to content

Commit 4898c33

Browse files
authored
fix-next(modal) fix crash when closing modal dialog with root tabview inside (NativeScript#5446)
1 parent 9423ae4 commit 4898c33

File tree

4 files changed

+68
-12
lines changed

4 files changed

+68
-12
lines changed

tests/app/ui/page/page-tests-common.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { View, PercentLength, Observable, unsetValue, EventData, isIOS } from "t
2222
import { Frame, stack } from "tns-core-modules/ui/frame";
2323
import { Label } from "tns-core-modules/ui/label";
2424
import { Color } from "tns-core-modules/color";
25+
import { TabView, TabViewItem } from "tns-core-modules/ui/tab-view/tab-view";
2526

2627
export function addLabelToPage(page: Page, text?: string) {
2728
const label = new Label();
@@ -460,6 +461,60 @@ export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() {
460461
helper.goBack();
461462
}
462463

464+
export function test_WhenRootTabViewShownModallyItCanCloseModal() {
465+
let modalClosed = false;
466+
467+
const modalCloseCallback = function (returnValue: any) {
468+
modalClosed = true;
469+
}
470+
471+
const createTabItems = function(count: number) {
472+
var items = new Array<TabViewItem>();
473+
474+
for (var i = 0; i < count; i++) {
475+
var label = new Label();
476+
label.text = "Tab " + i;
477+
var tabEntry = new TabViewItem();
478+
tabEntry.title = "Tab " + i;
479+
tabEntry.view = label;
480+
481+
items.push(tabEntry);
482+
}
483+
484+
return items;
485+
}
486+
487+
const tabViewShownModallyEventHandler = function(args: ShownModallyData) {
488+
args.closeCallback("return value");
489+
}
490+
491+
const hostNavigatedToEventHandler = function(args) {
492+
const page = <Page>args.object;
493+
page.off(Page.navigatedToEvent, hostNavigatedToEventHandler);
494+
495+
const tabView = new TabView();
496+
tabView.items = createTabItems(2);
497+
tabView.on(View.shownModallyEvent, tabViewShownModallyEventHandler);
498+
499+
page.showModal(tabView, {}, modalCloseCallback, false, false);
500+
}
501+
502+
const masterPageFactory = function(): Page {
503+
const masterPage = new Page();
504+
masterPage.id = "masterPage_test_WhenRootTabViewShownModallyItCanCloseModal";
505+
masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler);
506+
507+
const label = new Label();
508+
label.text = "Text";
509+
masterPage.content = label;
510+
return masterPage;
511+
};
512+
513+
helper.navigate(masterPageFactory);
514+
515+
TKUnit.waitUntilReady(() => modalClosed);
516+
}
517+
463518
export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
464519
// if (platform.device.os === platform.platformNames.android
465520
// && android.os.Build.VERSION.SDK_INT === android.os.Build.VERSION_CODES.JELLY_BEAN_MR1

tests/app/ui/tab-view/tab-view-tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { UITest } from "../../ui-test";
22
import { Label } from "tns-core-modules/ui/label";
33
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
44
import { unsetValue } from "tns-core-modules/ui/core/view";
5-
import TKUnit = require("../../TKUnit");
6-
import helper = require("../helper");
7-
import tabViewTestsNative = require("./tab-view-tests-native");
5+
import * as TKUnit from "../../TKUnit";
6+
import * as helper from "../helper";
7+
import * as tabViewTestsNative from "./tab-view-tests-native";
88

99
// Using a TabView requires the "ui/tab-view" module.
1010
// >> article-require-tabview-module

tns-core-modules/ui/core/view/view.android.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,19 @@ function initializeDialogFragment() {
175175

176176
this._shownCallback();
177177
}
178-
179-
public onStop(): void {
180-
super.onStop();
181-
const owner = this.owner;
182-
if (owner.isLoaded) {
183-
owner.callUnloaded();
184-
}
185-
}
186-
178+
187179
public onDismiss(dialog: android.content.IDialogInterface): void {
188180
super.onDismiss(dialog);
189181
const manager = this.getFragmentManager();
190182
if (manager) {
191183
removeModal(this.owner._domId);
192184
this._dismissCallback();
193185
}
186+
187+
const owner = this.owner;
188+
if (owner.isLoaded) {
189+
owner.callUnloaded();
190+
}
194191
}
195192

196193
public onDestroy(): void {

tns-core-modules/ui/tab-view/tab-view.android.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,10 @@ export class TabView extends TabViewBase {
461461
}
462462

463463
private shouldUpdateAdapter(items: Array<TabViewItemDefinition>) {
464+
if (!this._pagerAdapter) {
465+
return false;
466+
}
467+
464468
const currentPagerAdapterItems = (<any>this._pagerAdapter).items;
465469

466470
// if both values are null, should not update

0 commit comments

Comments
 (0)