Skip to content

Commit eca556b

Browse files
committed
Use Objective-C nullability to provide better Swift types in RCTAppDelegate (facebook#42236)
Summary: This PR adds nullable type annotations + nullability audit regions (`NS_ASSUME_NONNULL_BEGIN`/`NS_ASSUME_NONNULL_END`) to provide better Swift types. Before: ```swift class AppDelegate: RCTAppDelegate { override func sourceURL(for bridge: RCTBridge!) -> URL! { self.bundleURL() } override func bundleURL() -> URL! { RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "js/RNTesterApp.ios") } override func customize(_ rootView: RCTRootView!) { rootView.backgroundColor = .red } } ``` After: ```swift class AppDelegate: RCTAppDelegate { override func sourceURL(for bridge: RCTBridge) -> URL { self.bundleURL() } override func bundleURL() -> URL { RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "js/RNTesterApp.ios") } override func customize(_ rootView: RCTRootView) { rootView.backgroundColor = .red } } ``` ## Changelog: [IOS] [ADDED] - Provide better Swift types for RCTAppDelegate and RCTBridgeDelegate Pull Request resolved: facebook#42236 Test Plan: In Xcode click the top left square button and look up the generated interface: ![CleanShot 2024-01-10 at 16 40 51@2x](https://github.com/facebook/react-native/assets/52801365/ad2ac9ed-9d9a-4c5e-a200-1d7a2802e701) Reviewed By: christophpurrer Differential Revision: D52660647 Pulled By: cipolleschi fbshipit-source-id: d4d3c36b3f420b3490145c491cd3781613f4b111
1 parent 80461f7 commit eca556b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
@protocol RCTComponentViewProtocol;
1313
@class RCTSurfacePresenterBridgeAdapter;
1414

15+
NS_ASSUME_NONNULL_BEGIN
16+
1517
/**
1618
* The RCTAppDelegate is an utility class that implements some base configurations for all the React Native apps.
1719
* It is not mandatory to use it, but it could simplify your AppDelegate code.
@@ -53,10 +55,10 @@
5355
@interface RCTAppDelegate : UIResponder <UIApplicationDelegate, UISceneDelegate, RCTBridgeDelegate>
5456

5557
/// The window object, used to render the UViewControllers
56-
@property (nonatomic, strong) UIWindow *window;
57-
@property (nonatomic, strong) RCTBridge *bridge;
58-
@property (nonatomic, strong) NSString *moduleName;
59-
@property (nonatomic, strong) NSDictionary *initialProps;
58+
@property (nonatomic, strong, nonnull) UIWindow *window;
59+
@property (nonatomic, strong, nullable) RCTBridge *bridge;
60+
@property (nonatomic, strong, nullable) NSString *moduleName;
61+
@property (nonatomic, strong, nullable) NSDictionary *initialProps;
6062

6163
/**
6264
* It creates a `RCTBridge` using a delegate and some launch options.
@@ -146,3 +148,5 @@
146148
launchOptions:(NSDictionary *)launchOptions;
147149

148150
@end
151+
152+
NS_ASSUME_NONNULL_END

packages/react-native/React/Base/RCTBridgeDelegate.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
@class RCTBridge;
1111
@protocol RCTBridgeModule;
1212

13+
NS_ASSUME_NONNULL_BEGIN
14+
1315
@protocol RCTBridgeDelegate <NSObject>
1416

1517
/**
@@ -77,3 +79,5 @@
7779
- (NSDictionary<NSString *, Class> *)extraLazyModuleClassesForBridge:(RCTBridge *)bridge;
7880

7981
@end
82+
83+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)