Last active
February 10, 2020 17:23
-
-
Save scarlac/ec162221e11927c52cfc9c94e7252824 to your computer and use it in GitHub Desktop.
Patch to trigger onDismiss for iOS 13-style pageSheet/formSheet modals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-native/React/Views/RCTModalHostView.h b/node_modules/react-native/React/Views/RCTModalHostView.h | |
index e421e59..ba461e0 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostView.h | |
+++ b/node_modules/react-native/React/Views/RCTModalHostView.h | |
@@ -17,7 +17,7 @@ | |
@protocol RCTModalHostViewInteractor; | |
-@interface RCTModalHostView : UIView <RCTInvalidating> | |
+@interface RCTModalHostView : UIView <RCTInvalidating, UIAdaptivePresentationControllerDelegate> | |
@property (nonatomic, copy) NSString *animationType; | |
@property (nonatomic, assign) UIModalPresentationStyle presentationStyle; | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostView.m b/node_modules/react-native/React/Views/RCTModalHostView.m | |
index bc0cac1..7d36a9b 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostView.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostView.m | |
@@ -12,6 +12,7 @@ | |
#import "RCTAssert.h" | |
#import "RCTBridge.h" | |
#import "RCTModalHostViewController.h" | |
+#import "RCTModalManager.h" | |
#import "RCTTouchHandler.h" | |
#import "RCTUIManager.h" | |
#import "RCTUtils.h" | |
@@ -43,6 +44,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge | |
if ((self = [super initWithFrame:CGRectZero])) { | |
_bridge = bridge; | |
_modalViewController = [RCTModalHostViewController new]; | |
+ // Transparency breaks for overFullScreen in iOS < 13 | |
+ if (@available(iOS 13.0, *)) { | |
+ _modalViewController.presentationController.delegate = self; | |
+ } | |
UIView *containerView = [UIView new]; | |
containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | |
_modalViewController.view = containerView; | |
@@ -63,6 +68,24 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge | |
return self; | |
} | |
+// Method must be implemented, otherwise iOS defaults to 'automatic' (pageSheet on >= iOS 13.0) | |
+- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection | |
+{ | |
+ if (self.presentationStyle == UIModalPresentationFullScreen && self.isTransparent) { | |
+ return UIModalPresentationOverFullScreen; | |
+ } | |
+ return self.presentationStyle; | |
+} | |
+ | |
+// Method must be implemented, otherwise iOS defaults to 'automatic' (pageSheet on >= iOS 13.0) | |
+- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller | |
+{ | |
+ if (self.presentationStyle == UIModalPresentationFullScreen && self.isTransparent) { | |
+ return UIModalPresentationOverFullScreen; | |
+ } | |
+ return self.presentationStyle; | |
+} | |
+ | |
#if TARGET_OS_TV | |
- (void)menuButtonPressed:(__unused UIGestureRecognizer *)gestureRecognizer | |
{ | |
@@ -156,6 +179,14 @@ - (void)didUpdateReactSubviews | |
// Do nothing, as subview (singular) is managed by `insertReactSubview:atIndex:` | |
} | |
+- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController | |
+{ | |
+ // Modal is already dismissed so trigger onDismiss, etc. | |
+ if (self.identifier) { | |
+ [[_bridge moduleForClass:[RCTModalManager class]] modalDismissed:self.identifier]; | |
+ } | |
+} | |
+ | |
- (void)dismissModalViewController | |
{ | |
if (_isPresented) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment