diff --git a/packages/react-native-reanimated/src/js-reanimated/index.ts b/packages/react-native-reanimated/src/js-reanimated/index.ts index 82ffb2d484a7..e750c25736ac 100644 --- a/packages/react-native-reanimated/src/js-reanimated/index.ts +++ b/packages/react-native-reanimated/src/js-reanimated/index.ts @@ -2,37 +2,13 @@ import JSReanimated from './JSReanimated'; import type { StyleProps } from '../commonTypes'; import type { AnimatedStyle } from '../helperTypes'; -import { isWeb } from '../PlatformChecker'; +import { + createReactDOMStyle, + createTransformValue, + createTextShadowValue, +} from './webUtils'; import { PropsAllowlists } from '../propsAllowlists'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let createReactDOMStyle: (style: any) => any; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let createTransformValue: (transform: any) => any; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -let createTextShadowValue: (style: any) => void | string; - -if (isWeb()) { - try { - createReactDOMStyle = - // eslint-disable-next-line @typescript-eslint/no-var-requires - require('react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle').default; - } catch (e) {} - - try { - // React Native Web 0.19+ - createTransformValue = - // eslint-disable-next-line @typescript-eslint/no-var-requires - require('react-native-web/dist/exports/StyleSheet/preprocess').createTransformValue; - } catch (e) {} - - try { - createTextShadowValue = - // eslint-disable-next-line @typescript-eslint/no-var-requires - require('react-native-web/dist/exports/StyleSheet/preprocess').createTextShadowValue; - } catch (e) {} -} - const reanimatedJS = new JSReanimated(); global._makeShareableClone = () => { diff --git a/packages/react-native-reanimated/src/js-reanimated/webUtils.ts b/packages/react-native-reanimated/src/js-reanimated/webUtils.ts new file mode 100644 index 000000000000..d568831159cd --- /dev/null +++ b/packages/react-native-reanimated/src/js-reanimated/webUtils.ts @@ -0,0 +1,8 @@ +'use strict'; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export let createReactDOMStyle: (style: any) => any; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export let createTransformValue: (transform: any) => any; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export let createTextShadowValue: (style: any) => void | string; diff --git a/packages/react-native-reanimated/src/js-reanimated/webUtils.web.ts b/packages/react-native-reanimated/src/js-reanimated/webUtils.web.ts new file mode 100644 index 000000000000..957dd6b0eb60 --- /dev/null +++ b/packages/react-native-reanimated/src/js-reanimated/webUtils.web.ts @@ -0,0 +1,27 @@ +'use strict'; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export let createReactDOMStyle: (style: any) => any; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export let createTransformValue: (transform: any) => any; +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export let createTextShadowValue: (style: any) => void | string; + +try { + createReactDOMStyle = + // eslint-disable-next-line @typescript-eslint/no-var-requires + require('react-native-web/dist/exports/StyleSheet/compiler/createReactDOMStyle').default; +} catch (e) {} + +try { + // React Native Web 0.19+ + createTransformValue = + // eslint-disable-next-line @typescript-eslint/no-var-requires + require('react-native-web/dist/exports/StyleSheet/preprocess').createTransformValue; +} catch (e) {} + +try { + createTextShadowValue = + // eslint-disable-next-line @typescript-eslint/no-var-requires + require('react-native-web/dist/exports/StyleSheet/preprocess').createTextShadowValue; +} catch (e) {}