Skip to content

Commit

Permalink
Share bundled source URL to RN
Browse files Browse the repository at this point in the history
Differential Revision: D6192988

fbshipit-source-id: efa584ee2340a34156956990d6cd96d37ba4ab60
  • Loading branch information
Yujie Liu authored and facebook-github-bot committed Nov 8, 2017
1 parent 9ec9567 commit b983de9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
*/
@property (nonatomic, strong, readonly) NSURL *bundleURL;

/**
* URL of the original script (not necessarily loaded) of the bridge.
*/
@property (nonatomic, strong, readonly) NSURL *bundledSourceURL;

/**
* The class of the executor currently being used. Changes to this value will
* take effect after the bridge is reloaded.
Expand Down
5 changes: 5 additions & 0 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ - (void)setUp
// Sanitize the bundle URL
_bundleURL = [RCTConvert NSURL:_bundleURL.absoluteString];

if ([self.delegate respondsToSelector:@selector(bundledSourceURLForBridge:)]) {
_bundledSourceURL = [self.delegate bundledSourceURLForBridge:self];
_bundledSourceURL = [RCTConvert NSURL:_bundledSourceURL.absoluteString];
}

self.batchedBridge = [[bridgeClass alloc] initWithParentBridge:self];
[self.batchedBridge start];

Expand Down
8 changes: 6 additions & 2 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ @implementation RCTCxxBridge
std::shared_ptr<Instance> _reactInstance;
}

@synthesize bridgeDescription = _bridgeDescription;
@synthesize loading = _loading;
@synthesize valid = _valid;
@synthesize bundledSourceURL = _bundledSourceURL;
@synthesize performanceLogger = _performanceLogger;
@synthesize bridgeDescription = _bridgeDescription;
@synthesize valid = _valid;

+ (void)initialize
{
Expand Down Expand Up @@ -207,6 +208,9 @@ - (instancetype)initWithParentBridge:(RCTBridge *)bridge
launchOptions:bridge.launchOptions])) {
_parentBridge = bridge;
_performanceLogger = [bridge performanceLogger];
if ([bridge.delegate respondsToSelector:@selector(bundledSourceURLForBridge:)]) {
_bundledSourceURL = [bridge.delegate bundledSourceURLForBridge:bridge];
}

registerPerformanceLoggerHooks(_performanceLogger);

Expand Down
3 changes: 2 additions & 1 deletion React/Modules/RCTSourceCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ + (BOOL)requiresMainQueueSetup
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{
@"scriptURL": self.bridge.bundleURL.absoluteString ?: @""
@"scriptURL": self.bridge.bundleURL.absoluteString ?: @"",
@"bundledScriptURL": self.bridge.bundledSourceURL.absoluteString ?: @""
};
}

Expand Down

0 comments on commit b983de9

Please sign in to comment.