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

Fix issues with relative paths when bundling web apps #3922

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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';
tomekzaw marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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 {}