-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathreanimated.js
96 lines (89 loc) · 2.9 KB
/
reanimated.js
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
// @ts-check
const { createRunOncePlugin } = require("@expo/config-plugins");
const {
mergeContents,
} = require("@expo/config-plugins/build/utils/generateCode");
const { withBridgeDelegate } = require("./index");
/**
* @typedef {import("@expo/config-plugins").ExportedConfig} ExportedConfig
*/
const NAME = "react-native-reanimated";
/**
* Adds specified contents to an existing file with a generated header.
* @param {string} tag Tag used to generate a unique header
* @param {string} src Contents of the source file
* @param {string} newSrc Contents to be added
* @param {RegExp} anchor `RegExp` providing the position at which contents is added
* @returns {string} The merged content
*/
function addContents(tag, src, newSrc, anchor) {
return mergeContents({
tag: `${NAME}-${tag}`,
src,
newSrc,
anchor,
offset: 1,
comment: "//",
}).contents;
}
/**
* Plugin to inject Reanimated's JSI executor in the React bridge delegate.
*
* Only applies to iOS.
*
* @param {ExportedConfig} config Exported config
* @returns {ExportedConfig} Modified config
*/
function withReanimatedExecutor(config) {
return withBridgeDelegate(config, (config) => {
if (config.modResults.language !== "objcpp") {
throw new Error(
"`BridgeDelegate` is not in Objective-C++ (did that change recently?)"
);
}
// Add Reanimated headers
config.modResults.contents = addContents(
"header",
config.modResults.contents,
[
"#if !USE_TURBOMODULE",
"#pragma clang diagnostic push",
'#pragma clang diagnostic ignored "-Wnullability-completeness"',
"",
"#import <RNReanimated/REAInitializer.h>",
"",
"#if __has_include(<reacthermes/HermesExecutorFactory.h>)",
"#import <reacthermes/HermesExecutorFactory.h>",
"using ExecutorFactory = HermesExecutorFactory;",
"#elif __has_include(<React/HermesExecutorFactory.h>)",
"#import <React/HermesExecutorFactory.h>",
"using ExecutorFactory = HermesExecutorFactory;",
"#else",
"#import <React/JSCExecutorFactory.h>",
"using ExecutorFactory = JSCExecutorFactory;",
"#endif",
"",
"#pragma clang diagnostic pop",
"#endif // !USE_TURBOMODULE",
].join("\n"),
/#import "BridgeDelegate\.h"/
);
// Install Reanimated's JSI executor runtime
const indent = " ";
config.modResults.contents = addContents(
"executor",
config.modResults.contents,
[
`${indent}const auto installer = reanimated::REAJSIExecutorRuntimeInstaller(bridge, nullptr);`,
`${indent}return std::make_unique<ExecutorFactory>(RCTJSIExecutorRuntimeInstaller(installer));`,
].join("\n"),
/\/\/ jsExecutorFactoryForBridge: \(USE_TURBOMODULE=0\)/
);
return config;
});
}
module.exports = createRunOncePlugin(
withReanimatedExecutor,
NAME,
"UNVERSIONED"
);