@@ -30,6 +30,7 @@ export class View extends ViewCommon {
3030 nativeViewProtected : UIView ;
3131 viewController : UIViewController ;
3232 private _popoverPresentationDelegate : ios . UIPopoverPresentationControllerDelegateImp ;
33+ private _adaptivePresentationDelegate : ios . UIAdaptivePresentationControllerDelegateImp ;
3334
3435 private _isLaidOut = false ;
3536 private _hasTransfrom = false ;
@@ -422,14 +423,19 @@ export class View extends ViewCommon {
422423 controller . modalPresentationStyle = presentationStyle ;
423424
424425 if ( presentationStyle === UIModalPresentationStyle . Popover ) {
425- const popoverPresentationController = controller . popoverPresentationController ;
426- this . _popoverPresentationDelegate = ios . UIPopoverPresentationControllerDelegateImp . initWithOwnerAndCallback ( new WeakRef ( this ) , this . _closeModalCallback ) ;
427- popoverPresentationController . delegate = this . _popoverPresentationDelegate ;
428- const view = parent . nativeViewProtected ;
429- // Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
430- // Note: sourceView should be the button triggering the modal. If it the Page the popover might appear "behind" the page content
431- popoverPresentationController . sourceView = view ;
432- popoverPresentationController . sourceRect = CGRectMake ( 0 , 0 , view . frame . size . width , view . frame . size . height ) ;
426+ this . _setupPopoverControllerDelegate ( controller , parent ) ;
427+ }
428+ }
429+
430+ const cancelable = options . cancelable !== undefined ? ! ! options . cancelable : true ;
431+
432+ if ( majorVersion >= 13 ) {
433+ if ( cancelable ) {
434+ // Listen for dismiss modal callback.
435+ this . _setupAdaptiveControllerDelegate ( controller ) ;
436+ } else {
437+ // Prevent users from dismissing the modal.
438+ ( < any > controller ) . modalInPresentation = true ;
433439 }
434440 }
435441
@@ -644,6 +650,22 @@ export class View extends ViewCommon {
644650 backgroundInternal . hasBorderWidth ( ) ||
645651 backgroundInternal . hasBorderRadius ( ) ;
646652 }
653+
654+ private _setupPopoverControllerDelegate ( controller : UIViewController , parent : View ) {
655+ const popoverPresentationController = controller . popoverPresentationController ;
656+ this . _popoverPresentationDelegate = ios . UIPopoverPresentationControllerDelegateImp . initWithOwnerAndCallback ( new WeakRef ( this ) , this . _closeModalCallback ) ;
657+ popoverPresentationController . delegate = this . _popoverPresentationDelegate ;
658+ const view = parent . nativeViewProtected ;
659+ // Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
660+ // Note: sourceView should be the button triggering the modal. If it the Page the popover might appear "behind" the page content
661+ popoverPresentationController . sourceView = view ;
662+ popoverPresentationController . sourceRect = CGRectMake ( 0 , 0 , view . frame . size . width , view . frame . size . height ) ;
663+ }
664+
665+ private _setupAdaptiveControllerDelegate ( controller : UIViewController ) {
666+ this . _adaptivePresentationDelegate = ios . UIAdaptivePresentationControllerDelegateImp . initWithOwnerAndCallback ( new WeakRef ( this ) , this . _closeModalCallback ) ;
667+ controller . presentationController . delegate = this . _adaptivePresentationDelegate ;
668+ }
647669}
648670View . prototype . _nativeBackgroundState = "unset" ;
649671
@@ -1019,6 +1041,28 @@ export namespace ios {
10191041 }
10201042 }
10211043
1044+ export class UIAdaptivePresentationControllerDelegateImp extends NSObject implements UIAdaptivePresentationControllerDelegate {
1045+ public static ObjCProtocols = [ UIAdaptivePresentationControllerDelegate ] ;
1046+
1047+ private owner : WeakRef < View > ;
1048+ private closedCallback : Function ;
1049+
1050+ public static initWithOwnerAndCallback ( owner : WeakRef < View > , whenClosedCallback : Function ) : UIAdaptivePresentationControllerDelegateImp {
1051+ const instance = < UIAdaptivePresentationControllerDelegateImp > super . new ( ) ;
1052+ instance . owner = owner ;
1053+ instance . closedCallback = whenClosedCallback ;
1054+
1055+ return instance ;
1056+ }
1057+
1058+ public presentationControllerDidDismiss ( presentationController : UIPresentationController ) {
1059+ const owner = this . owner . get ( ) ;
1060+ if ( owner && typeof this . closedCallback === "function" ) {
1061+ this . closedCallback ( ) ;
1062+ }
1063+ }
1064+ }
1065+
10221066 export class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate {
10231067 public static ObjCProtocols = [ UIPopoverPresentationControllerDelegate ] ;
10241068
0 commit comments