-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ios): add support for
react-native-reanimated
- Loading branch information
Showing
10 changed files
with
140 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
ios/ReactTestApp/React+TurboModule.h → ios/ReactTestApp/BridgeDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
#if USE_TURBOMODULE | ||
|
||
#import <React/RCTBridgeDelegate.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RTATurboModuleManagerDelegate : NSObject <RCTBridgeDelegate> | ||
@interface RTABridgeDelegate : NSObject <RCTBridgeDelegate> | ||
- (instancetype)initWithBridgeDelegate:(id<RCTBridgeDelegate>)bridgeDelegate; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // USE_TURBOMODULE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const { withMod } = require("@expo/config-plugins"); | ||
|
||
function withBridgeDelegate(config, action) { | ||
return withMod(config, { | ||
platform: "ios", | ||
mod: "bridgeDelegate", | ||
action, | ||
}); | ||
} | ||
|
||
function withSceneDelegate(config, action) { | ||
return withMod(config, { | ||
platform: "ios", | ||
mod: "sceneDelegate", | ||
action, | ||
}); | ||
} | ||
|
||
exports.withBridgeDelegate = withBridgeDelegate; | ||
exports.withSceneDelegate = withSceneDelegate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { createRunOncePlugin } = require("@expo/config-plugins"); | ||
const { | ||
mergeContents, | ||
} = require("@expo/config-plugins/build/utils/generateCode"); | ||
const { withBridgeDelegate } = require("./index"); | ||
|
||
const NAME = "react-native-reanimated"; | ||
|
||
function addContents(tag, src, newSrc, anchor) { | ||
return mergeContents({ | ||
tag: `${NAME}-${tag}`, | ||
src, | ||
newSrc, | ||
anchor, | ||
offset: 1, | ||
comment: "//", | ||
}).contents; | ||
} | ||
|
||
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, | ||
[ | ||
"#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", | ||
].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" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters