From 2d547a3252b328251e49dabfeec85f8d46c85411 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Thu, 7 Mar 2024 18:05:34 -0800 Subject: [PATCH] feat: RCTConvert to support UIModalPresentationStyle (#43297) Summary: Currently, the ability to convert JS values to `UIModalPresentationStyle` is not present directly on `RCTConvert`. In the RN code base itself, there's not a lot of need to do this type of conversion, but in community modules, presenting ViewControllers can be a fairly common scenario and it'd be nice to be able to use this conversion directly from `RCTConvert`, rather than from `RCTModalHostViewManager`, as it'd improve its "discoverability" and consistency. If someone relied on this, then it's technically speaking a breaking change but I'd say it's for the better, and searching `#import ` on github doesn't reveal a lot of results. ## Changelog: [IOS] [ADDED] - RCTConvert to support UIModalPresentationStyle For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: https://github.com/facebook/react-native/pull/43297 Test Plan: Tested using RN Tester https://github.com/facebook/react-native/assets/1566403/6e62df86-dde3-47b0-b2e9-bb6b483cadf6 Reviewed By: fkgozali Differential Revision: D54635896 Pulled By: dmytrorykun fbshipit-source-id: c6747857830762cd0333c31c287954f3f10d4954 --- packages/react-native/React/Base/RCTConvert.h | 1 + packages/react-native/React/Base/RCTConvert.mm | 11 +++++++++++ .../React/Views/RCTModalHostViewManager.h | 6 ------ .../React/Views/RCTModalHostViewManager.m | 15 --------------- 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/react-native/React/Base/RCTConvert.h b/packages/react-native/React/Base/RCTConvert.h index 8b819fda89e..8e8a847f6fc 100644 --- a/packages/react-native/React/Base/RCTConvert.h +++ b/packages/react-native/React/Base/RCTConvert.h @@ -80,6 +80,7 @@ typedef NSURL RCTFileURL; + (UIReturnKeyType)UIReturnKeyType:(id)json; + (UIUserInterfaceStyle)UIUserInterfaceStyle:(id)json API_AVAILABLE(ios(12)); + (UIInterfaceOrientationMask)UIInterfaceOrientationMask:(NSString *)orientation; ++ (UIModalPresentationStyle)UIModalPresentationStyle:(id)json; #if !TARGET_OS_TV + (UIDataDetectorTypes)UIDataDetectorTypes:(id)json; diff --git a/packages/react-native/React/Base/RCTConvert.mm b/packages/react-native/React/Base/RCTConvert.mm index fb5e43c6d2e..c4b15a1df20 100644 --- a/packages/react-native/React/Base/RCTConvert.mm +++ b/packages/react-native/React/Base/RCTConvert.mm @@ -510,6 +510,17 @@ RCT_ENUM_CONVERTER( NSNotFound, unsignedIntegerValue) +RCT_ENUM_CONVERTER( + UIModalPresentationStyle, + (@{ + @"fullScreen" : @(UIModalPresentationFullScreen), + @"pageSheet" : @(UIModalPresentationPageSheet), + @"formSheet" : @(UIModalPresentationFormSheet), + @"overFullScreen" : @(UIModalPresentationOverFullScreen), + }), + UIModalPresentationFullScreen, + integerValue) + RCT_ENUM_CONVERTER( UIViewContentMode, (@{ diff --git a/packages/react-native/React/Views/RCTModalHostViewManager.h b/packages/react-native/React/Views/RCTModalHostViewManager.h index 11b52984b30..d2694ea26fd 100644 --- a/packages/react-native/React/Views/RCTModalHostViewManager.h +++ b/packages/react-native/React/Views/RCTModalHostViewManager.h @@ -9,12 +9,6 @@ #import #import -@interface RCTConvert (RCTModalHostView) - -+ (UIModalPresentationStyle)UIModalPresentationStyle:(id)json; - -@end - typedef void (^RCTModalViewInteractionBlock)( UIViewController *reactViewController, UIViewController *viewController, diff --git a/packages/react-native/React/Views/RCTModalHostViewManager.m b/packages/react-native/React/Views/RCTModalHostViewManager.m index b0295e05ae4..eccf05f9cb6 100644 --- a/packages/react-native/React/Views/RCTModalHostViewManager.m +++ b/packages/react-native/React/Views/RCTModalHostViewManager.m @@ -14,21 +14,6 @@ #import "RCTShadowView.h" #import "RCTUtils.h" -@implementation RCTConvert (RCTModalHostView) - -RCT_ENUM_CONVERTER( - UIModalPresentationStyle, - (@{ - @"fullScreen" : @(UIModalPresentationFullScreen), - @"pageSheet" : @(UIModalPresentationPageSheet), - @"formSheet" : @(UIModalPresentationFormSheet), - @"overFullScreen" : @(UIModalPresentationOverFullScreen), - }), - UIModalPresentationFullScreen, - integerValue) - -@end - @interface RCTModalHostShadowView : RCTShadowView @end