-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: NativeModules can read from, or write to, the bridge's bundleURL. To do so, they access the bundleURL property on the bridge directly. **Setter:** https://www.internalfb.com/code/fbsource/[2a74581dfff31febe6e91c5739294705f5244ecb]/xplat/js/react-native-github/React/CoreModules/RCTDevMenu.mm?lines=213-214 **Getter:** https://www.internalfb.com/code/fbsource/[2a74581dfff31febe6e91c5739294705f5244ecb]/xplat/js/react-native-github/React/CoreModules/RCTDevMenu.mm?lines=245%2C256 In bridgeless mode, the bridge is nil. So, this form of access will fail. After this stack lands, every NativeModule will be able to synthesize an RCTBundleManager, like so: ``` synthesize bundleManager = _bundleManager; ``` From then on, all NativeModules will use this bundleManager to access the bundle URL. This should ensure that NativeModules can read from/write to the bundleURL, **even in bridgeless mode**. Changelog: [iOS][Added] - Introduce RCTBundleManager for bundleURL access Reviewed By: PeteTheHeat Differential Revision: D28086318 fbshipit-source-id: 34c15bf05c144341aa912fad9aa25d6d3a364f9e
- Loading branch information
1 parent
7db89f9
commit 4a1bafe
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import "RCTAssert.h" | ||
#import "RCTBridge+Private.h" | ||
#import "RCTBridge.h" | ||
#import "RCTBridgeModule.h" | ||
|
||
@implementation RCTBundleManager { | ||
__weak RCTBridge *_bridge; | ||
RCTBridgelessBundleURLGetter _bridgelessBundleURLGetter; | ||
RCTBridgelessBundleURLSetter _bridgelessBundleURLSetter; | ||
} | ||
|
||
- (void)setBridge:(RCTBridge *)bridge | ||
{ | ||
_bridge = bridge; | ||
} | ||
|
||
- (void)setBridgelessBundleURLGetter:(RCTBridgelessBundleURLGetter)getter andSetter:(RCTBridgelessBundleURLSetter)setter | ||
{ | ||
_bridgelessBundleURLGetter = getter; | ||
_bridgelessBundleURLSetter = setter; | ||
} | ||
|
||
- (void)setBundleURL:(NSURL *)bundleURL | ||
{ | ||
if (_bridge) { | ||
_bridge.bundleURL = bundleURL; | ||
return; | ||
} | ||
|
||
RCTAssert( | ||
_bridgelessBundleURLSetter != nil, | ||
@"RCTBundleManager: In bridgeless mode, RCTBridgelessBundleURLSetter must not be nil."); | ||
_bridgelessBundleURLSetter(bundleURL); | ||
} | ||
|
||
- (NSURL *)bundleURL | ||
{ | ||
if (_bridge) { | ||
return _bridge.bundleURL; | ||
} | ||
|
||
RCTAssert( | ||
_bridgelessBundleURLGetter != nil, | ||
@"RCTBundleManager: In bridgeless mode, RCTBridgelessBundleURLGetter must not be nil."); | ||
|
||
return _bridgelessBundleURLGetter(); | ||
} | ||
|
||
@end |