Skip to content

Instantly share code, notes, and snippets.

@scarlac
Last active February 10, 2020 17:23
Show Gist options
  • Select an option

  • Save scarlac/ec162221e11927c52cfc9c94e7252824 to your computer and use it in GitHub Desktop.

Select an option

Save scarlac/ec162221e11927c52cfc9c94e7252824 to your computer and use it in GitHub Desktop.
Patch to trigger onDismiss for iOS 13-style pageSheet/formSheet modals
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..56bd0a6 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"
@@ -58,6 +59,8 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_modalViewController.boundsDidChangeBlock = ^(CGRect newBounds) {
[weakSelf notifyForBoundsChange:newBounds];
};
+
+ _modalViewController.presentationController.delegate = self;
}
return self;
@@ -156,6 +159,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