Skip to content

Commit

Permalink
fix: cleanup the modal parent once closed.
Browse files Browse the repository at this point in the history
on iOS as the UILayoutViewController can be used for other widget we need to let it know it is for modal so that it still loads/unloads the view (there was a test for parent).
  • Loading branch information
farfromrefug committed Nov 16, 2023
1 parent cb7743c commit cb52301
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/core/ui/core/view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function initializeDialogFragment() {

owner._isAddedToNativeVisualTree = false;
owner._tearDownUI(true);
owner.parent = null;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/core/ui/core/view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,11 @@ export class View extends ViewCommon implements ViewDefinition {
this._setupAsRootView({});

super._showNativeModalView(<ViewCommon>parentWithController, options);
let controller = this.viewController;
let controller: IOSHelper.UILayoutViewController = this.viewController;
if (!controller) {
const nativeView = this.ios || this.nativeViewProtected;
controller = <UIViewController>IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(this));
controller = <IOSHelper.UILayoutViewController>IOSHelper.UILayoutViewController.initWithOwner(new WeakRef(this));
controller.modal = true;
this.parent = Application.getRootView();

if (nativeView instanceof UIView) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/ui/core/view/view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
}

this._tearDownUI(true);
this.parent = null;
}
};

Expand Down
3 changes: 2 additions & 1 deletion packages/core/ui/core/view/view-helper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ export namespace IOSHelper {
export function getFrameFromPosition(position: { left; top; right; bottom }, insets?: { left; top; right; bottom }): any; /* CGRect */
export function shrinkToSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */
export function expandBeyondSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */
export class UILayoutViewController {
export class UILayoutViewController extends UIViewController {
public static initWithOwner(owner: WeakRef<View>): UILayoutViewController;
modal?: boolean;
}
export class UIAdaptivePresentationControllerDelegateImp {
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp;
Expand Down
7 changes: 5 additions & 2 deletions packages/core/ui/core/view/view-helper/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export * from './view-helper-common';
@NativeClass
class UILayoutViewController extends UIViewController {
public owner: WeakRef<View>;
// used to know if we are a modal controller
// in this case the owner has a parent (rootView) but we still need to load/unload it
public modal;

public static initWithOwner(owner: WeakRef<View>): UILayoutViewController {
const controller = <UILayoutViewController>UILayoutViewController.new();
Expand Down Expand Up @@ -97,15 +100,15 @@ class UILayoutViewController extends UIViewController {

IOSHelper.updateAutoAdjustScrollInsets(this, owner);

if (!owner.isLoaded && !owner.parent) {
if (!owner.isLoaded && (!owner.parent || this.modal)) {
owner.callLoaded();
}
}

public viewDidDisappear(animated: boolean): void {
super.viewDidDisappear(animated);
const owner = this.owner?.deref();
if (owner && owner.isLoaded && !owner.parent) {
if (owner && owner.isLoaded && (!owner.parent || this.modal)) {
owner.callUnloaded();
}
}
Expand Down

0 comments on commit cb52301

Please sign in to comment.