fix-next(modal) fix crash when closing modal dialog with root tabview inside (#5446)

This commit is contained in:
Manol Donev
2018-02-23 16:46:49 +02:00
committed by GitHub
parent 9423ae40fa
commit 4898c33a04
4 changed files with 68 additions and 12 deletions

View File

@ -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<TabViewItem>();
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 = <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

View File

@ -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

View File

@ -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 {

View File

@ -461,6 +461,10 @@ export class TabView extends TabViewBase {
}
private shouldUpdateAdapter(items: Array<TabViewItemDefinition>) {
if (!this._pagerAdapter) {
return false;
}
const currentPagerAdapterItems = (<any>this._pagerAdapter).items;
// if both values are null, should not update