-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
REAInitializer.mm
73 lines (61 loc) · 2.65 KB
/
REAInitializer.mm
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
#import <RNReanimated/REAInitializer.h>
#import <RNReanimated/REAUIManager.h>
@interface RCTEventDispatcher (Reanimated)
- (void)setBridge:(RCTBridge *)bridge;
@end
namespace reanimated {
using namespace facebook;
using namespace react;
JSIExecutor::RuntimeInstaller REAJSIExecutorRuntimeInstaller(
RCTBridge *bridge,
JSIExecutor::RuntimeInstaller runtimeInstallerToWrap)
{
[bridge moduleForClass:[RCTUIManager class]];
REAUIManager *reaUiManager = [REAUIManager new];
[reaUiManager setBridge:bridge];
RCTUIManager *uiManager = reaUiManager;
[bridge updateModuleWithInstance:uiManager];
[bridge moduleForClass:[RCTEventDispatcher class]];
RCTEventDispatcher *eventDispatcher = [REAEventDispatcher new];
#if REACT_NATIVE_MINOR_VERSION >= 66
RCTCallableJSModules *callableJSModules = [RCTCallableJSModules new];
[bridge setValue:callableJSModules forKey:@"_callableJSModules"];
[callableJSModules setBridge:bridge];
[eventDispatcher setValue:callableJSModules forKey:@"_callableJSModules"];
[eventDispatcher setValue:bridge forKey:@"_bridge"];
[eventDispatcher initialize];
#else
[eventDispatcher setBridge:bridge];
#endif
[bridge updateModuleWithInstance:eventDispatcher];
const auto runtimeInstaller = [bridge, runtimeInstallerToWrap](facebook::jsi::Runtime &runtime) {
if (!bridge) {
return;
}
#if REACT_NATIVE_MINOR_VERSION >= 63
auto reanimatedModule = reanimated::createReanimatedModule(bridge, bridge.jsCallInvoker);
#else
auto callInvoker = std::make_shared<react::BridgeJSCallInvoker>(bridge.reactInstance);
auto reanimatedModule = reanimated::createReanimatedModule(bridge, callInvoker);
#endif
auto workletRuntimeValue = runtime.global()
.getProperty(runtime, "ArrayBuffer")
.asObject(runtime)
.asFunction(runtime)
.callAsConstructor(runtime, {static_cast<double>(sizeof(void *))});
uintptr_t *workletRuntimeData =
reinterpret_cast<uintptr_t *>(workletRuntimeValue.getObject(runtime).getArrayBuffer(runtime).data(runtime));
workletRuntimeData[0] = reinterpret_cast<uintptr_t>(reanimatedModule->runtime.get());
runtime.global().setProperty(runtime, "_WORKLET_RUNTIME", workletRuntimeValue);
runtime.global().setProperty(runtime, "_IS_FABRIC", false);
runtime.global().setProperty(
runtime,
jsi::PropNameID::forAscii(runtime, "__reanimatedModuleProxy"),
jsi::Object::createFromHostObject(runtime, reanimatedModule));
if (runtimeInstallerToWrap) {
runtimeInstallerToWrap(runtime);
}
};
return runtimeInstaller;
}
}