@@ -29,6 +29,7 @@ const majorVersion = iosUtils.MajorVersion;
2929export class View extends ViewCommon {
3030 nativeViewProtected : UIView ;
3131 viewController : UIViewController ;
32+ private _popoverPresentationDelegate : ios . UIPopoverPresentationControllerDelegateImp ;
3233
3334 private _isLaidOut = false ;
3435 private _hasTransfrom = false ;
@@ -416,6 +417,8 @@ export class View extends ViewCommon {
416417
417418 if ( presentationStyle === UIModalPresentationStyle . Popover ) {
418419 const popoverPresentationController = controller . popoverPresentationController ;
420+ this . _popoverPresentationDelegate = ios . UIPopoverPresentationControllerDelegateImp . initWithOwnerAndCallback ( new WeakRef ( this ) , this . _closeModalCallback ) ;
421+ popoverPresentationController . delegate = this . _popoverPresentationDelegate ;
419422 const view = parent . nativeViewProtected ;
420423 // Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
421424 // 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 {
906909
907910 public viewDidLoad ( ) : void {
908911 super . viewDidLoad ( ) ;
909-
912+
910913 // Unify translucent and opaque bars layout
911914 // this.edgesForExtendedLayout = UIRectEdgeBottom;
912915 this . extendedLayoutIncludesOpaqueBars = true ;
@@ -982,4 +985,26 @@ export namespace ios {
982985 }
983986 }
984987 }
988+
989+ export class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate {
990+ public static ObjCProtocols = [ UIPopoverPresentationControllerDelegate ] ;
991+
992+ private owner : WeakRef < View > ;
993+ private closedCallback : Function ;
994+
995+ public static initWithOwnerAndCallback ( owner : WeakRef < View > , whenClosedCallback : Function ) : UIPopoverPresentationControllerDelegateImp {
996+ const instance = < UIPopoverPresentationControllerDelegateImp > super . new ( ) ;
997+ instance . owner = owner ;
998+ instance . closedCallback = whenClosedCallback ;
999+
1000+ return instance ;
1001+ }
1002+
1003+ public popoverPresentationControllerDidDismissPopover ( popoverPresentationController : UIPopoverPresentationController ) {
1004+ const owner = this . owner . get ( ) ;
1005+ if ( owner && typeof this . closedCallback === "function" ) {
1006+ this . closedCallback ( ) ;
1007+ }
1008+ }
1009+ }
9851010}
0 commit comments