Last active
July 6, 2022 05:58
-
-
Save r0b0t3d/3c9f77434e6fbcfa78698dcf57614fad to your computer and use it in GitHub Desktop.
[ios] Trigger onRequestClose when swiping down a pageSheet
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 e16dd22..97f24a6 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; | |
@@ -31,9 +31,9 @@ | |
@property (nonatomic, copy) NSArray<NSString *> *supportedOrientations; | |
@property (nonatomic, copy) RCTDirectEventBlock onOrientationChange; | |
+@property (nonatomic, copy) RCTDirectEventBlock onRequestClose; | |
#if TARGET_OS_TV | |
-@property (nonatomic, copy) RCTDirectEventBlock onRequestClose; | |
@property (nonatomic, strong) RCTTVRemoteHandler *tvRemoteHandler; | |
#endif | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostView.m b/node_modules/react-native/React/Views/RCTModalHostView.m | |
index 95d572b..7e4f4c4 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostView.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostView.m | |
@@ -43,6 +43,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 +67,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 | |
{ | |
@@ -70,10 +92,12 @@ - (void)menuButtonPressed:(__unused UIGestureRecognizer *)gestureRecognizer | |
_onRequestClose(nil); | |
} | |
} | |
+#endif | |
- (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose | |
{ | |
_onRequestClose = onRequestClose; | |
+ #if TARGET_OS_TV | |
if (_reactSubview) { | |
if (_onRequestClose && _menuButtonGestureRecognizer) { | |
[_reactSubview addGestureRecognizer:_menuButtonGestureRecognizer]; | |
@@ -81,8 +105,8 @@ - (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose | |
[_reactSubview removeGestureRecognizer:_menuButtonGestureRecognizer]; | |
} | |
} | |
+ #endif | |
} | |
-#endif | |
- (void)notifyForBoundsChange:(CGRect)newBounds | |
{ | |
@@ -156,6 +180,13 @@ - (void)didUpdateReactSubviews | |
// Do nothing, as subview (singular) is managed by `insertReactSubview:atIndex:` | |
} | |
+- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController | |
+{ | |
+ if (_onRequestClose) { | |
+ _onRequestClose(nil); | |
+ } | |
+} | |
+ | |
- (void)dismissModalViewController | |
{ | |
if (_isPresented) { | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostViewManager.m b/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
index 44f9ac9..9c0d13c 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
@@ -108,9 +108,6 @@ - (void)invalidate | |
RCT_EXPORT_VIEW_PROPERTY(identifier, NSNumber) | |
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray) | |
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock) | |
- | |
-#if TARGET_OS_TV | |
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock) | |
-#endif | |
@end |
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 e16dd22..97f24a6 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; | |
@@ -31,9 +31,9 @@ | |
@property (nonatomic, copy) NSArray<NSString *> *supportedOrientations; | |
@property (nonatomic, copy) RCTDirectEventBlock onOrientationChange; | |
+@property (nonatomic, copy) RCTDirectEventBlock onRequestClose; | |
#if TARGET_OS_TV | |
-@property (nonatomic, copy) RCTDirectEventBlock onRequestClose; | |
@property (nonatomic, strong) RCTTVRemoteHandler *tvRemoteHandler; | |
#endif | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostView.m b/node_modules/react-native/React/Views/RCTModalHostView.m | |
index 95d572b..7e4f4c4 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostView.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostView.m | |
@@ -43,6 +43,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 +67,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 | |
{ | |
@@ -70,10 +92,12 @@ - (void)menuButtonPressed:(__unused UIGestureRecognizer *)gestureRecognizer | |
_onRequestClose(nil); | |
} | |
} | |
+#endif | |
- (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose | |
{ | |
_onRequestClose = onRequestClose; | |
+ #if TARGET_OS_TV | |
if (_reactSubview) { | |
if (_onRequestClose && _menuButtonGestureRecognizer) { | |
[_reactSubview addGestureRecognizer:_menuButtonGestureRecognizer]; | |
@@ -81,8 +105,8 @@ - (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose | |
[_reactSubview removeGestureRecognizer:_menuButtonGestureRecognizer]; | |
} | |
} | |
+ #endif | |
} | |
-#endif | |
- (void)notifyForBoundsChange:(CGRect)newBounds | |
{ | |
@@ -156,6 +180,13 @@ - (void)didUpdateReactSubviews | |
// Do nothing, as subview (singular) is managed by `insertReactSubview:atIndex:` | |
} | |
+- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController | |
+{ | |
+ if (_onRequestClose) { | |
+ _onRequestClose(nil); | |
+ } | |
+} | |
+ | |
- (void)dismissModalViewController | |
{ | |
if (_isPresented) { | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostViewManager.m b/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
index fa6f645..da7ca01 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
@@ -114,9 +114,6 @@ - (void)invalidate | |
RCT_EXPORT_VIEW_PROPERTY(identifier, NSNumber) | |
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray) | |
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock) | |
- | |
-#if TARGET_OS_TV | |
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock) | |
-#endif | |
@end |
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 4e61886..2b8b6c0 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; | |
@@ -31,9 +31,9 @@ | |
@property (nonatomic, copy) NSArray<NSString *> *supportedOrientations; | |
@property (nonatomic, copy) RCTDirectEventBlock onOrientationChange; | |
+@property (nonatomic, copy) RCTDirectEventBlock onRequestClose; | |
#if TARGET_OS_TV | |
-@property (nonatomic, copy) RCTDirectEventBlock onRequestClose; | |
@property (nonatomic, strong) RCTTVRemoteHandler *tvRemoteHandler; | |
#endif | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostView.m b/node_modules/react-native/React/Views/RCTModalHostView.m | |
index 6a15330..ec81912 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostView.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostView.m | |
@@ -41,6 +41,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; | |
@@ -69,10 +73,12 @@ - (void)menuButtonPressed:(__unused UIGestureRecognizer *)gestureRecognizer | |
_onRequestClose(nil); | |
} | |
} | |
+#endif | |
- (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose | |
{ | |
_onRequestClose = onRequestClose; | |
+ #if TARGET_OS_TV | |
if (_reactSubview) { | |
if (_onRequestClose && _menuButtonGestureRecognizer) { | |
[_reactSubview addGestureRecognizer:_menuButtonGestureRecognizer]; | |
@@ -80,8 +86,8 @@ - (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose | |
[_reactSubview removeGestureRecognizer:_menuButtonGestureRecognizer]; | |
} | |
} | |
+ #endif | |
} | |
-#endif | |
- (void)notifyForBoundsChange:(CGRect)newBounds | |
{ | |
@@ -257,4 +263,31 @@ - (UIInterfaceOrientationMask)supportedOrientationsMask | |
} | |
#endif | |
+// MARK: - UIAdaptivePresentationControllerDelegate - | |
+ | |
+// 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; | |
+} | |
+ | |
+- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController | |
+{ | |
+ if (_onRequestClose) { | |
+ _onRequestClose(nil); | |
+ } | |
+} | |
+ | |
@end | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostViewController.m b/node_modules/react-native/React/Views/RCTModalHostViewController.m | |
index 112bc17..d1158d8 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostViewController.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostViewController.m | |
@@ -24,12 +24,12 @@ - (instancetype)init | |
return nil; | |
} | |
-#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ | |
- __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 | |
- if (@available(iOS 13.0, *)) { | |
- self.modalInPresentation = YES; | |
- } | |
-#endif | |
+//#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && defined(__IPHONE_13_0) && \ | |
+// __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0 | |
+// if (@available(iOS 13.0, *)) { | |
+// self.modalInPresentation = YES; | |
+// } | |
+//#endif | |
#if !TARGET_OS_TV | |
_preferredStatusBarStyle = [RCTSharedApplication() statusBarStyle]; | |
diff --git a/node_modules/react-native/React/Views/RCTModalHostViewManager.m b/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
index bafab9d..d56bb52 100644 | |
--- a/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
+++ b/node_modules/react-native/React/Views/RCTModalHostViewManager.m | |
@@ -116,9 +116,6 @@ - (void)invalidate | |
RCT_EXPORT_VIEW_PROPERTY(identifier, NSNumber) | |
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray) | |
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock) | |
- | |
-#if TARGET_OS_TV | |
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock) | |
-#endif | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By using https://github.com/ds300/patch-package.