我的旧版RN项目异步加载了多个js包。 js包之间有本机导航。选择标签后,它将加载由AppRegistry.registerComponent('user', () => App);
注册的应用。
它基于在0.55.1中已删除的callFunctionOnModule https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#055
https://github.com/facebook/react-native/commit/19a4a7d
如何用0.59.8 RN替换callFunctionOnModule
- (void)initializeWithJsCodeLocation:(NSURL *)jsCodeLocation
bundleName:(NSString *)bundleName
applicationId:(NSString *)applicationId
initialProperties:(NSDictionary *)initialProperties {
if (self.rootView) {
[self.rootView removeFromSuperview];
}
self.jsCodeLocation = jsCodeLocation;
@weakify(self)
RCTBridge *bridge = [self.bridgeBuilder bridgeWithDelegate:self
bundleName:bundleName
applicationId:applicationId];
[bridge.batchedBridge dispatchBlock:^{
@strongify(self)
self.registeredAppArray = [self ufsl_registeredArrayForBridge:bridge];
@weakify(self)
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self)
if ([self.registeredAppArray containsObject:bundleName]) {
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:bundleName
initialProperties:initialProperties];
if (self.bundleBackgroundColor) {
rootView.backgroundColor = self.bundleBackgroundColor;
}
[self addSubview:rootView];
[rootView autoPinEdgesToSuperviewEdges];
self.rootView = rootView;
[self.presenter applicationDidLoad];
} else {
[self.presenter applicationDidNotLoadWithWrongName:bundleName];
}
});
}
queue:RCTJSThread];
}
- (void)removeBackgroundColor {
self.bundleBackgroundColor = UIColor.clearColor;
}
#pragma mark - Private
- (NSArray<NSString *> *)ufsl_registeredArrayForBridge:(RCTBridge *)bridge {
JSValue *value = [bridge callFunctionOnModule:kUFSAppRegistryModuleName
method:kUFSGetAppKeysMethodName
arguments:nil
error:nil];
if (!value.isUndefined && value.isArray) {
return [value toArray];
} else {
return @[];
}
}```
callFunctionOnModule is not defined.