Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions React/Base/RCTJSScriptLoaderModule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/

@class RCTSource;

/**
* This protocol should be adopted when a turbo module needs to tell React Native to load a script.
* In bridge-less React Native, it is a replacement for [_bridge loadAndExecuteSplitBundleURL:].
*/
@protocol RCTJSScriptLoaderModule <NSObject>

@property (nonatomic, copy, nonnull) void (^loadScript)(RCTSource *source);

@end
3 changes: 2 additions & 1 deletion React/CoreModules/RCTDevSplitBundleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

#import <React/RCTBridgeModule.h>
#import <React/RCTJSScriptLoaderModule.h>
#import <UIKit/UIKit.h>

@interface RCTDevSplitBundleLoader : NSObject <RCTBridgeModule>
@interface RCTDevSplitBundleLoader : NSObject <RCTBridgeModule, RCTJSScriptLoaderModule>
@end
39 changes: 30 additions & 9 deletions React/CoreModules/RCTDevSplitBundleLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <React/RCTBundleURLProvider.h>
#import <React/RCTConvert.h>
#import <React/RCTDefines.h>
#import <React/RCTDevSettings.h>
#import <React/RCTUtils.h>

#import "CoreModulesPlugins.h"
Expand All @@ -23,10 +24,11 @@ @interface RCTDevSplitBundleLoader () <NativeDevSplitBundleLoaderSpec>

#if RCT_DEV_MENU

@implementation RCTDevSplitBundleLoader {
}
@implementation RCTDevSplitBundleLoader

@synthesize bridge = _bridge;
@synthesize loadScript = _loadScript;
@synthesize turboModuleRegistry = _turboModuleRegistry;

RCT_EXPORT_MODULE()

Expand All @@ -46,13 +48,32 @@ - (void)setBridge:(RCTBridge *)bridge
: (RCTPromiseRejectBlock)reject)
{
NSURL *sourceURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForSplitBundleRoot:bundlePath];
[_bridge loadAndExecuteSplitBundleURL:sourceURL
onError:^(NSError *error) {
reject(@"E_BUNDLE_LOAD_ERROR", [error localizedDescription], error);
}
onComplete:^() {
resolve(@YES);
}];
if (_bridge) {
[_bridge loadAndExecuteSplitBundleURL:sourceURL
onError:^(NSError *error) {
reject(@"E_BUNDLE_LOAD_ERROR", [error localizedDescription], error);
}
onComplete:^() {
resolve(@YES);
}];
} else {
__weak __typeof(self) weakSelf = self;
[RCTJavaScriptLoader loadBundleAtURL:sourceURL
onProgress:^(RCTLoadingProgress *progressData) {
// TODO: Setup loading bar.
}
onComplete:^(NSError *error, RCTSource *source) {
if (error) {
reject(@"E_BUNDLE_LOAD_ERROR", [error localizedDescription], error);
return;
}
__typeof(self) strongSelf = weakSelf;
strongSelf->_loadScript(source);
RCTDevSettings *devSettings = [strongSelf->_turboModuleRegistry moduleForName:"RCTDevSettings"];
[devSettings setupHMRClientWithAdditionalBundleURL:source.url];
resolve(@YES);
}];
}
}

- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
Expand Down