mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(ios-modal): closeCallback not being called with popover presentation style (#7189)
This commit is contained in:
committed by
GitHub
parent
77c45da790
commit
aa44eb950e
@@ -22,6 +22,7 @@ import {
|
||||
} from "../../gestures";
|
||||
|
||||
import { createViewFromEntry } from "../../builder";
|
||||
import { isAndroid } from "../../../platform";
|
||||
import { StyleScope } from "../../styling/style-scope";
|
||||
import { LinearGradient } from "../../styling/linear-gradient";
|
||||
import { BackgroundRepeat } from "../../styling/style-properties";
|
||||
@@ -324,7 +325,11 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
that._hideNativeModalView(parent, whenClosedCallback);
|
||||
if (isAndroid || (parent.viewController && parent.viewController.presentedViewController)) {
|
||||
that._hideNativeModalView(parent, whenClosedCallback);
|
||||
} else {
|
||||
whenClosedCallback();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ const majorVersion = iosUtils.MajorVersion;
|
||||
export class View extends ViewCommon {
|
||||
nativeViewProtected: UIView;
|
||||
viewController: UIViewController;
|
||||
private _popoverPresentationDelegate: ios.UIPopoverPresentationControllerDelegateImp;
|
||||
|
||||
private _isLaidOut = false;
|
||||
private _hasTransfrom = false;
|
||||
@@ -416,6 +417,8 @@ export class View extends ViewCommon {
|
||||
|
||||
if (presentationStyle === UIModalPresentationStyle.Popover) {
|
||||
const popoverPresentationController = controller.popoverPresentationController;
|
||||
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
|
||||
popoverPresentationController.delegate = this._popoverPresentationDelegate;
|
||||
const view = parent.nativeViewProtected;
|
||||
// Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
|
||||
// Note: sourceView should be the button triggering the modal. If it the Page the popover might appear "behind" the page content
|
||||
@@ -906,7 +909,7 @@ export namespace ios {
|
||||
|
||||
public viewDidLoad(): void {
|
||||
super.viewDidLoad();
|
||||
|
||||
|
||||
// Unify translucent and opaque bars layout
|
||||
// this.edgesForExtendedLayout = UIRectEdgeBottom;
|
||||
this.extendedLayoutIncludesOpaqueBars = true;
|
||||
@@ -982,4 +985,26 @@ export namespace ios {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate {
|
||||
public static ObjCProtocols = [UIPopoverPresentationControllerDelegate];
|
||||
|
||||
private owner: WeakRef<View>;
|
||||
private closedCallback: Function;
|
||||
|
||||
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp {
|
||||
const instance = <UIPopoverPresentationControllerDelegateImp>super.new();
|
||||
instance.owner = owner;
|
||||
instance.closedCallback = whenClosedCallback;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
|
||||
const owner = this.owner.get();
|
||||
if (owner && typeof this.closedCallback === "function") {
|
||||
this.closedCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user