From b27dc2ef6c5e5180513d5e4e71034557d5dde808 Mon Sep 17 00:00:00 2001 From: Juliusz Wajgelt Date: Mon, 9 Jan 2023 16:20:32 +0100 Subject: [PATCH] fix issues with relative paths when bundling web apps --- .../NativeReanimated/NativeReanimated.ts | 28 ++----------------- .../platform-specific/checkVersion.ts | 28 +++++++++++++++++++ .../platform-specific/checkVersion.web.ts | 6 ++++ 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 src/reanimated2/platform-specific/checkVersion.ts create mode 100644 src/reanimated2/platform-specific/checkVersion.web.ts diff --git a/src/reanimated2/NativeReanimated/NativeReanimated.ts b/src/reanimated2/NativeReanimated/NativeReanimated.ts index 04952384960..7897e0880d0 100644 --- a/src/reanimated2/NativeReanimated/NativeReanimated.ts +++ b/src/reanimated2/NativeReanimated/NativeReanimated.ts @@ -1,7 +1,7 @@ import { NativeModules } from 'react-native'; import { ShareableRef, ShareableSyncDataHolderRef } from '../commonTypes'; import { LayoutAnimationFunction } from '../layoutReanimation'; -import { version as jsVersion } from '../../../package.json'; +import { checkVersion } from '../platform-specific/checkVersion'; export class NativeReanimated { native: boolean; @@ -15,31 +15,7 @@ export class NativeReanimated { this.InnerNativeModule = global.__reanimatedModuleProxy; this.native = native; if (native) { - this.checkVersion(); - } - } - - checkVersion(): void { - const cppVersion = global._REANIMATED_VERSION_CPP; - const ok = (() => { - if ( - jsVersion.match(/^\d+\.\d+\.\d+$/) && - cppVersion.match(/^\d+\.\d+\.\d+$/) - ) { - // x.y.z, compare only major and minor, skip patch - const [jsMajor, jsMinor] = jsVersion.split('.'); - const [cppMajor, cppMinor] = cppVersion.split('.'); - return jsMajor === cppMajor && jsMinor === cppMinor; - } else { - // alpha, beta or rc, compare everything - return jsVersion === cppVersion; - } - })(); - if (!ok) { - console.error( - `[Reanimated] Mismatch between JavaScript part and native part of Reanimated (${jsVersion} vs. ${cppVersion}). Did you forget to re-build the app after upgrading react-native-reanimated? If you use Expo Go, you must downgrade to ${cppVersion} which is bundled into Expo SDK.` - ); - // TODO: detect Expo managed workflow + checkVersion(); } } diff --git a/src/reanimated2/platform-specific/checkVersion.ts b/src/reanimated2/platform-specific/checkVersion.ts new file mode 100644 index 00000000000..cbf559e4855 --- /dev/null +++ b/src/reanimated2/platform-specific/checkVersion.ts @@ -0,0 +1,28 @@ +import { version as jsVersion } from '../../../package.json'; + +/** + * Checks that native and js versions of reanimated match. + */ +export function checkVersion(): void { + const cppVersion = global._REANIMATED_VERSION_CPP; + const ok = (() => { + if ( + jsVersion.match(/^\d+\.\d+\.\d+$/) && + cppVersion.match(/^\d+\.\d+\.\d+$/) + ) { + // x.y.z, compare only major and minor, skip patch + const [jsMajor, jsMinor] = jsVersion.split('.'); + const [cppMajor, cppMinor] = cppVersion.split('.'); + return jsMajor === cppMajor && jsMinor === cppMinor; + } else { + // alpha, beta or rc, compare everything + return jsVersion === cppVersion; + } + })(); + if (!ok) { + console.error( + `[Reanimated] Mismatch between JavaScript part and native part of Reanimated (${jsVersion} vs. ${cppVersion}). Did you forget to re-build the app after upgrading react-native-reanimated? If you use Expo Go, you must downgrade to ${cppVersion} which is bundled into Expo SDK.` + ); + // TODO: detect Expo managed workflow + } +} diff --git a/src/reanimated2/platform-specific/checkVersion.web.ts b/src/reanimated2/platform-specific/checkVersion.web.ts new file mode 100644 index 00000000000..8c62094355f --- /dev/null +++ b/src/reanimated2/platform-specific/checkVersion.web.ts @@ -0,0 +1,6 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ +/** + * Checks that native and js versions of reanimated match. + * Stubbed for web, where this check is unnecessary. + */ +export function checkVersion(): void {}