mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
Merge branch 'master' into merge-6.2.1-release-in-master
This commit is contained in:
@ -83,10 +83,15 @@ export interface ShowModalOptions {
|
||||
}
|
||||
android?: {
|
||||
/**
|
||||
* @deprecated Use ShowModalOptions.cancelable instead.
|
||||
* An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
|
||||
*/
|
||||
cancelable?: boolean
|
||||
}
|
||||
/**
|
||||
* An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
|
||||
*/
|
||||
cancelable?: boolean
|
||||
}
|
||||
|
||||
export abstract class ViewBase extends Observable {
|
||||
|
@ -640,12 +640,21 @@ export class View extends ViewCommon {
|
||||
args.putInt(DOMID, this._domId);
|
||||
df.setArguments(args);
|
||||
|
||||
let cancelable = true;
|
||||
|
||||
if (options.android && (<any>options).android.cancelable !== undefined) {
|
||||
cancelable = !!(<any>options).android.cancelable;
|
||||
console.log("ShowModalOptions.android.cancelable is deprecated. Use ShowModalOptions.cancelable instead.");
|
||||
}
|
||||
|
||||
cancelable = options.cancelable !== undefined ? !!options.cancelable : cancelable;
|
||||
|
||||
const dialogOptions: DialogOptions = {
|
||||
owner: this,
|
||||
fullscreen: !!options.fullscreen,
|
||||
animated: !!options.animated,
|
||||
stretched: !!options.stretched,
|
||||
cancelable: options.android ? !!options.android.cancelable : true,
|
||||
cancelable: cancelable,
|
||||
shownCallback: () => this._raiseShownModallyEvent(),
|
||||
dismissCallback: () => this.closeModal()
|
||||
};
|
||||
|
@ -30,6 +30,7 @@ export class View extends ViewCommon {
|
||||
nativeViewProtected: UIView;
|
||||
viewController: UIViewController;
|
||||
private _popoverPresentationDelegate: ios.UIPopoverPresentationControllerDelegateImp;
|
||||
private _adaptivePresentationDelegate: ios.UIAdaptivePresentationControllerDelegateImp;
|
||||
|
||||
private _isLaidOut = false;
|
||||
private _hasTransfrom = false;
|
||||
@ -422,14 +423,19 @@ export class View extends ViewCommon {
|
||||
controller.modalPresentationStyle = presentationStyle;
|
||||
|
||||
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
|
||||
popoverPresentationController.sourceView = view;
|
||||
popoverPresentationController.sourceRect = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height);
|
||||
this._setupPopoverControllerDelegate(controller, parent);
|
||||
}
|
||||
}
|
||||
|
||||
const cancelable = options.cancelable !== undefined ? !!options.cancelable : true;
|
||||
|
||||
if (majorVersion >= 13) {
|
||||
if (cancelable) {
|
||||
// Listen for dismiss modal callback.
|
||||
this._setupAdaptiveControllerDelegate(controller);
|
||||
} else {
|
||||
// Prevent users from dismissing the modal.
|
||||
(<any>controller).modalInPresentation = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -644,6 +650,22 @@ export class View extends ViewCommon {
|
||||
backgroundInternal.hasBorderWidth() ||
|
||||
backgroundInternal.hasBorderRadius();
|
||||
}
|
||||
|
||||
private _setupPopoverControllerDelegate(controller: UIViewController, parent: View) {
|
||||
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
|
||||
popoverPresentationController.sourceView = view;
|
||||
popoverPresentationController.sourceRect = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height);
|
||||
}
|
||||
|
||||
private _setupAdaptiveControllerDelegate(controller: UIViewController) {
|
||||
this._adaptivePresentationDelegate = ios.UIAdaptivePresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
|
||||
controller.presentationController.delegate = this._adaptivePresentationDelegate;
|
||||
}
|
||||
}
|
||||
View.prototype._nativeBackgroundState = "unset";
|
||||
|
||||
@ -1019,6 +1041,28 @@ export namespace ios {
|
||||
}
|
||||
}
|
||||
|
||||
export class UIAdaptivePresentationControllerDelegateImp extends NSObject implements UIAdaptivePresentationControllerDelegate {
|
||||
public static ObjCProtocols = [UIAdaptivePresentationControllerDelegate];
|
||||
|
||||
private owner: WeakRef<View>;
|
||||
private closedCallback: Function;
|
||||
|
||||
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp {
|
||||
const instance = <UIAdaptivePresentationControllerDelegateImp>super.new();
|
||||
instance.owner = owner;
|
||||
instance.closedCallback = whenClosedCallback;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public presentationControllerDidDismiss(presentationController: UIPresentationController) {
|
||||
const owner = this.owner.get();
|
||||
if (owner && typeof this.closedCallback === "function") {
|
||||
this.closedCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate {
|
||||
public static ObjCProtocols = [UIPopoverPresentationControllerDelegate];
|
||||
|
||||
|
@ -205,6 +205,11 @@ function showUIAlertController(alertController: UIAlertController) {
|
||||
if (currentView) {
|
||||
currentView = currentView.modal || currentView;
|
||||
|
||||
//get to the top most view controller on the stack
|
||||
while (currentView && currentView.modal) {
|
||||
currentView = currentView.modal;
|
||||
}
|
||||
|
||||
let viewController: UIViewController = currentView.ios;
|
||||
|
||||
if (viewController.presentedViewController) {
|
||||
|
Reference in New Issue
Block a user