Skip to content

Commit

Permalink
Fix issues with relative paths when bundling web apps (software-mansi…
Browse files Browse the repository at this point in the history
…on#3922)

<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary
Fixes issues when bundling web apps using reanimated due to relative
path to `package.json` being wrongly resolved in prebuild reanimated
modules.

<!-- Explain the motivation for this PR. Include "Fixes #<number>" if
applicable. -->
  • Loading branch information
jwajgelt authored and fluiddot committed Jun 5, 2023
1 parent 985781d commit 3547c64
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
28 changes: 2 additions & 26 deletions src/reanimated2/NativeReanimated/NativeReanimated.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/reanimated2/platform-specific/checkVersion.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions src/reanimated2/platform-specific/checkVersion.web.ts
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 3547c64

Please sign in to comment.