Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple version checking #4914

Merged
merged 35 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2987693
init
tjzel Aug 10, 2023
4e0c7ed
androidele
tjzel Aug 10, 2023
d2ab1e9
invertio
tjzel Aug 10, 2023
f4e02fc
renamele
tjzel Aug 10, 2023
0a71101
hmmm... bugs...
tjzel Aug 10, 2023
4fbba50
init
tjzel Aug 10, 2023
9fc54c5
Merge branch 'main' into @tjzel/troubleshooting
tjzel Aug 10, 2023
4311419
remove future
tjzel Aug 10, 2023
80edeeb
sharebale pls
tjzel Aug 10, 2023
ba3861c
test trobule
tjzel Aug 11, 2023
99982f0
url validator lets goooo 🧨
tjzel Aug 11, 2023
3c551d6
fix urls
tjzel Aug 11, 2023
ba149e3
self-review
tjzel Aug 16, 2023
5a58f09
mergele to trobuleshooting
tjzel Aug 16, 2023
6f38b70
fix CI
tjzel Aug 16, 2023
65ca4aa
remove old checker
tjzel Aug 18, 2023
c5c4d67
mergele to trobuleshooting
tjzel Aug 23, 2023
4a107e0
actually...
tjzel Aug 24, 2023
4a86f30
Merge branch 'main' into @tjzel/version-checker
tjzel Aug 24, 2023
bf20b6a
cpp eats java
tjzel Aug 25, 2023
7413264
no more drafties
tjzel Aug 25, 2023
dd68a13
patch matching for js version
tjzel Aug 25, 2023
3fc88aa
Merge branch 'main' into @tjzel/version-checker
tjzel Aug 25, 2023
78d1bbd
mergele main
tjzel Aug 28, 2023
35ba611
huh
tjzel Aug 28, 2023
848916f
ok
tjzel Aug 28, 2023
6d174f7
review changes
tjzel Aug 30, 2023
bd5f532
version checker
tjzel Sep 7, 2023
cc6c399
mergele main
tjzel Sep 7, 2023
87afd30
review changes
tjzel Sep 14, 2023
12b6180
mergele main
tjzel Sep 26, 2023
2b5e2fa
trobuleshouting
tjzel Sep 26, 2023
cfe6749
remove whitespace
tjzel Sep 26, 2023
b8e5081
trobuleshouting
tjzel Sep 26, 2023
10dfb4b
final touches
tjzel Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Common/cpp/Tools/RuntimeDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ void RuntimeDecorator::decorateUIRuntime(
rt, "_maybeFlushUIUpdatesQueue", maybeFlushUIUpdatesQueueFunction);
}

#ifdef DEBUG
void versionCheck(jsi::Runtime &rnRuntime) {
tjzel marked this conversation as resolved.
Show resolved Hide resolved
auto version = getReanimatedVersionString(rnRuntime);

auto JSVersion =
rnRuntime.global().getProperty(rnRuntime, "_REANIMATED_VERSION_JS");
if (JSVersion.isUndefined()) {
throw std::runtime_error(
"[Reanimated] JS version of `react-native-reanimated` is undefined");
}
auto CPPVersionReadable = version.utf8(rnRuntime);
auto JSVersionReadable = JSVersion.asString(rnRuntime).utf8(rnRuntime);
if (JSVersionReadable != CPPVersionReadable) {
auto errorMessage =
"[Reanimated] Mismatch between JS version of `react-native-reanimated` [" +
JSVersionReadable + "] and CPP version [" + CPPVersionReadable + "]";
throw std::runtime_error(errorMessage);
}
rnRuntime.global().setProperty(rnRuntime, "_REANIMATED_VERSION_CPP", version);
}
#endif // DEBUG

void RuntimeDecorator::decorateRNRuntime(
jsi::Runtime &rnRuntime,
const std::shared_ptr<jsi::Runtime> &uiRuntime,
Expand All @@ -178,8 +200,9 @@ void RuntimeDecorator::decorateRNRuntime(
#endif // RCT_NEW_ARCH_ENABLED
rnRuntime.global().setProperty(rnRuntime, "_IS_FABRIC", isFabric);

auto version = getReanimatedVersionString(rnRuntime);
rnRuntime.global().setProperty(rnRuntime, "_REANIMATED_VERSION_CPP", version);
#ifdef DEBUG
versionCheck(rnRuntime);
#endif // DEBUG

rnRuntime.global().setProperty(
rnRuntime, "_REANIMATED_IS_REDUCED_MOTION", isReducedMotion);
Expand Down
17 changes: 16 additions & 1 deletion android/src/main/cpp/NativeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,23 @@ void NativeProxy::installJSIBindings(
#endif
auto &rnRuntime = *rnRuntime_;
auto isReducedMotion = getIsReducedMotion();
auto androidVersion = "3.4.0";
auto JSVersion =
rnRuntime.global().getProperty(rnRuntime, "_REANIMATED_VERSION_JS");
if (JSVersion.isUndefined()) {
throw std::runtime_error(
"[Reanimated] JS version of `react-native-reanimated` is undefined");
}
auto JSVersionReadable = JSVersion.asString(rnRuntime).utf8(rnRuntime);
if (androidVersion != JSVersionReadable) {
auto errorMessage =
"[Reanimated] Mismatch between JS version of `react-native-reanimated` [" +
JSVersionReadable + "] and Android version [" + androidVersion + "]";
throw std::runtime_error(errorMessage);
}
rnRuntime.global().setProperty(
rnRuntime, "_REANIMATED_VERSION_ANDROID", androidVersion);
RuntimeDecorator::decorateRNRuntime(rnRuntime, uiRuntime, isReducedMotion);

registerEventHandler();
setupLayoutAnimations();

Expand Down
23 changes: 23 additions & 0 deletions src/reanimated2/NativeReanimated/NativeReanimated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type {
LayoutAnimationType,
} from '../layoutReanimation';
import { checkCppVersion } from '../platform-specific/checkCppVersion';
import { jsVersion } from '../platform-specific/jsVersion';
import { isAndroid } from '../PlatformChecker';

// this is the type of `__reanimatedModuleProxy` which is injected using JSI
export interface NativeReanimatedModule {
Expand Down Expand Up @@ -67,6 +69,13 @@ export class NativeReanimated {
private InnerNativeModule: NativeReanimatedModule;

constructor() {
if (global._REANIMATED_VERSION_JS === undefined) {
global._REANIMATED_VERSION_JS = jsVersion;
} else {
throw new Error(
'[Reanimated] Another instance of `react-native-reanimated` was detected. Aborting.'
);
}
tjzel marked this conversation as resolved.
Show resolved Hide resolved
if (global.__reanimatedModuleProxy === undefined) {
const { ReanimatedModule } = NativeModules;
ReanimatedModule?.installTurboModule();
Expand All @@ -80,6 +89,20 @@ export class NativeReanimated {
);
}
checkCppVersion();
if (isAndroid()) {
const androidVersion = global._REANIMATED_VERSION_ANDROID;
if (androidVersion === undefined) {
throw new Error(
'[Reanimated] Android native part of Reanimated is not initialized'
);
}
if (androidVersion !== jsVersion) {
throw new Error(
`[Reanimated] Mismatch between android version [${androidVersion}] and JS version ${jsVersion}`
);
}
tjzel marked this conversation as resolved.
Show resolved Hide resolved
}

this.InnerNativeModule = global.__reanimatedModuleProxy;
}

Expand Down
2 changes: 2 additions & 0 deletions src/reanimated2/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ declare global {
var _REANIMATED_IS_REDUCED_MOTION: boolean | undefined;
var _IS_FABRIC: boolean | undefined;
var _REANIMATED_VERSION_CPP: string | undefined;
var _REANIMATED_VERSION_ANDROID: string | undefined;
var _REANIMATED_VERSION_JS: string | undefined;
var _REANIMATED_VERSION_BABEL_PLUGIN: string | undefined;
var __reanimatedModuleProxy: NativeReanimatedModule | undefined;
var evalWithSourceMap:
Expand Down