Share bundled source URL to RN

Differential Revision: D6192988

fbshipit-source-id: efa584ee2340a34156956990d6cd96d37ba4ab60
This commit is contained in:
Yujie Liu 2017-11-07 16:44:51 -08:00 committed by Facebook Github Bot
parent 9ec9567390
commit b983de9c54
4 changed files with 19 additions and 4 deletions

View File

@ -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.

View File

@ -329,6 +329,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
// 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];

View File

@ -175,10 +175,11 @@ struct RCTInstanceCallback : public InstanceCallback {
std::shared_ptr<Instance> _reactInstance;
}
@synthesize loading = _loading;
@synthesize valid = _valid;
@synthesize performanceLogger = _performanceLogger;
@synthesize bridgeDescription = _bridgeDescription;
@synthesize loading = _loading;
@synthesize bundledSourceURL = _bundledSourceURL;
@synthesize performanceLogger = _performanceLogger;
@synthesize valid = _valid;
+ (void)initialize
{
@ -207,6 +208,9 @@ struct RCTInstanceCallback : public InstanceCallback {
launchOptions:bridge.launchOptions])) {
_parentBridge = bridge;
_performanceLogger = [bridge performanceLogger];
if ([bridge.delegate respondsToSelector:@selector(bundledSourceURLForBridge:)]) {
_bundledSourceURL = [bridge.delegate bundledSourceURLForBridge:bridge];
}
registerPerformanceLoggerHooks(_performanceLogger);

View File

@ -25,7 +25,8 @@ RCT_EXPORT_MODULE()
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{
@"scriptURL": self.bridge.bundleURL.absoluteString ?: @""
@"scriptURL": self.bridge.bundleURL.absoluteString ?: @"",
@"bundledScriptURL": self.bridge.bundledSourceURL.absoluteString ?: @""
};
}