fix(modal): persist modal through configuration changes (#9533)

This commit is contained in:
Eduardo Speroni
2021-09-03 22:41:49 -03:00
committed by GitHub
parent a93bab2c8c
commit f3cd3d3375
4 changed files with 34 additions and 12 deletions

View File

@@ -1,10 +1,11 @@
import { ControlStateChangeListener } from '../core/control-state-change';
import { ButtonBase } from './button-common';
import { View, PseudoClassHandler } from '../core/view';
import { borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty } from '../styling/style-properties';
import { backgroundColorProperty, borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, paddingLeftProperty, paddingTopProperty, paddingRightProperty, paddingBottomProperty } from '../styling/style-properties';
import { textAlignmentProperty, whiteSpaceProperty } from '../text-base';
import { layout } from '../../utils';
import { CoreTypes } from '../../core-types';
import { Color } from '../../color';
export * from './button-common';
@@ -56,6 +57,14 @@ export class Button extends ButtonBase {
}
}
[backgroundColorProperty.getDefault](): UIColor {
return this.nativeViewProtected.backgroundColor;
}
[backgroundColorProperty.setNative](value: UIColor | Color) {
this.nativeViewProtected.backgroundColor = value instanceof Color ? value.ios : value;
}
[borderTopWidthProperty.getDefault](): CoreTypes.LengthType {
return {
value: this.nativeViewProtected.contentEdgeInsets.top,

View File

@@ -161,6 +161,7 @@ function initializeDialogFragment() {
private _cancelable: boolean;
private _shownCallback: () => void;
private _dismissCallback: () => void;
private activity: WeakRef<android.app.Activity>;
constructor() {
super();
@@ -215,6 +216,7 @@ function initializeDialogFragment() {
public onCreateView(inflater: android.view.LayoutInflater, container: android.view.ViewGroup, savedInstanceState: android.os.Bundle): android.view.View {
const owner = this.owner;
this.activity = new WeakRef(this.getActivity());
owner._setupAsRootView(this.getActivity());
owner._isAddedToNativeVisualTree = true;
@@ -252,7 +254,8 @@ function initializeDialogFragment() {
public onDismiss(dialog: android.content.DialogInterface): void {
super.onDismiss(dialog);
const manager = this.getFragmentManager();
if (manager) {
const activity = this.activity?.get();
if (manager && !activity?.isChangingConfigurations()) {
removeModal(this.owner._domId);
this._dismissCallback();
}
@@ -266,6 +269,10 @@ function initializeDialogFragment() {
public onDestroy(): void {
super.onDestroy();
const owner = this.owner;
const activity = this.activity?.get();
if (!activity?.isChangingConfigurations()) {
this.activity = null;
}
if (owner) {
// Android calls onDestroy before onDismiss.

View File

@@ -1189,12 +1189,18 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
rootView._tearDownUI(true);
}
const exitArgs = {
eventName: application.exitEvent,
object: application.android,
android: activity,
};
application.notify(exitArgs);
// this may happen when the user changes the system theme
// In such case, isFinishing() is false (and isChangingConfigurations is true), and the app will start again (onCreate) with a savedInstanceState
// as a result, launchEvent will never be called
// possible alternative: always fire launchEvent and exitEvent, but pass extra flags to make it clear what kind of launch/destroy is happening
if (activity.isFinishing()) {
const exitArgs = {
eventName: application.exitEvent,
object: application.android,
android: activity,
};
application.notify(exitArgs);
}
} finally {
superFunc.call(activity);
}

View File

@@ -404,13 +404,13 @@ class UINavigationControllerImpl extends UINavigationController {
}
get owner(): Frame {
return this._owner.get();
return this._owner.get?.();
}
@profile
public viewWillAppear(animated: boolean): void {
super.viewWillAppear(animated);
const owner = this._owner.get();
const owner = this._owner.get?.();
if (owner && !owner.isLoaded && !owner.parent) {
owner.callLoaded();
}
@@ -419,7 +419,7 @@ class UINavigationControllerImpl extends UINavigationController {
@profile
public viewDidDisappear(animated: boolean): void {
super.viewDidDisappear(animated);
const owner = this._owner?.get();
const owner = this._owner?.get?.();
if (owner && owner.isLoaded && !owner.parent && !this.presentedViewController) {
owner.callUnloaded();
owner._tearDownUI(true);
@@ -543,7 +543,7 @@ class UINavigationControllerImpl extends UINavigationController {
super.traitCollectionDidChange(previousTraitCollection);
if (majorVersion >= 13) {
const owner = this._owner.get();
const owner = this._owner.get?.();
if (owner && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection && this.traitCollection.hasDifferentColorAppearanceComparedToTraitCollection(previousTraitCollection)) {
owner.notify({
eventName: IOSHelper.traitCollectionColorAppearanceChangedEvent,