feat: add nullable annotations to RCTBundleURLProvider (#42293)

Summary:
This PR adds nullable annotations to `RCTBundleURLProvider` also allowing to return optional (the default that will be returned when metro is not running). Not having this may lead to crashes because Swift will try to unwrap optional with nil when metro is not running.

## Changelog:
[iOS] [Added] - add nullable annotations to RCTBundleURLProvider

Pull Request resolved: https://github.com/facebook/react-native/pull/42293

Test Plan: CI Green

Reviewed By: sammy-SC

Differential Revision: D52797676

Pulled By: cipolleschi

fbshipit-source-id: 98b4f99aa71828f5397276d22f35d24e48657dc8
This commit is contained in:
Oskar Kwaśniewski
2024-02-08 07:56:05 -08:00
committed by Facebook GitHub Bot
parent 50bd9e367b
commit 12e4a5745d
3 changed files with 35 additions and 30 deletions
@@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)bridgelessEnabled;
/// Return the bundle URL for the main bundle.
- (NSURL *)bundleURL;
- (NSURL *__nullable)bundleURL;
@end
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
* When running from a locally bundled JS file, this should be a `file://` url
* pointing to a path inside the app resources, e.g. `file://.../main.jsbundle`.
*/
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge;
- (NSURL *__nullable)sourceURLForBridge:(RCTBridge *)bridge;
@optional
@@ -9,7 +9,7 @@
#import "RCTDefines.h"
RCT_EXTERN NSString *const RCTBundleURLProviderUpdatedNotification;
RCT_EXTERN NSString *_Nonnull const RCTBundleURLProviderUpdatedNotification;
RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort;
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
@@ -22,6 +22,8 @@ RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort;
RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
#endif
NS_ASSUME_NONNULL_BEGIN
@interface RCTBundleURLProvider : NSObject
/**
@@ -52,52 +54,53 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
* The port is optional, if not specified, kRCTBundleURLProviderDefaultPort will be used
* The scheme is also optional, if not specified, a default http protocol will be used
*/
+ (BOOL)isPackagerRunning:(NSString *)hostPort scheme:(NSString *)scheme;
+ (BOOL)isPackagerRunning:(NSString *)hostPort scheme:(NSString *__nullable)scheme;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(NSURL * (^)(void))fallbackURLProvider;
- (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot
fallbackURLProvider:(NSURL *__nullable (^)(void))fallbackURLProvider;
/**
* Returns the jsBundleURL for a given split bundle entrypoint in development
*/
- (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot;
- (NSURL *__nullable)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
* if extension is nil, "jsbundle" will be used.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *)extension;
- (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *__nullable)extension;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle if the packager is not running.
*/
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot;
- (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot;
/**
* Returns the jsBundleURL for a given bundle entrypoint and
* the fallback offline JS bundle. If extension is nil,
* "jsbundle" will be used.
*/
- (NSURL *)jsBundleURLForFallbackExtension:(NSString *)extension;
- (NSURL *__nullable)jsBundleURLForFallbackExtension:(NSString *__nullable)extension;
/**
* Returns the resourceURL for a given bundle entrypoint and
* the fallback offline resource file if the packager is not running.
*/
- (NSURL *)resourceURLForResourceRoot:(NSString *)root
resourceName:(NSString *)name
resourceExtension:(NSString *)extension
offlineBundle:(NSBundle *)offlineBundle;
- (NSURL *__nullable)resourceURLForResourceRoot:(NSString *)root
resourceName:(NSString *)name
resourceExtension:(NSString *)extension
offlineBundle:(NSBundle *)offlineBundle;
/**
* The IP address or hostname of the packager.
*/
@property (nonatomic, copy) NSString *jsLocation;
@property (nonatomic, copy, nullable) NSString *jsLocation;
@property (nonatomic, assign) BOOL enableMinification;
@property (nonatomic, assign) BOOL enableDev;
@@ -124,20 +127,20 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
* - runModule: When true, will run the main module after defining all modules. This is used in the main bundle but not
* in split bundles.
*/
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
inlineSourceMap:(BOOL)inlineSourceMap;
+ (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
inlineSourceMap:(BOOL)inlineSourceMap;
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
packagerScheme:(NSString *)scheme
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
inlineSourceMap:(BOOL)inlineSourceMap
modulesOnly:(BOOL)modulesOnly
runModule:(BOOL)runModule;
+ (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot
packagerHost:(NSString *)packagerHost
packagerScheme:(NSString *__nullable)scheme
enableDev:(BOOL)enableDev
enableMinification:(BOOL)enableMinification
inlineSourceMap:(BOOL)inlineSourceMap
modulesOnly:(BOOL)modulesOnly
runModule:(BOOL)runModule;
/**
* Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
* In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged
@@ -145,8 +148,8 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
*/
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
packagerHost:(NSString *)packagerHost
scheme:(NSString *)scheme
query:(NSString *)query
scheme:(NSString *__nullable)scheme
query:(NSString *__nullable)query
__deprecated_msg("Use version with queryItems parameter instead");
/**
@@ -157,6 +160,8 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
packagerHost:(NSString *)packagerHost
scheme:(NSString *)scheme
queryItems:(NSArray<NSURLQueryItem *> *)queryItems;
queryItems:(NSArray<NSURLQueryItem *> *__nullable)queryItems;
@end
NS_ASSUME_NONNULL_END