forked from react/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRCTDevSplitBundleLoader.mm
More file actions
109 lines (89 loc) · 2.78 KB
/
Copy pathRCTDevSplitBundleLoader.mm
File metadata and controls
109 lines (89 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* 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 <React/RCTDevSplitBundleLoader.h>
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTConvert.h>
#import <React/RCTDefines.h>
#import <React/RCTDevSettings.h>
#import <React/RCTUtils.h>
#import "CoreModulesPlugins.h"
using namespace facebook::react;
@interface RCTDevSplitBundleLoader () <NativeDevSplitBundleLoaderSpec>
@end
#if RCT_DEV_MENU
@implementation RCTDevSplitBundleLoader
@synthesize bridge = _bridge;
@synthesize loadScript = _loadScript;
@synthesize turboModuleRegistry = _turboModuleRegistry;
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
}
RCT_EXPORT_METHOD(loadBundle
: (NSString *)bundlePath resolve
: (RCTPromiseResolveBlock)resolve reject
: (RCTPromiseRejectBlock)reject)
{
NSURL *sourceURL = [[RCTBundleURLProvider sharedSettings] jsBundleURLForSplitBundleRoot:bundlePath];
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
{
return std::make_shared<NativeDevSplitBundleLoaderSpecJSI>(params);
}
@end
#else
@implementation RCTDevSplitBundleLoader
+ (NSString *)moduleName
{
return nil;
}
- (void)loadBundle:(NSString *)bundlePath resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
{
}
- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
{
return std::make_shared<NativeDevSplitBundleLoaderSpecJSI>(params);
}
@end
#endif
Class RCTDevSplitBundleLoaderCls(void)
{
return RCTDevSplitBundleLoader.class;
}