Skip to content

Commit

Permalink
Move REACT_NATIVE_VERSION to native-only code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Coomber committed Nov 3, 2023
1 parent b0986c3 commit 4d48403
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/getReactNativeVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pack from 'react-native/package.json';

const [majorStr, minorStr] = pack.version.split('.');
const REACT_NATIVE_VERSION = {
major: parseInt(majorStr, 10),
minor: parseInt(minorStr, 10),
};

export function getReactNativeVersion() {
return REACT_NATIVE_VERSION;
}
3 changes: 3 additions & 0 deletions src/getReactNativeVersion.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getReactNativeVersion() {
throw new Error('getReactNativeVersion is not supported on web');
}
3 changes: 2 additions & 1 deletion src/handlers/gestures/GestureDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import { ActionType } from '../../ActionType';
import {
isFabric,
isJestEnv,
REACT_NATIVE_VERSION,
tagMessage,
} from '../../utils';
import { getReactNativeVersion } from 'src/getReactNativeVersion';
import { getShadowNodeFromRef } from '../../getShadowNodeFromRef';
import { Platform } from 'react-native';
import type RNGestureHandlerModuleWeb from '../../RNGestureHandlerModule.web';
Expand Down Expand Up @@ -565,6 +565,7 @@ function validateDetectorChildren(ref: any) {
// / \
// NativeView NativeView
if (__DEV__ && Platform.OS !== 'web') {
const REACT_NATIVE_VERSION = getReactNativeVersion();
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const wrapType =
REACT_NATIVE_VERSION.minor > 63 || REACT_NATIVE_VERSION.major > 0
Expand Down
8 changes: 0 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import pack from 'react-native/package.json';

const [majorStr, minorStr] = pack.version.split('.');
export const REACT_NATIVE_VERSION = {
major: parseInt(majorStr, 10),
minor: parseInt(minorStr, 10),
};

export function toArray<T>(object: T | T[]): T[] {
if (!Array.isArray(object)) {
return [object];
Expand Down

0 comments on commit 4d48403

Please sign in to comment.