mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
fix-next(modal) fix crash when closing modal dialog with root tabview inside (#5446)
This commit is contained in:
@ -22,6 +22,7 @@ import { View, PercentLength, Observable, unsetValue, EventData, isIOS } from "t
|
|||||||
import { Frame, stack } from "tns-core-modules/ui/frame";
|
import { Frame, stack } from "tns-core-modules/ui/frame";
|
||||||
import { Label } from "tns-core-modules/ui/label";
|
import { Label } from "tns-core-modules/ui/label";
|
||||||
import { Color } from "tns-core-modules/color";
|
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) {
|
export function addLabelToPage(page: Page, text?: string) {
|
||||||
const label = new Label();
|
const label = new Label();
|
||||||
@ -460,6 +461,60 @@ export function test_WhenNavigatingForwardAndBack_IsBackNavigationIsCorrect() {
|
|||||||
helper.goBack();
|
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() {
|
export function test_WhenPageIsNavigatedToItCanShowAnotherPageAsModal() {
|
||||||
// if (platform.device.os === platform.platformNames.android
|
// if (platform.device.os === platform.platformNames.android
|
||||||
// && android.os.Build.VERSION.SDK_INT === android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
|
// && android.os.Build.VERSION.SDK_INT === android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
|
||||||
|
@ -2,9 +2,9 @@ import { UITest } from "../../ui-test";
|
|||||||
import { Label } from "tns-core-modules/ui/label";
|
import { Label } from "tns-core-modules/ui/label";
|
||||||
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
|
||||||
import { unsetValue } from "tns-core-modules/ui/core/view";
|
import { unsetValue } from "tns-core-modules/ui/core/view";
|
||||||
import TKUnit = require("../../TKUnit");
|
import * as TKUnit from "../../TKUnit";
|
||||||
import helper = require("../helper");
|
import * as helper from "../helper";
|
||||||
import tabViewTestsNative = require("./tab-view-tests-native");
|
import * as tabViewTestsNative from "./tab-view-tests-native";
|
||||||
|
|
||||||
// Using a TabView requires the "ui/tab-view" module.
|
// Using a TabView requires the "ui/tab-view" module.
|
||||||
// >> article-require-tabview-module
|
// >> article-require-tabview-module
|
||||||
|
@ -175,15 +175,7 @@ function initializeDialogFragment() {
|
|||||||
|
|
||||||
this._shownCallback();
|
this._shownCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onStop(): void {
|
|
||||||
super.onStop();
|
|
||||||
const owner = this.owner;
|
|
||||||
if (owner.isLoaded) {
|
|
||||||
owner.callUnloaded();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public onDismiss(dialog: android.content.IDialogInterface): void {
|
public onDismiss(dialog: android.content.IDialogInterface): void {
|
||||||
super.onDismiss(dialog);
|
super.onDismiss(dialog);
|
||||||
const manager = this.getFragmentManager();
|
const manager = this.getFragmentManager();
|
||||||
@ -191,6 +183,11 @@ function initializeDialogFragment() {
|
|||||||
removeModal(this.owner._domId);
|
removeModal(this.owner._domId);
|
||||||
this._dismissCallback();
|
this._dismissCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const owner = this.owner;
|
||||||
|
if (owner.isLoaded) {
|
||||||
|
owner.callUnloaded();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public onDestroy(): void {
|
public onDestroy(): void {
|
||||||
|
@ -461,6 +461,10 @@ export class TabView extends TabViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private shouldUpdateAdapter(items: Array<TabViewItemDefinition>) {
|
private shouldUpdateAdapter(items: Array<TabViewItemDefinition>) {
|
||||||
|
if (!this._pagerAdapter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const currentPagerAdapterItems = (<any>this._pagerAdapter).items;
|
const currentPagerAdapterItems = (<any>this._pagerAdapter).items;
|
||||||
|
|
||||||
// if both values are null, should not update
|
// if both values are null, should not update
|
||||||
|
Reference in New Issue
Block a user