Skip to content

Commit 84c1c6e

Browse files
cortinicofacebook-github-bot
authored andcommitted
Follow-up with Review Feedback on RCTAppDelegate from #43526 (#43607)
Summary: Pull Request resolved: #43607 PR #43526 was accidentally merged with several changes excluded. I'm following up on those here. Changelog: [Internal] [Changed] - Follow-up with Review Feedback on RCTAppDelegate from #43526 Reviewed By: dmytrorykun Differential Revision: D55240435 fbshipit-source-id: c296a1e14b7032b211551334ca7b5a6824e8d45c
1 parent 0a12557 commit 84c1c6e

File tree

3 files changed

+68
-12
lines changed

3 files changed

+68
-12
lines changed

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,42 @@ - (RCTRootViewFactory *)createRCTRootViewFactory
265265
return [weakSelf sourceURLForBridge:bridge];
266266
};
267267

268-
configuration.extraModulesForBridge = ^NSArray<id<RCTBridgeModule>> *_Nonnull(RCTBridge *_Nonnull bridge)
269-
{
270-
return [weakSelf extraModulesForBridge:bridge];
271-
};
268+
if ([self respondsToSelector:@selector(extraModulesForBridge:)]) {
269+
configuration.extraModulesForBridge = ^NSArray<id<RCTBridgeModule>> *_Nonnull(RCTBridge *_Nonnull bridge)
270+
{
271+
return [weakSelf extraModulesForBridge:bridge];
272+
};
273+
}
272274

273-
configuration.extraLazyModuleClassesForBridge = ^NSDictionary<NSString *, Class> *_Nonnull(RCTBridge *_Nonnull bridge)
274-
{
275-
return [weakSelf extraLazyModuleClassesForBridge:bridge];
276-
};
275+
if ([self respondsToSelector:@selector(extraLazyModuleClassesForBridge:)]) {
276+
configuration.extraLazyModuleClassesForBridge =
277+
^NSDictionary<NSString *, Class> *_Nonnull(RCTBridge *_Nonnull bridge)
278+
{
279+
return [weakSelf extraLazyModuleClassesForBridge:bridge];
280+
};
281+
}
277282

278-
configuration.bridgeDidNotFindModule = ^BOOL(RCTBridge *_Nonnull bridge, NSString *_Nonnull moduleName) {
279-
return [weakSelf bridge:bridge didNotFindModule:moduleName];
280-
};
283+
if ([self respondsToSelector:@selector(bridge:didNotFindModule:)]) {
284+
configuration.bridgeDidNotFindModule = ^BOOL(RCTBridge *_Nonnull bridge, NSString *_Nonnull moduleName) {
285+
return [weakSelf bridge:bridge didNotFindModule:moduleName];
286+
};
287+
}
288+
289+
if ([self respondsToSelector:@selector(loadSourceForBridge:withBlock:)]) {
290+
configuration.loadSourceForBridgeBlock =
291+
^void(RCTBridge *_Nonnull bridge, RCTSourceLoadBlock _Nonnull loadCallback) {
292+
[weakSelf loadSourceForBridge:bridge withBlock:loadCallback];
293+
};
294+
}
295+
296+
if ([self respondsToSelector:@selector(loadSourceForBridge:onProgress:onComplete:)]) {
297+
configuration.loadSourceForBridgeProgressBlock =
298+
^(RCTBridge *_Nonnull bridge,
299+
RCTSourceLoadProgressBlock _Nonnull onProgress,
300+
RCTSourceLoadBlock _Nonnull loadCallback) {
301+
[weakSelf loadSourceForBridge:bridge onProgress:onProgress onComplete:loadCallback];
302+
};
303+
}
281304

282305
return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
283306
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ typedef NSURL *_Nullable (^RCTSourceURLForBridgeBlock)(RCTBridge *bridge);
2727
typedef NSArray<id<RCTBridgeModule>> *_Nonnull (^RCTExtraModulesForBridgeBlock)(RCTBridge *bridge);
2828
typedef NSDictionary<NSString *, Class> *_Nonnull (^RCTExtraLazyModuleClassesForBridge)(RCTBridge *bridge);
2929
typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *moduleName);
30+
typedef void (^RCTLoadSourceForBridgeBlock)(RCTBridge *bridge, RCTSourceLoadBlock loadCallback);
31+
typedef void (^RCTLoadSourceForBridgeProgressBlock)(
32+
RCTBridge *bridge,
33+
RCTSourceLoadProgressBlock onProgress,
34+
RCTSourceLoadBlock loadCallback);
3035

3136
#pragma mark - RCTRootViewFactory Configuration
3237
@interface RCTRootViewFactoryConfiguration : NSObject
@@ -84,7 +89,6 @@ typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *modu
8489
* @returns: a newly created instance of RCTBridge.
8590
*/
8691
@property (nonatomic, nullable) RCTCreateBridgeWithDelegateBlock createBridgeWithDelegate;
87-
8892
/**
8993
* Block that returns the location of the JavaScript source file. When running from the packager
9094
* this should be an absolute URL, e.g. `http://localhost:8081/index.ios.bundle`.
@@ -123,6 +127,19 @@ typedef BOOL (^RCTBridgeDidNotFindModuleBlock)(RCTBridge *bridge, NSString *modu
123127
*/
124128
@property (nonatomic, nullable) RCTBridgeDidNotFindModuleBlock bridgeDidNotFindModule;
125129

130+
/**
131+
* The bridge will automatically attempt to load the JS source code from the
132+
* location specified by the `sourceURLForBridge:` method, however, if you want
133+
* to handle loading the JS yourself, you can do so by implementing this method.
134+
*/
135+
@property (nonatomic, nullable) RCTLoadSourceForBridgeProgressBlock loadSourceForBridgeProgressBlock;
136+
137+
/**
138+
* Similar to loadSourceForBridge:onProgress:onComplete: but without progress
139+
* reporting.
140+
*/
141+
@property (nonatomic, nullable) RCTLoadSourceForBridgeBlock loadSourceForBridgeBlock;
142+
126143
@end
127144

128145
#pragma mark - RCTRootViewFactory

packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ - (BOOL)bridge:(RCTBridge *)bridge didNotFindModule:(NSString *)moduleName
273273
return NO;
274274
}
275275

276+
- (void)loadSourceForBridge:(RCTBridge *)bridge withBlock:(RCTSourceLoadBlock)loadCallback
277+
{
278+
if (_configuration.loadSourceForBridgeBlock != nil) {
279+
_configuration.loadSourceForBridgeBlock(bridge, loadCallback);
280+
}
281+
}
282+
283+
- (void)loadSourceForBridge:(RCTBridge *)bridge
284+
onProgress:(RCTSourceLoadProgressBlock)onProgress
285+
onComplete:(RCTSourceLoadBlock)loadCallback
286+
{
287+
if (_configuration.loadSourceForBridgeProgressBlock != nil) {
288+
_configuration.loadSourceForBridgeProgressBlock(bridge, onProgress, loadCallback);
289+
}
290+
}
291+
276292
- (NSURL *)bundleURL
277293
{
278294
return self->_configuration.bundleURL;

0 commit comments

Comments
 (0)