react-native-unistyles 3.0.0-beta.8 → 3.0.0-experimental-2025051402
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -26
- package/Unistyles.podspec +1 -0
- package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
- package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +2 -3
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
- package/components/native/ActivityIndicator/package.json +1 -0
- package/components/native/Animated/package.json +1 -0
- package/components/native/FlatList/package.json +1 -0
- package/components/native/Image/package.json +2 -1
- package/components/native/ImageBackground/package.json +1 -0
- package/components/native/KeyboardAvoidingView/package.json +1 -0
- package/components/native/NativeText/package.json +1 -0
- package/components/native/NativeView/package.json +1 -0
- package/components/native/Pressable/package.json +1 -0
- package/components/native/RefreshControl/package.json +1 -0
- package/components/native/ScrollView/package.json +1 -0
- package/components/native/SectionList/package.json +1 -0
- package/components/native/Switch/package.json +1 -0
- package/components/native/Text/package.json +1 -0
- package/components/native/TextInput/package.json +1 -0
- package/components/native/TouchableHighlight/package.json +1 -0
- package/components/native/TouchableOpacity/package.json +1 -0
- package/components/native/View/package.json +1 -0
- package/components/native/VirtualizedList/package.json +1 -0
- package/cxx/common/Helpers.h +4 -0
- package/cxx/core/HostUnistyle.cpp +14 -5
- package/cxx/core/StyleSheet.h +1 -1
- package/cxx/core/UnistyleWrapper.h +1 -1
- package/cxx/core/UnistylesCommitShadowNode.h +0 -21
- package/cxx/core/UnistylesRegistry.cpp +67 -64
- package/cxx/core/UnistylesRegistry.h +1 -1
- package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
- package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
- package/cxx/parser/Parser.cpp +161 -115
- package/cxx/parser/Parser.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +7 -9
- package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
- package/cxx/shadowTree/ShadowTreeManager.h +0 -1
- package/ios/NativePlatform+ios.swift +1 -1
- package/ios/NativePlatformListener+ios.swift +12 -7
- package/ios/UnistylesModuleOnLoad.h +1 -5
- package/ios/UnistylesModuleOnLoad.mm +5 -13
- package/lib/commonjs/components/native/Image.js +27 -1
- package/lib/commonjs/components/native/Image.js.map +1 -1
- package/lib/commonjs/components/native/Image.native.js +10 -0
- package/lib/commonjs/components/native/Image.native.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +17 -28
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +7 -4
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +17 -21
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +6 -4
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +7 -5
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +11 -5
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +3 -5
- package/lib/commonjs/core/passForwardRef.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +14 -5
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.js +4 -4
- package/lib/commonjs/hooks/useMedia.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.native.js +4 -4
- package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
- package/lib/commonjs/mocks.js +203 -0
- package/lib/commonjs/mocks.js.map +1 -0
- package/lib/commonjs/mq.js +1 -23
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/reanimated/index.js +13 -0
- package/lib/commonjs/reanimated/index.js.map +1 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
- package/lib/commonjs/server/getServerUnistyles.js +9 -4
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js +4 -2
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/serialize.js +24 -0
- package/lib/commonjs/server/serialize.js.map +1 -0
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/utils.js +23 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/index.js +4 -7
- package/lib/commonjs/web/convert/index.js.map +1 -1
- package/lib/commonjs/web/convert/object/filter.js +7 -8
- package/lib/commonjs/web/convert/object/filter.js.map +1 -1
- package/lib/commonjs/web/create.js +10 -2
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/core.js +2 -2
- package/lib/commonjs/web/css/core.js.map +1 -1
- package/lib/commonjs/web/css/state.js +6 -3
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/index.js +7 -12
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/registry.js +11 -9
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +5 -1
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/services.js +7 -2
- package/lib/commonjs/web/services.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +27 -10
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +11 -2
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/types.js +2 -0
- package/lib/commonjs/web/types.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +31 -0
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
- package/lib/commonjs/web/utils/unistyle.js +40 -14
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web-only/getWebProps.js +19 -0
- package/lib/commonjs/web-only/getWebProps.js.map +1 -0
- package/lib/commonjs/web-only/index.js +13 -0
- package/lib/commonjs/web-only/index.js.map +1 -0
- package/lib/module/components/native/Image.js +26 -2
- package/lib/module/components/native/Image.js.map +1 -1
- package/lib/module/components/native/Image.native.js +6 -0
- package/lib/module/components/native/Image.native.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +18 -29
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +7 -4
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +17 -21
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +6 -4
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +7 -5
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/getClassname.js +9 -5
- package/lib/module/core/getClassname.js.map +1 -1
- package/lib/module/core/passForwardRef.js +3 -5
- package/lib/module/core/passForwardRef.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.js +14 -5
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/hooks/useMedia.js +1 -1
- package/lib/module/hooks/useMedia.js.map +1 -1
- package/lib/module/hooks/useMedia.native.js +1 -1
- package/lib/module/hooks/useMedia.native.js.map +1 -1
- package/lib/module/mocks.js +201 -0
- package/lib/module/mocks.js.map +1 -0
- package/lib/module/mq.js +0 -19
- package/lib/module/mq.js.map +1 -1
- package/lib/module/reanimated/index.js +4 -0
- package/lib/module/reanimated/index.js.map +1 -0
- package/lib/module/reanimated/useAnimatedTheme.js +17 -0
- package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
- package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
- package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
- package/lib/module/server/getServerUnistyles.js +7 -4
- package/lib/module/server/getServerUnistyles.js.map +1 -1
- package/lib/module/server/hydrateServerUnistyles.js +2 -2
- package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/module/server/resetServerUnistyles.js +2 -2
- package/lib/module/server/resetServerUnistyles.js.map +1 -1
- package/lib/module/server/serialize.js +19 -0
- package/lib/module/server/serialize.js.map +1 -0
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/utils.js +19 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/index.js +4 -7
- package/lib/module/web/convert/index.js.map +1 -1
- package/lib/module/web/convert/object/filter.js +3 -4
- package/lib/module/web/convert/object/filter.js.map +1 -1
- package/lib/module/web/create.js +9 -3
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/core.js +2 -2
- package/lib/module/web/css/core.js.map +1 -1
- package/lib/module/web/css/state.js +6 -3
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/index.js +4 -10
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/registry.js +11 -9
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +5 -1
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/services.js +7 -1
- package/lib/module/web/services.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +27 -10
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +11 -2
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/types.js +1 -1
- package/lib/module/web/types.js.map +1 -1
- package/lib/module/web/utils/createUnistylesRef.js +24 -0
- package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
- package/lib/module/web/utils/unistyle.js +32 -10
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web-only/getWebProps.js +14 -0
- package/lib/module/web-only/getWebProps.js.map +1 -0
- package/lib/module/web-only/index.js +4 -0
- package/lib/module/web-only/index.js.map +1 -0
- package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
- package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/getClassname.d.ts +5 -5
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/warn.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
- package/lib/typescript/src/mocks.d.ts +2 -0
- package/lib/typescript/src/mocks.d.ts.map +1 -0
- package/lib/typescript/src/mq.d.ts +0 -8
- package/lib/typescript/src/mq.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/index.d.ts +2 -0
- package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
- package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/serialize.d.ts +2 -0
- package/lib/typescript/src/server/serialize.d.ts.map +1 -0
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/types/common.d.ts +0 -1
- package/lib/typescript/src/types/common.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +8 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/index.d.ts +2 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/css/core.d.ts.map +1 -1
- package/lib/typescript/src/web/css/state.d.ts +4 -1
- package/lib/typescript/src/web/css/state.d.ts.map +1 -1
- package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +0 -5
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +2 -2
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/services.d.ts +6 -1
- package/lib/typescript/src/web/services.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts +2 -0
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +3 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +11 -0
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -2
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/lib/typescript/src/web/variants.d.ts.map +1 -1
- package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
- package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
- package/lib/typescript/src/web-only/index.d.ts +2 -0
- package/lib/typescript/src/web-only/index.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
- package/package.json +66 -32
- package/plugin/index.js +155 -67
- package/reanimated/package.json +6 -0
- package/server/package.json +6 -0
- package/src/components/native/Image.native.tsx +4 -0
- package/src/components/native/Image.tsx +36 -3
- package/src/components/native/ImageBackground.tsx +18 -33
- package/src/components/native/Pressable.native.tsx +12 -4
- package/src/core/createUnistylesElement.native.tsx +12 -6
- package/src/core/createUnistylesElement.tsx +26 -27
- package/src/core/createUnistylesImageBackground.tsx +16 -10
- package/src/core/getClassname.ts +16 -5
- package/src/core/passForwardRef.ts +5 -5
- package/src/core/useProxifiedUnistyles/listener.ts +3 -3
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +17 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +3 -4
- package/src/core/withUnistyles/withUnistyles.tsx +23 -6
- package/src/hooks/useMedia.native.ts +1 -1
- package/src/hooks/useMedia.ts +1 -1
- package/src/mocks.ts +217 -0
- package/src/mq.ts +0 -24
- package/src/reanimated/index.ts +1 -0
- package/src/reanimated/useAnimatedTheme.native.ts +21 -0
- package/src/reanimated/useAnimatedTheme.ts +19 -0
- package/src/server/getServerUnistyles.tsx +15 -10
- package/src/server/hydrateServerUnistyles.ts +3 -2
- package/src/server/resetServerUnistyles.ts +4 -3
- package/src/server/serialize.ts +20 -0
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
- package/src/specs/ShadowRegistry/index.ts +1 -2
- package/src/types/common.ts +0 -1
- package/src/utils.ts +25 -0
- package/src/web/convert/index.ts +5 -7
- package/src/web/convert/object/filter.ts +4 -4
- package/src/web/create.ts +10 -3
- package/src/web/css/core.ts +2 -2
- package/src/web/css/state.ts +5 -3
- package/src/web/index.ts +4 -16
- package/src/web/registry.ts +20 -11
- package/src/web/runtime.ts +6 -2
- package/src/web/services.ts +14 -1
- package/src/web/shadowRegistry.ts +35 -13
- package/src/web/state.ts +14 -2
- package/src/web/types.ts +9 -4
- package/src/web/utils/createUnistylesRef.ts +33 -0
- package/src/web/utils/unistyle.ts +55 -23
- package/src/web-only/getWebProps.ts +18 -0
- package/src/web-only/index.ts +2 -0
- package/web/package.json +6 -0
- package/cxx/core/UnistylesCommitHook.cpp +0 -52
- package/cxx/core/UnistylesCommitHook.h +0 -27
- package/cxx/core/UnistylesMountHook.cpp +0 -28
- package/cxx/core/UnistylesMountHook.h +0 -24
- package/lib/module/package.json +0 -1
- /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
package/plugin/index.js
CHANGED
@@ -59,6 +59,9 @@ var REACT_NATIVE_COMPONENT_NAMES = [
|
|
59
59
|
];
|
60
60
|
var REPLACE_WITH_UNISTYLES_PATHS = [
|
61
61
|
"react-native-reanimated/src/component",
|
62
|
+
"react-native-reanimated/lib/module/component",
|
63
|
+
"react-native-gesture-handler/lib/module/components",
|
64
|
+
"react-native-gesture-handler/lib/commonjs/components",
|
62
65
|
"react-native-gesture-handler/src/components"
|
63
66
|
];
|
64
67
|
var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
|
@@ -80,10 +83,10 @@ var NATIVE_COMPONENTS_PATHS = {
|
|
80
83
|
|
81
84
|
// plugin/src/exotic.ts
|
82
85
|
var t = __toESM(require("@babel/types"));
|
83
|
-
function handleExoticImport(
|
84
|
-
const specifiers =
|
85
|
-
const source =
|
86
|
-
if (
|
86
|
+
function handleExoticImport(path2, state, exoticImport) {
|
87
|
+
const specifiers = path2.node.specifiers;
|
88
|
+
const source = path2.node.source;
|
89
|
+
if (path2.node.importKind !== "value") {
|
87
90
|
return;
|
88
91
|
}
|
89
92
|
specifiers.forEach((specifier) => {
|
@@ -101,7 +104,7 @@ function handleExoticImport(path, state, exoticImport) {
|
|
101
104
|
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
|
102
105
|
)
|
103
106
|
);
|
104
|
-
|
107
|
+
path2.replaceWith(newImport);
|
105
108
|
} else {
|
106
109
|
const newImport = t.importDeclaration(
|
107
110
|
[t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
|
@@ -109,11 +112,11 @@ function handleExoticImport(path, state, exoticImport) {
|
|
109
112
|
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
|
110
113
|
)
|
111
114
|
);
|
112
|
-
|
113
|
-
if (
|
114
|
-
|
115
|
+
path2.node.specifiers = specifiers.filter((s) => s !== specifier);
|
116
|
+
if (path2.node.specifiers.length === 0) {
|
117
|
+
path2.replaceWith(newImport);
|
115
118
|
} else {
|
116
|
-
|
119
|
+
path2.insertBefore(newImport);
|
117
120
|
}
|
118
121
|
}
|
119
122
|
return;
|
@@ -123,12 +126,12 @@ function handleExoticImport(path, state, exoticImport) {
|
|
123
126
|
|
124
127
|
// plugin/src/import.ts
|
125
128
|
var t2 = __toESM(require("@babel/types"));
|
126
|
-
function addUnistylesImport(
|
129
|
+
function addUnistylesImport(path2, state) {
|
127
130
|
const localNames = Object.keys(state.reactNativeImports);
|
128
131
|
const names = Object.values(state.reactNativeImports);
|
129
132
|
const pairs = Object.entries(state.reactNativeImports);
|
130
133
|
const nodesToRemove = [];
|
131
|
-
|
134
|
+
path2.node.body.forEach((node) => {
|
132
135
|
if (t2.isImportDeclaration(node) && node.source.value === "react-native") {
|
133
136
|
node.specifiers = node.specifiers.filter((specifier) => !localNames.some((name) => name === specifier.local.name));
|
134
137
|
if (node.specifiers.length === 0) {
|
@@ -137,7 +140,7 @@ function addUnistylesImport(path, state) {
|
|
137
140
|
}
|
138
141
|
});
|
139
142
|
names.forEach((name) => {
|
140
|
-
const rnWebImport =
|
143
|
+
const rnWebImport = path2.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`);
|
141
144
|
if (rnWebImport) {
|
142
145
|
rnWebImport.specifiers = [];
|
143
146
|
}
|
@@ -149,18 +152,41 @@ function addUnistylesImport(path, state) {
|
|
149
152
|
state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/src/components/native/${name}`) ?? "" : `react-native-unistyles/components/native/${name}`
|
150
153
|
)
|
151
154
|
);
|
152
|
-
|
155
|
+
path2.node.body.unshift(newImport);
|
153
156
|
});
|
154
|
-
nodesToRemove.forEach((node) =>
|
157
|
+
nodesToRemove.forEach((node) => path2.node.body.splice(path2.node.body.indexOf(node), 1));
|
155
158
|
}
|
156
159
|
function isInsideNodeModules(state) {
|
157
|
-
return state.file.opts.filename?.includes("node_modules");
|
160
|
+
return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
|
158
161
|
}
|
162
|
+
function addUnistylesRequire(path2, state) {
|
163
|
+
Object.entries(state.reactNativeImports).forEach(([componentName, uniqueName]) => {
|
164
|
+
const newRequire = t2.variableDeclaration("const", [
|
165
|
+
t2.variableDeclarator(
|
166
|
+
t2.identifier(uniqueName),
|
167
|
+
t2.callExpression(t2.identifier("require"), [
|
168
|
+
t2.stringLiteral(`react-native-unistyles/src/components/native/${componentName}`)
|
169
|
+
])
|
170
|
+
)
|
171
|
+
]);
|
172
|
+
path2.node.body.unshift(newRequire);
|
173
|
+
});
|
174
|
+
}
|
175
|
+
|
176
|
+
// plugin/src/paths.ts
|
177
|
+
var import_node_path = __toESM(require("node:path"));
|
178
|
+
var isWindows = process.platform === "win32";
|
179
|
+
var toWinPath = (pathString) => {
|
180
|
+
return import_node_path.default.normalize(pathString).replace(/\//g, "\\");
|
181
|
+
};
|
182
|
+
var toPlatformPath = (pathString) => {
|
183
|
+
return isWindows ? toWinPath(pathString) : pathString;
|
184
|
+
};
|
159
185
|
|
160
186
|
// plugin/src/ref.ts
|
161
187
|
var t3 = __toESM(require("@babel/types"));
|
162
|
-
function hasStringRef(
|
163
|
-
return
|
188
|
+
function hasStringRef(path2) {
|
189
|
+
return path2.node.openingElement.attributes.find(
|
164
190
|
(attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
|
165
191
|
);
|
166
192
|
}
|
@@ -182,7 +208,8 @@ var UnistyleDependency = {
|
|
182
208
|
FontScale: 11,
|
183
209
|
StatusBar: 12,
|
184
210
|
NavigationBar: 13,
|
185
|
-
Ime: 14
|
211
|
+
Ime: 14,
|
212
|
+
Rtl: 15
|
186
213
|
};
|
187
214
|
function getProperty(property) {
|
188
215
|
if (!property) {
|
@@ -265,6 +292,9 @@ function toUnistylesDependency(dependency) {
|
|
265
292
|
case "variants": {
|
266
293
|
return UnistyleDependency.Variants;
|
267
294
|
}
|
295
|
+
case "rtl": {
|
296
|
+
return UnistyleDependency.Rtl;
|
297
|
+
}
|
268
298
|
default:
|
269
299
|
return null;
|
270
300
|
}
|
@@ -293,28 +323,47 @@ function stringToUniqueId(str) {
|
|
293
323
|
const absHash = Math.abs(hash);
|
294
324
|
return absHash % 1e9;
|
295
325
|
}
|
296
|
-
function isUnistylesStyleSheet(
|
297
|
-
const { callee } =
|
298
|
-
if (t4.isMemberExpression(callee)
|
299
|
-
return
|
326
|
+
function isUnistylesStyleSheet(path2, state) {
|
327
|
+
const { callee } = path2.node;
|
328
|
+
if (!t4.isMemberExpression(callee) || !t4.isIdentifier(callee.property)) {
|
329
|
+
return false;
|
330
|
+
}
|
331
|
+
const isImport = callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
|
332
|
+
const isRequire = state.file.hasUnistylesImport && callee.property.name === "create" && t4.isMemberExpression(callee.object) && t4.isIdentifier(callee.object.property) && t4.isIdentifier(callee.object.object) && callee.object.object.name === state.file.styleSheetLocalName && callee.object.property.name === "StyleSheet";
|
333
|
+
return isImport || isRequire;
|
334
|
+
}
|
335
|
+
function isUnistylesCommonJSRequire(path2, state) {
|
336
|
+
const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && t4.isStringLiteral(path2.node.arguments[0]) && path2.node.arguments[0].value === "react-native-unistyles";
|
337
|
+
if (isRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
|
338
|
+
state.file.hasUnistylesImport = true;
|
339
|
+
state.file.styleSheetLocalName = path2.parent.id.name;
|
340
|
+
}
|
341
|
+
return isRequire;
|
342
|
+
}
|
343
|
+
function isReactNativeCommonJSRequire(path2, state) {
|
344
|
+
const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && path2.node.callee.name === "require";
|
345
|
+
const requireImportName = path2.node.arguments.find((node) => t4.isStringLiteral(node));
|
346
|
+
const isReactNativeRequire = isRequire && requireImportName && (requireImportName.value === "react-native" || requireImportName.value === "react-native-web/dist/index");
|
347
|
+
if (isReactNativeRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
|
348
|
+
state.file.reactNativeCommonJSName = path2.parent.id.name;
|
300
349
|
}
|
301
|
-
return
|
350
|
+
return isRequire;
|
302
351
|
}
|
303
|
-
function isKindOfStyleSheet(
|
352
|
+
function isKindOfStyleSheet(path2, state) {
|
304
353
|
if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
|
305
354
|
return false;
|
306
355
|
}
|
307
|
-
const { callee } =
|
356
|
+
const { callee } = path2.node;
|
308
357
|
return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
|
309
358
|
}
|
310
|
-
function addStyleSheetTag(
|
359
|
+
function addStyleSheetTag(path2, state) {
|
311
360
|
const str = state.filename?.replace(state.cwd, "") ?? "";
|
312
361
|
const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
|
313
|
-
|
362
|
+
path2.node.arguments.push(t4.numericLiteral(uniqueId));
|
314
363
|
}
|
315
|
-
function getStylesDependenciesFromObject(
|
364
|
+
function getStylesDependenciesFromObject(path2) {
|
316
365
|
const detectedStylesWithVariants = /* @__PURE__ */ new Set();
|
317
|
-
const stylesheet =
|
366
|
+
const stylesheet = path2.node.arguments[0];
|
318
367
|
if (t4.isObjectExpression(stylesheet)) {
|
319
368
|
stylesheet?.properties.forEach((property) => {
|
320
369
|
if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
|
@@ -359,8 +408,7 @@ function getStylesDependenciesFromObject(path) {
|
|
359
408
|
return acc;
|
360
409
|
}, {});
|
361
410
|
}
|
362
|
-
function getStylesDependenciesFromFunction(
|
363
|
-
const funcPath = path.get("arguments.0");
|
411
|
+
function getStylesDependenciesFromFunction(funcPath) {
|
364
412
|
if (!funcPath) {
|
365
413
|
return;
|
366
414
|
}
|
@@ -614,8 +662,8 @@ function addDependencies(state, styleName, unistyle, detectedDependencies) {
|
|
614
662
|
|
615
663
|
// plugin/src/variants.ts
|
616
664
|
var t5 = __toESM(require("@babel/types"));
|
617
|
-
function extractVariants(
|
618
|
-
const maybeVariants =
|
665
|
+
function extractVariants(path2, state) {
|
666
|
+
const maybeVariants = path2.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
|
619
667
|
if (maybeVariants.length === 0) {
|
620
668
|
return;
|
621
669
|
}
|
@@ -638,7 +686,7 @@ function extractVariants(path, state) {
|
|
638
686
|
return;
|
639
687
|
}
|
640
688
|
const calleeName = callee.object.name;
|
641
|
-
const newUniqueName =
|
689
|
+
const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
|
642
690
|
const shadowDeclaration = t5.variableDeclaration("const", [
|
643
691
|
t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
|
644
692
|
]);
|
@@ -649,14 +697,14 @@ function extractVariants(path, state) {
|
|
649
697
|
const finalDeclaration = t5.variableDeclaration("const", [
|
650
698
|
t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
|
651
699
|
]);
|
652
|
-
const pathIndex =
|
653
|
-
const rest =
|
700
|
+
const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
|
701
|
+
const rest = path2.node.body.slice(pathIndex + 1);
|
654
702
|
const statement = t5.blockStatement([
|
655
703
|
finalDeclaration,
|
656
704
|
...rest
|
657
705
|
]);
|
658
|
-
|
659
|
-
...
|
706
|
+
path2.node.body = [
|
707
|
+
...path2.node.body.slice(0, pathIndex),
|
660
708
|
shadowDeclaration,
|
661
709
|
statement
|
662
710
|
];
|
@@ -665,52 +713,71 @@ function extractVariants(path, state) {
|
|
665
713
|
|
666
714
|
// plugin/src/index.ts
|
667
715
|
function index_default() {
|
716
|
+
if (process.env.NODE_ENV === "test") {
|
717
|
+
return {
|
718
|
+
name: "babel-react-native-unistyles",
|
719
|
+
visitor: {}
|
720
|
+
};
|
721
|
+
}
|
668
722
|
return {
|
669
723
|
name: "babel-react-native-unistyles",
|
670
724
|
visitor: {
|
671
725
|
Program: {
|
672
|
-
enter(
|
673
|
-
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.concat(state.opts.autoProcessPaths ?? []).some((
|
726
|
+
enter(path2, state) {
|
727
|
+
state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path3) => state.filename?.includes(path3));
|
674
728
|
state.file.hasAnyUnistyle = false;
|
675
729
|
state.file.hasUnistylesImport = false;
|
730
|
+
state.file.addUnistylesRequire = false;
|
676
731
|
state.file.hasVariants = false;
|
677
732
|
state.file.styleSheetLocalName = "";
|
733
|
+
state.file.reactNativeCommonJSName = "";
|
678
734
|
state.file.tagNumber = 0;
|
679
735
|
state.reactNativeImports = {};
|
680
|
-
state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`) : false;
|
736
|
+
state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
|
737
|
+
path2.traverse({
|
738
|
+
BlockStatement(blockPath) {
|
739
|
+
if (isInsideNodeModules(state)) {
|
740
|
+
return;
|
741
|
+
}
|
742
|
+
extractVariants(blockPath, state);
|
743
|
+
}
|
744
|
+
});
|
681
745
|
},
|
682
|
-
exit(
|
683
|
-
if (isInsideNodeModules(state)
|
746
|
+
exit(path2, state) {
|
747
|
+
if (isInsideNodeModules(state)) {
|
684
748
|
return;
|
685
749
|
}
|
750
|
+
if (state.file.addUnistylesRequire) {
|
751
|
+
return addUnistylesRequire(path2, state);
|
752
|
+
}
|
686
753
|
if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
|
687
|
-
addUnistylesImport(
|
754
|
+
addUnistylesImport(path2, state);
|
688
755
|
}
|
689
756
|
}
|
690
757
|
},
|
691
|
-
FunctionDeclaration(
|
758
|
+
FunctionDeclaration(path2, state) {
|
692
759
|
if (isInsideNodeModules(state)) {
|
693
760
|
return;
|
694
761
|
}
|
695
|
-
const componentName =
|
762
|
+
const componentName = path2.node.id ? path2.node.id.name : null;
|
696
763
|
if (componentName) {
|
697
764
|
state.file.hasVariants = false;
|
698
765
|
}
|
699
766
|
},
|
700
|
-
ClassDeclaration(
|
767
|
+
ClassDeclaration(path2, state) {
|
701
768
|
if (isInsideNodeModules(state)) {
|
702
769
|
return;
|
703
770
|
}
|
704
|
-
const componentName =
|
771
|
+
const componentName = path2.node.id ? path2.node.id.name : null;
|
705
772
|
if (componentName) {
|
706
773
|
state.file.hasVariants = false;
|
707
774
|
}
|
708
775
|
},
|
709
|
-
VariableDeclaration(
|
776
|
+
VariableDeclaration(path2, state) {
|
710
777
|
if (isInsideNodeModules(state)) {
|
711
778
|
return;
|
712
779
|
}
|
713
|
-
|
780
|
+
path2.node.declarations.forEach((declaration) => {
|
714
781
|
if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
|
715
782
|
const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
|
716
783
|
if (componentName) {
|
@@ -719,63 +786,83 @@ function index_default() {
|
|
719
786
|
}
|
720
787
|
});
|
721
788
|
},
|
722
|
-
ImportDeclaration(
|
789
|
+
ImportDeclaration(path2, state) {
|
723
790
|
const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
|
724
791
|
if (exoticImport) {
|
725
|
-
return handleExoticImport(
|
792
|
+
return handleExoticImport(path2, state, exoticImport);
|
726
793
|
}
|
727
|
-
if (isInsideNodeModules(state)
|
794
|
+
if (isInsideNodeModules(state)) {
|
728
795
|
return;
|
729
796
|
}
|
730
|
-
const importSource =
|
797
|
+
const importSource = path2.node.source.value;
|
731
798
|
if (importSource.includes("react-native-unistyles")) {
|
732
799
|
state.file.hasUnistylesImport = true;
|
733
|
-
|
800
|
+
path2.node.specifiers.forEach((specifier) => {
|
734
801
|
if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
|
735
802
|
state.file.styleSheetLocalName = specifier.local.name;
|
736
803
|
}
|
737
804
|
});
|
738
805
|
}
|
739
806
|
if (importSource === "react-native") {
|
740
|
-
|
807
|
+
path2.node.specifiers.forEach((specifier) => {
|
741
808
|
if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
|
742
809
|
state.reactNativeImports[specifier.local.name] = specifier.imported.name;
|
743
810
|
}
|
744
811
|
});
|
745
812
|
}
|
746
813
|
if (importSource.includes("react-native/Libraries")) {
|
747
|
-
handleExoticImport(
|
814
|
+
handleExoticImport(path2, state, NATIVE_COMPONENTS_PATHS);
|
748
815
|
}
|
749
816
|
if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
|
750
817
|
state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
|
751
818
|
}
|
752
819
|
},
|
753
|
-
JSXElement(
|
820
|
+
JSXElement(path2, state) {
|
754
821
|
if (isInsideNodeModules(state)) {
|
755
822
|
return;
|
756
823
|
}
|
757
|
-
if (hasStringRef(
|
824
|
+
if (hasStringRef(path2)) {
|
758
825
|
throw new Error("Detected string based ref which is not supported by Unistyles.");
|
759
826
|
}
|
760
827
|
},
|
761
|
-
|
828
|
+
MemberExpression(path2, state) {
|
762
829
|
if (isInsideNodeModules(state)) {
|
763
830
|
return;
|
764
831
|
}
|
765
|
-
|
832
|
+
if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.object)) {
|
833
|
+
return;
|
834
|
+
}
|
835
|
+
if (path2.node.object.name !== state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.property)) {
|
836
|
+
return;
|
837
|
+
}
|
838
|
+
if (!REACT_NATIVE_COMPONENT_NAMES.includes(path2.node.property.name)) {
|
839
|
+
return;
|
840
|
+
}
|
841
|
+
if (!state.reactNativeImports[path2.node.property.name]) {
|
842
|
+
const uniqueId = path2.scope.generateUidIdentifier(`reactNativeUnistyles_${path2.node.property.name}`);
|
843
|
+
state.reactNativeImports[path2.node.property.name] = uniqueId.name;
|
844
|
+
state.file.addUnistylesRequire = true;
|
845
|
+
}
|
846
|
+
path2.node.object.name = state.reactNativeImports[path2.node.property.name];
|
766
847
|
},
|
767
|
-
CallExpression(
|
848
|
+
CallExpression(path2, state) {
|
768
849
|
if (isInsideNodeModules(state)) {
|
769
850
|
return;
|
770
851
|
}
|
771
|
-
if (
|
852
|
+
if (isUnistylesCommonJSRequire(path2, state)) {
|
853
|
+
return;
|
854
|
+
}
|
855
|
+
if (isReactNativeCommonJSRequire(path2, state)) {
|
856
|
+
return;
|
857
|
+
}
|
858
|
+
if (!isUnistylesStyleSheet(path2, state) && !isKindOfStyleSheet(path2, state)) {
|
772
859
|
return;
|
773
860
|
}
|
774
861
|
state.file.hasAnyUnistyle = true;
|
775
|
-
addStyleSheetTag(
|
776
|
-
const arg =
|
862
|
+
addStyleSheetTag(path2, state);
|
863
|
+
const arg = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.node.arguments[0].right : path2.node.arguments[0];
|
777
864
|
if (t6.isObjectExpression(arg)) {
|
778
|
-
const detectedDependencies = getStylesDependenciesFromObject(
|
865
|
+
const detectedDependencies = getStylesDependenciesFromObject(path2);
|
779
866
|
if (detectedDependencies) {
|
780
867
|
if (t6.isObjectExpression(arg)) {
|
781
868
|
arg.properties.forEach((property) => {
|
@@ -787,7 +874,8 @@ function index_default() {
|
|
787
874
|
}
|
788
875
|
}
|
789
876
|
if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
|
790
|
-
const
|
877
|
+
const funcPath = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.get("arguments.0.right") : path2.get("arguments.0");
|
878
|
+
const detectedDependencies = getStylesDependenciesFromFunction(funcPath);
|
791
879
|
if (detectedDependencies) {
|
792
880
|
const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;
|
793
881
|
if (t6.isObjectExpression(body)) {
|
@@ -1,4 +1,37 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import React, { type ComponentProps, forwardRef } from 'react'
|
2
|
+
import { type ImageStyle, Image as NativeImage, type StyleProp, type ViewStyle } from 'react-native'
|
3
|
+
import { getClassName } from '../../core'
|
4
|
+
import { maybeWarnAboutMultipleUnistyles } from '../../core/warn'
|
5
|
+
import type { UnistylesValues } from '../../types'
|
6
|
+
import { copyComponentProperties } from '../../utils'
|
7
|
+
import { checkForProp } from '../../web/utils'
|
8
|
+
import { createUnistylesRef } from '../../web/utils/createUnistylesRef'
|
3
9
|
|
4
|
-
|
10
|
+
type Props = ComponentProps<typeof NativeImage> & {
|
11
|
+
style?: UnistylesValues
|
12
|
+
imageStyle?: UnistylesValues
|
13
|
+
}
|
14
|
+
|
15
|
+
const UnistylesImage = forwardRef<unknown, Props>((props, forwardedRef) => {
|
16
|
+
const classNames = getClassName(props.style)
|
17
|
+
const ref = createUnistylesRef(classNames, forwardedRef)
|
18
|
+
const hasWidthStyle = checkForProp(props.style, 'width')
|
19
|
+
const hasHeightStyle = checkForProp(props.style, 'height')
|
20
|
+
|
21
|
+
maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, 'Image')
|
22
|
+
|
23
|
+
return (
|
24
|
+
<NativeImage
|
25
|
+
{...props}
|
26
|
+
style={[
|
27
|
+
classNames,
|
28
|
+
// Clear inline width and height extracted from source
|
29
|
+
hasWidthStyle && { width: '' },
|
30
|
+
hasHeightStyle && { height: '' }
|
31
|
+
] as StyleProp<ImageStyle>}
|
32
|
+
ref={ref}
|
33
|
+
/>
|
34
|
+
)
|
35
|
+
})
|
36
|
+
|
37
|
+
export const Image = copyComponentProperties(NativeImage, UnistylesImage)
|
@@ -2,10 +2,11 @@ import React from 'react'
|
|
2
2
|
import { forwardRef } from 'react'
|
3
3
|
import { type ImageStyle, ImageBackground as NativeImageBackground, type StyleProp, type ViewStyle } from 'react-native'
|
4
4
|
import { getClassName } from '../../core'
|
5
|
+
import { maybeWarnAboutMultipleUnistyles } from '../../core/warn'
|
5
6
|
import type { UnistylesValues } from '../../types'
|
6
7
|
import { copyComponentProperties } from '../../utils'
|
7
|
-
import {
|
8
|
-
import {
|
8
|
+
import { keyInObject } from '../../web/utils'
|
9
|
+
import { createUnistylesRef } from '../../web/utils/createUnistylesRef'
|
9
10
|
|
10
11
|
type Props = {
|
11
12
|
style?: UnistylesValues
|
@@ -13,44 +14,28 @@ type Props = {
|
|
13
14
|
}
|
14
15
|
|
15
16
|
const UnistylesImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
|
16
|
-
let storedRef: NativeImageBackground | null = null
|
17
|
-
let storedImageRef: NativeImageBackground | null = null
|
18
17
|
const styleClassNames = getClassName(props.style)
|
19
18
|
const imageClassNames = getClassName(props.imageStyle)
|
19
|
+
const ref = createUnistylesRef(styleClassNames, forwardedRef)
|
20
|
+
const imageRef = createUnistylesRef(imageClassNames)
|
21
|
+
const hasWidthStyle = typeof props.imageStyle === 'object' && keyInObject(props.imageStyle, 'width')
|
22
|
+
const hasHeightStyle = typeof props.imageStyle === 'object' && keyInObject(props.imageStyle, 'height')
|
23
|
+
|
24
|
+
maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, 'ImageBackground')
|
25
|
+
maybeWarnAboutMultipleUnistyles(props.imageStyle as ViewStyle, 'ImageBackground')
|
20
26
|
|
21
27
|
return (
|
22
28
|
<NativeImageBackground
|
23
29
|
{...props}
|
24
30
|
style={styleClassNames as StyleProp<ViewStyle>}
|
25
|
-
imageStyle={
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// @ts-expect-error hidden from TS
|
34
|
-
UnistylesShadowRegistry.add(ref, styleClassNames?.hash)
|
35
|
-
|
36
|
-
if (typeof forwardedRef === 'function') {
|
37
|
-
return forwardedRef(ref)
|
38
|
-
}
|
39
|
-
|
40
|
-
if (forwardedRef) {
|
41
|
-
forwardedRef.current = ref
|
42
|
-
}
|
43
|
-
}}
|
44
|
-
imageRef={isServer() ? undefined : ref => {
|
45
|
-
if (!ref) {
|
46
|
-
// @ts-expect-error hidden from TS
|
47
|
-
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
|
48
|
-
}
|
49
|
-
|
50
|
-
storedImageRef = ref
|
51
|
-
// @ts-expect-error hidden from TS
|
52
|
-
UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
|
53
|
-
}}
|
31
|
+
imageStyle={[
|
32
|
+
imageClassNames,
|
33
|
+
// Clear inline width and height extracted from source
|
34
|
+
hasWidthStyle && { width: '' },
|
35
|
+
hasHeightStyle && { height: '' }
|
36
|
+
] as StyleProp<ImageStyle>}
|
37
|
+
ref={ref}
|
38
|
+
imageRef={imageRef}
|
54
39
|
/>
|
55
40
|
)
|
56
41
|
})
|
@@ -50,10 +50,18 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
50
50
|
storedRef.current = ref
|
51
51
|
}
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
return passForwardedRef(
|
54
|
+
ref,
|
55
|
+
forwardedRef,
|
56
|
+
() => {
|
57
|
+
// @ts-expect-error - this is hidden from TS
|
58
|
+
UnistylesShadowRegistry.add(ref, unistyles)
|
59
|
+
},
|
60
|
+
() => {
|
61
|
+
// @ts-expect-error - this is hidden from TS
|
62
|
+
UnistylesShadowRegistry.remove(ref)
|
63
|
+
}
|
64
|
+
)
|
57
65
|
}}
|
58
66
|
style={state => {
|
59
67
|
const isPropStyleAFunction = typeof style === 'function'
|
@@ -38,15 +38,21 @@ export const createUnistylesElement = (Component: any) => {
|
|
38
38
|
storedRef.current = getNativeRef(Component, ref)
|
39
39
|
}
|
40
40
|
|
41
|
-
passForwardedRef(props, ref, forwardedRef)
|
42
|
-
|
43
41
|
// @ts-ignore we don't know the type of the component
|
44
42
|
maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
|
45
43
|
|
46
|
-
return (
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
return passForwardedRef(
|
45
|
+
ref,
|
46
|
+
forwardedRef,
|
47
|
+
() => {
|
48
|
+
// @ts-ignore this is hidden from TS
|
49
|
+
UnistylesShadowRegistry.add(ref, props.style)
|
50
|
+
},
|
51
|
+
() => {
|
52
|
+
// @ts-ignore this is hidden from TS
|
53
|
+
UnistylesShadowRegistry.remove(ref)
|
54
|
+
}
|
55
|
+
)
|
50
56
|
}}
|
51
57
|
/>
|
52
58
|
)
|