react-native-unistyles 3.0.0-beta.8 → 3.0.0-experimental-2025051401
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 +35 -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
@@ -1,45 +1,44 @@
|
|
1
1
|
import React from 'react'
|
2
|
+
import type { ViewStyle } from 'react-native'
|
2
3
|
import type { UnistylesValues } from '../types'
|
3
4
|
import { copyComponentProperties } from '../utils'
|
4
|
-
import { UnistylesShadowRegistry } from '../web'
|
5
5
|
import { isServer } from '../web/utils'
|
6
|
+
import { createUnistylesRef } from '../web/utils/createUnistylesRef'
|
6
7
|
import { getClassName } from './getClassname'
|
7
8
|
import { maybeWarnAboutMultipleUnistyles } from './warn'
|
8
9
|
|
10
|
+
const STYLE_PROPS = ['style', 'contentContainerStyle', 'columnWrapperStyle'] as const
|
11
|
+
|
9
12
|
type ComponentProps = {
|
10
|
-
|
13
|
+
[K in typeof STYLE_PROPS[number]]?: UnistylesValues
|
14
|
+
}
|
15
|
+
|
16
|
+
const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef: React.ForwardedRef<unknown>) => {
|
17
|
+
const componentStyleProps = STYLE_PROPS.filter(styleProp => styleProp in props)
|
18
|
+
const classNames = Object.fromEntries(componentStyleProps.map(styleProp => [styleProp, getClassName(props[styleProp])]))
|
19
|
+
const refs = componentStyleProps.map(styleProp => {
|
20
|
+
return createUnistylesRef(
|
21
|
+
classNames[styleProp],
|
22
|
+
styleProp === 'style' ? forwardedRef : undefined
|
23
|
+
)
|
24
|
+
})
|
25
|
+
|
26
|
+
componentStyleProps.forEach(styleProp => {
|
27
|
+
maybeWarnAboutMultipleUnistyles(props[styleProp] as ViewStyle, Component.displayName)
|
28
|
+
})
|
29
|
+
|
30
|
+
return {
|
31
|
+
...classNames,
|
32
|
+
ref: isServer() ? undefined : (componentRef: any) => refs.forEach(ref => ref?.(componentRef))
|
33
|
+
}
|
11
34
|
}
|
12
35
|
|
13
36
|
export const createUnistylesElement = (Component: any) => {
|
14
37
|
const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
|
15
|
-
let storedRef: HTMLElement | null = null
|
16
|
-
const classNames = getClassName(props.style)
|
17
|
-
|
18
38
|
return (
|
19
39
|
<Component
|
20
40
|
{...props}
|
21
|
-
|
22
|
-
ref={isServer() ? undefined : (ref: HTMLElement | null) => {
|
23
|
-
// @ts-ignore we don't know the type of the component
|
24
|
-
maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
|
25
|
-
|
26
|
-
if (!ref) {
|
27
|
-
// @ts-expect-error hidden from TS
|
28
|
-
UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
|
29
|
-
}
|
30
|
-
|
31
|
-
storedRef = ref
|
32
|
-
// @ts-expect-error hidden from TS
|
33
|
-
UnistylesShadowRegistry.add(ref, classNames?.hash)
|
34
|
-
|
35
|
-
if (typeof forwardedRef === 'function') {
|
36
|
-
return forwardedRef(ref)
|
37
|
-
}
|
38
|
-
|
39
|
-
if (forwardedRef) {
|
40
|
-
forwardedRef.current = ref
|
41
|
-
}
|
42
|
-
}}
|
41
|
+
{...buildUnistylesProps(Component, props, forwardedRef)}
|
43
42
|
/>
|
44
43
|
)
|
45
44
|
})
|
@@ -27,17 +27,23 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
|
|
27
27
|
<Component
|
28
28
|
{...props}
|
29
29
|
ref={ref => {
|
30
|
-
passForwardedRef(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
return passForwardedRef(
|
31
|
+
ref,
|
32
|
+
forwardedRef,
|
33
|
+
() => {
|
34
|
+
// @ts-expect-error - this is hidden from TS
|
35
|
+
UnistylesShadowRegistry.add(ref, props.style)
|
36
|
+
},
|
37
|
+
() => {
|
38
|
+
// @ts-expect-error - this is hidden from TS
|
39
|
+
UnistylesShadowRegistry.remove(ref)
|
40
|
+
|
41
|
+
if (storedImageRef.current) {
|
42
|
+
// @ts-expect-error - this is hidden from TS
|
43
|
+
UnistylesShadowRegistry.remove(storedImageRef.current)
|
44
|
+
}
|
39
45
|
}
|
40
|
-
|
46
|
+
)
|
41
47
|
}}
|
42
48
|
imageRef={ref => {
|
43
49
|
if (ref) {
|
package/src/core/getClassname.ts
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
import type { UnistylesValues } from '../types'
|
2
|
-
import
|
2
|
+
import * as unistyles from '../web/services'
|
3
|
+
import { checkForAnimated } from '../web/utils'
|
3
4
|
|
4
|
-
export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues
|
5
|
+
export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>, forChild?: boolean) => {
|
5
6
|
if (!unistyle) {
|
6
7
|
return undefined
|
7
8
|
}
|
8
9
|
|
9
|
-
const
|
10
|
-
|
10
|
+
const flattenedStyles = Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
|
11
|
+
const animatedStyles = flattenedStyles.filter(checkForAnimated)
|
12
|
+
const regularStyles = flattenedStyles.filter(style => !checkForAnimated(style))
|
13
|
+
|
14
|
+
const { hash, injectedClassName } = unistyles.services.shadowRegistry.addStyles(
|
15
|
+
regularStyles,
|
16
|
+
forChild
|
11
17
|
)
|
12
18
|
|
13
|
-
return hash
|
19
|
+
return hash
|
20
|
+
? [
|
21
|
+
{ $$css: true, hash, injectedClassName },
|
22
|
+
animatedStyles,
|
23
|
+
] as const
|
24
|
+
: undefined
|
14
25
|
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import React from 'react'
|
2
|
-
import { UnistylesShadowRegistry } from '../specs'
|
3
2
|
|
4
3
|
export const passForwardedRef = <T>(
|
5
|
-
props: any,
|
6
4
|
ref: T,
|
7
|
-
forwardedRef: React.ForwardedRef<T
|
5
|
+
forwardedRef: React.ForwardedRef<T>,
|
6
|
+
onMount?: () => void,
|
7
|
+
onUnmount?: () => void
|
8
8
|
) => {
|
9
9
|
const passForwardedRef = () => {
|
10
10
|
if (typeof forwardedRef === 'function') {
|
@@ -19,10 +19,10 @@ export const passForwardedRef = <T>(
|
|
19
19
|
}
|
20
20
|
const forwardedRefReturnFn = passForwardedRef()
|
21
21
|
|
22
|
-
|
23
|
-
UnistylesShadowRegistry.add(ref, props.style)
|
22
|
+
onMount?.()
|
24
23
|
|
25
24
|
return () => {
|
26
25
|
forwardedRefReturnFn?.()
|
26
|
+
onUnmount?.()
|
27
27
|
}
|
28
28
|
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { UnistyleDependency } from '../../specs'
|
2
|
-
import
|
2
|
+
import * as unistyles from '../../web/services'
|
3
3
|
import type { ListenerProps } from './types'
|
4
4
|
|
5
5
|
export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
|
6
|
-
const disposeTheme =
|
7
|
-
const disposeRuntime =
|
6
|
+
const disposeTheme = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
|
7
|
+
const disposeRuntime = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
|
8
8
|
|
9
9
|
return () => {
|
10
10
|
disposeTheme()
|
@@ -24,6 +24,7 @@ const RTDependencyMap = {
|
|
24
24
|
statusBar: UnistyleDependency.StatusBar,
|
25
25
|
pixelRatio: UnistyleDependency.PixelRatio,
|
26
26
|
themeName: UnistyleDependency.ThemeName,
|
27
|
+
rtl: UnistyleDependency.Rtl
|
27
28
|
} satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
|
28
29
|
|
29
30
|
export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
@@ -63,6 +64,22 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
63
64
|
})
|
64
65
|
const proxifiedRuntime = new Proxy(getMiniRuntime(), {
|
65
66
|
get: (target, prop) => {
|
67
|
+
if (prop === 'insets') {
|
68
|
+
return new Proxy(target.insets, {
|
69
|
+
get: (target, prop) => {
|
70
|
+
if (prop === 'ime') {
|
71
|
+
dependencies.add(UnistyleDependency.Ime)
|
72
|
+
|
73
|
+
return target[prop as keyof typeof target]
|
74
|
+
}
|
75
|
+
|
76
|
+
dependencies.add(UnistyleDependency.Insets)
|
77
|
+
|
78
|
+
return target[prop as keyof typeof target]
|
79
|
+
}
|
80
|
+
})
|
81
|
+
}
|
82
|
+
|
66
83
|
if (prop in RTDependencyMap) {
|
67
84
|
dependencies.add(RTDependencyMap[prop as keyof typeof RTDependencyMap])
|
68
85
|
}
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import React, { forwardRef, useEffect, type ComponentType, useRef } from 'react'
|
2
2
|
import { type UnistyleDependency, UnistylesShadowRegistry } from '../../specs'
|
3
3
|
import type { UnistylesTheme } from '../../types'
|
4
|
-
import type { PartialBy } from '../../types/common'
|
5
4
|
import { deepMergeObjects } from '../../utils'
|
6
5
|
import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
|
7
6
|
import { maybeWarnAboutMultipleUnistyles } from '../warn'
|
8
|
-
import type { Mappings
|
7
|
+
import type { Mappings } from './types'
|
9
8
|
|
10
9
|
// @ts-expect-error
|
11
10
|
type GenericComponentProps<P> = ComponentProps<P>
|
@@ -24,7 +23,7 @@ type MappedSecrets = {
|
|
24
23
|
|
25
24
|
export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
|
26
25
|
type TProps = GenericComponentProps<TComponent>
|
27
|
-
type PropsWithUnistyles =
|
26
|
+
type PropsWithUnistyles = Partial<TProps> & {
|
28
27
|
uniProps?: Mappings<TProps>
|
29
28
|
}
|
30
29
|
const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
|
@@ -43,7 +42,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
43
42
|
unistyleKey
|
44
43
|
? style[unistyleKey]
|
45
44
|
: {
|
46
|
-
uni__getStyles: () =>
|
45
|
+
uni__getStyles: () => style,
|
47
46
|
uni__dependencies: [],
|
48
47
|
}
|
49
48
|
])
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import React, { type ComponentType, forwardRef, type ComponentProps, type ComponentRef } from 'react'
|
2
2
|
import type { UnistylesValues } from '../../types'
|
3
|
-
import type { PartialBy } from '../../types/common'
|
4
3
|
import { deepMergeObjects } from '../../utils'
|
5
4
|
import { getClassName } from '../getClassname'
|
6
5
|
import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
|
7
6
|
import { maybeWarnAboutMultipleUnistyles } from '../warn'
|
8
|
-
import type { Mappings
|
7
|
+
import type { Mappings } from './types'
|
9
8
|
|
10
9
|
// @ts-expect-error
|
11
10
|
type GenericComponentProps<T> = ComponentProps<T>
|
@@ -14,7 +13,7 @@ type GenericComponentRef<T> = ComponentRef<T>
|
|
14
13
|
|
15
14
|
export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
|
16
15
|
type TProps = GenericComponentProps<TComponent>
|
17
|
-
type PropsWithUnistyles =
|
16
|
+
type PropsWithUnistyles = Partial<TProps> & {
|
18
17
|
uniProps?: Mappings<TProps>
|
19
18
|
}
|
20
19
|
type UnistyleStyles = {
|
@@ -24,17 +23,27 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
24
23
|
|
25
24
|
return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
|
26
25
|
const narrowedProps = props as PropsWithUnistyles & UnistyleStyles
|
27
|
-
const styleClassNames = getClassName(narrowedProps.style)
|
26
|
+
const styleClassNames = getClassName(narrowedProps.style, true)
|
28
27
|
const contentContainerStyleClassNames = getClassName(narrowedProps.contentContainerStyle)
|
29
28
|
const { proxifiedRuntime, proxifiedTheme } = useProxifiedUnistyles()
|
30
29
|
|
31
30
|
const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
|
32
31
|
const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
|
33
32
|
|
33
|
+
|
34
|
+
const emptyStyles = narrowedProps.style
|
35
|
+
? Object.fromEntries(
|
36
|
+
Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
|
37
|
+
.filter(([key]) => !key.startsWith("unistyles") && !key.startsWith("_"))
|
38
|
+
.map(([key]) => [key, undefined])
|
39
|
+
)
|
40
|
+
: undefined
|
41
|
+
|
34
42
|
const combinedProps = {
|
35
43
|
...deepMergeObjects(mappingsProps, unistyleProps, props),
|
36
44
|
...narrowedProps.style ? {
|
37
|
-
|
45
|
+
// Override default component styles with undefined values to reset them
|
46
|
+
style: emptyStyles
|
38
47
|
} : {},
|
39
48
|
...narrowedProps.contentContainerStyle ? {
|
40
49
|
contentContainerStyle: contentContainerStyleClassNames,
|
@@ -47,7 +56,15 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
47
56
|
maybeWarnAboutMultipleUnistyles(narrowedProps.contentContainerStyle, `withUnistyles(${Component.displayName ?? Component.name ?? 'Unknown'})`)
|
48
57
|
|
49
58
|
const NativeComponent = Component as ComponentType
|
59
|
+
const [classNames] = styleClassNames ?? []
|
50
60
|
|
51
|
-
return
|
61
|
+
return (
|
62
|
+
<div
|
63
|
+
className={classNames?.hash}
|
64
|
+
style={{ display: 'contents' }}
|
65
|
+
>
|
66
|
+
<NativeComponent {...combinedProps} ref={ref} />
|
67
|
+
</div>
|
68
|
+
)
|
52
69
|
})
|
53
70
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { useEffect, useLayoutEffect, useState } from 'react'
|
2
|
-
import { isUnistylesMq, isValidMq, parseMq } from '../mq'
|
3
2
|
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
|
3
|
+
import { isUnistylesMq, isValidMq, parseMq } from '../utils'
|
4
4
|
|
5
5
|
export const useMedia = (config: { mq: symbol }) => {
|
6
6
|
const computeIsVisible = (): boolean => {
|
package/src/hooks/useMedia.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
2
|
-
import { isUnistylesMq, isValidMq, parseMq } from '../
|
2
|
+
import { isUnistylesMq, isValidMq, parseMq } from '../utils'
|
3
3
|
|
4
4
|
export const useMedia = (config: { mq: symbol }) => {
|
5
5
|
const disposeRef = useRef(() => {})
|
package/src/mocks.ts
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
import type { UnistylesBreakpoints, UnistylesThemes } from './global'
|
2
|
+
import type { UnistylesNavigationBar } from './specs/NavigtionBar'
|
3
|
+
import type { UnistylesStatusBar } from './specs/StatusBar'
|
4
|
+
import type { UnistylesConfig, UnistylesStyleSheet } from './specs/StyleSheet'
|
5
|
+
import type { UnistylesRuntimePrivate } from './specs/UnistylesRuntime'
|
6
|
+
import type { ColorScheme, Orientation } from './specs/types'
|
7
|
+
import type { IOSContentSizeCategory, UnistylesTheme } from './types'
|
8
|
+
|
9
|
+
type Registry = {
|
10
|
+
themes: UnistylesThemes
|
11
|
+
breakpoints: UnistylesBreakpoints
|
12
|
+
}
|
13
|
+
|
14
|
+
jest.mock('react-native-nitro-modules', () => ({
|
15
|
+
NitroModules: {
|
16
|
+
createHybridObject: () => ({
|
17
|
+
add: () => {},
|
18
|
+
init: () => {},
|
19
|
+
createHybridStatusBar: () => ({
|
20
|
+
setStyle: () => {},
|
21
|
+
}),
|
22
|
+
createHybridNavigationBar: () => {},
|
23
|
+
})
|
24
|
+
}
|
25
|
+
}))
|
26
|
+
|
27
|
+
jest.mock('react-native-unistyles', () => {
|
28
|
+
const React = require('react')
|
29
|
+
const _REGISTRY: Registry = {
|
30
|
+
themes: {},
|
31
|
+
breakpoints: {}
|
32
|
+
}
|
33
|
+
const miniRuntime = {
|
34
|
+
themeName: undefined,
|
35
|
+
breakpoint: undefined,
|
36
|
+
hasAdaptiveThemes: false,
|
37
|
+
colorScheme: 'unspecified' as ColorScheme,
|
38
|
+
contentSizeCategory: 'Medium' as IOSContentSizeCategory,
|
39
|
+
insets: {
|
40
|
+
top: 0,
|
41
|
+
left: 0,
|
42
|
+
right: 0,
|
43
|
+
bottom: 0,
|
44
|
+
ime: 0
|
45
|
+
},
|
46
|
+
pixelRatio: 1,
|
47
|
+
fontScale: 1,
|
48
|
+
rtl: false,
|
49
|
+
isLandscape: false,
|
50
|
+
isPortrait: true,
|
51
|
+
navigationBar: {
|
52
|
+
width: 0,
|
53
|
+
height: 0
|
54
|
+
},
|
55
|
+
screen: {
|
56
|
+
width: 0,
|
57
|
+
height: 0
|
58
|
+
},
|
59
|
+
statusBar: {
|
60
|
+
width: 0,
|
61
|
+
height: 0
|
62
|
+
}
|
63
|
+
}
|
64
|
+
const unistylesRuntime = {
|
65
|
+
colorScheme: 'unspecified' as ColorScheme,
|
66
|
+
contentSizeCategory: 'Medium' as IOSContentSizeCategory,
|
67
|
+
orientation: 'portrait' as Orientation,
|
68
|
+
breakpoints: {},
|
69
|
+
dispose: () => { },
|
70
|
+
equals: () => false,
|
71
|
+
name: 'UnistylesRuntimeMock',
|
72
|
+
miniRuntime: miniRuntime,
|
73
|
+
statusBar: {
|
74
|
+
height: 0,
|
75
|
+
width: 0,
|
76
|
+
name: 'StatusBarMock',
|
77
|
+
equals: () => false,
|
78
|
+
setHidden: () => { },
|
79
|
+
setStyle: () => { }
|
80
|
+
},
|
81
|
+
navigationBar: {
|
82
|
+
height: 0,
|
83
|
+
width: 0,
|
84
|
+
name: 'NavigationBarMock',
|
85
|
+
equals: () => false,
|
86
|
+
setHidden: () => { },
|
87
|
+
dispose: () => { }
|
88
|
+
},
|
89
|
+
fontScale: 1,
|
90
|
+
hasAdaptiveThemes: false,
|
91
|
+
pixelRatio: 0,
|
92
|
+
rtl: false,
|
93
|
+
getTheme: () => {
|
94
|
+
return {} as UnistylesTheme
|
95
|
+
},
|
96
|
+
setTheme: () => {},
|
97
|
+
updateTheme: () => {},
|
98
|
+
setRootViewBackgroundColor: () => {},
|
99
|
+
_setRootViewBackgroundColor: () => {},
|
100
|
+
createHybridStatusBar: () => {
|
101
|
+
return {} as UnistylesStatusBar
|
102
|
+
},
|
103
|
+
createHybridNavigationBar: () => {
|
104
|
+
return {} as UnistylesNavigationBar
|
105
|
+
},
|
106
|
+
setAdaptiveThemes: () => {},
|
107
|
+
setImmersiveMode: () => {},
|
108
|
+
insets: {
|
109
|
+
top: 0,
|
110
|
+
left: 0,
|
111
|
+
right: 0,
|
112
|
+
bottom: 0,
|
113
|
+
ime: 0
|
114
|
+
},
|
115
|
+
screen: {
|
116
|
+
width: 0,
|
117
|
+
height: 0
|
118
|
+
},
|
119
|
+
breakpoint: undefined
|
120
|
+
} satisfies UnistylesRuntimePrivate
|
121
|
+
|
122
|
+
return {
|
123
|
+
Hide: () => null,
|
124
|
+
Display: () => null,
|
125
|
+
ScopedTheme: () => null,
|
126
|
+
withUnistyles: <TComponent,>(Component: TComponent, mapper?: (theme: UnistylesTheme, runtime: typeof miniRuntime) => TComponent) => (props: any) =>
|
127
|
+
React.createElement(Component, {
|
128
|
+
...mapper?.((Object.values(_REGISTRY.themes).at(0) ?? {}) as UnistylesTheme, miniRuntime),
|
129
|
+
...props
|
130
|
+
}),
|
131
|
+
mq: {
|
132
|
+
only: {
|
133
|
+
width: () => ({
|
134
|
+
and: {
|
135
|
+
height: () => ({})
|
136
|
+
}
|
137
|
+
}),
|
138
|
+
height: () => ({
|
139
|
+
and: {
|
140
|
+
width: () => ({})
|
141
|
+
}
|
142
|
+
})
|
143
|
+
},
|
144
|
+
width: () => ({
|
145
|
+
and: {
|
146
|
+
height: () => ({})
|
147
|
+
}
|
148
|
+
}),
|
149
|
+
height: () => ({
|
150
|
+
and: {
|
151
|
+
width: () => ({})
|
152
|
+
}
|
153
|
+
})
|
154
|
+
},
|
155
|
+
useUnistyles: () => ({
|
156
|
+
theme: Object.values(_REGISTRY.themes).at(0) ?? {},
|
157
|
+
rt: unistylesRuntime
|
158
|
+
}),
|
159
|
+
StyleSheet: {
|
160
|
+
absoluteFillObject: {
|
161
|
+
position: 'absolute',
|
162
|
+
left: 0,
|
163
|
+
right: 0,
|
164
|
+
top: 0,
|
165
|
+
bottom: 0
|
166
|
+
},
|
167
|
+
absoluteFill: {
|
168
|
+
position: 'absolute',
|
169
|
+
left: 0,
|
170
|
+
right: 0,
|
171
|
+
top: 0,
|
172
|
+
bottom: 0
|
173
|
+
} as unknown as UnistylesStyleSheet['absoluteFill'],
|
174
|
+
compose: (styles: any) => {
|
175
|
+
return styles
|
176
|
+
},
|
177
|
+
flatten: (styles: any) => {
|
178
|
+
return styles
|
179
|
+
},
|
180
|
+
create: (styles: any) => {
|
181
|
+
if (typeof styles === 'function') {
|
182
|
+
return {
|
183
|
+
...styles(Object.values(_REGISTRY.themes).at(0) ?? {}, miniRuntime),
|
184
|
+
useVariants: () => {}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
return {
|
189
|
+
...styles,
|
190
|
+
useVariants: () => {}
|
191
|
+
}
|
192
|
+
},
|
193
|
+
configure: (config: UnistylesConfig) => {
|
194
|
+
if (config.breakpoints) {
|
195
|
+
_REGISTRY.breakpoints = config.breakpoints
|
196
|
+
}
|
197
|
+
|
198
|
+
if (config.themes) {
|
199
|
+
_REGISTRY.themes = config.themes
|
200
|
+
}
|
201
|
+
},
|
202
|
+
jsMethods: {
|
203
|
+
processColor: () => null
|
204
|
+
},
|
205
|
+
hairlineWidth: 1,
|
206
|
+
unid: -1,
|
207
|
+
addChangeListener: () => () => {},
|
208
|
+
init: () => {},
|
209
|
+
name: 'StyleSheetMock',
|
210
|
+
dispose: () => {},
|
211
|
+
equals: () => false
|
212
|
+
} satisfies UnistylesStyleSheet,
|
213
|
+
UnistylesRuntime: unistylesRuntime
|
214
|
+
}
|
215
|
+
})
|
216
|
+
|
217
|
+
|
package/src/mq.ts
CHANGED
@@ -2,10 +2,6 @@ import type { UnistylesBreakpoints } from './global'
|
|
2
2
|
import { UnistylesRuntime } from './specs'
|
3
3
|
import type { Nullable } from './types'
|
4
4
|
|
5
|
-
const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
6
|
-
const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
7
|
-
const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
|
8
|
-
|
9
5
|
type MQValue = keyof UnistylesBreakpoints | number
|
10
6
|
|
11
7
|
type MQHandler = {
|
@@ -62,23 +58,3 @@ export const mq: MQHandler = {
|
|
62
58
|
})
|
63
59
|
}
|
64
60
|
|
65
|
-
export const parseMq = (mq: string) => {
|
66
|
-
const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
|
67
|
-
const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
|
68
|
-
|
69
|
-
return {
|
70
|
-
minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
|
71
|
-
maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
|
72
|
-
minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
|
73
|
-
maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
|
78
|
-
|
79
|
-
export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
|
80
|
-
const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
|
81
|
-
const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
|
82
|
-
|
83
|
-
return isWidthValid && isHeightValid
|
84
|
-
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { useAnimatedTheme } from './useAnimatedTheme'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { useEffect } from 'react'
|
2
|
+
import { type SharedValue, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
|
4
|
+
import type { UnistylesTheme } from '../types'
|
5
|
+
|
6
|
+
export const useAnimatedTheme = () => {
|
7
|
+
const theme = useSharedValue(UnistylesRuntime.getTheme())
|
8
|
+
|
9
|
+
useEffect(() => {
|
10
|
+
// @ts-ignore this is hidden from TS
|
11
|
+
const dispose = StyleSheet.addChangeListener(changedDependencies => {
|
12
|
+
if (changedDependencies.includes(UnistyleDependency.Theme)) {
|
13
|
+
theme.set(UnistylesRuntime.getTheme())
|
14
|
+
}
|
15
|
+
})
|
16
|
+
|
17
|
+
return () => dispose()
|
18
|
+
}, [])
|
19
|
+
|
20
|
+
return theme as SharedValue<UnistylesTheme>
|
21
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { useEffect } from 'react'
|
2
|
+
import { type SharedValue, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { UnistyleDependency, UnistylesRuntime } from '../specs'
|
4
|
+
import type { UnistylesTheme } from '../types'
|
5
|
+
import { services } from '../web/services'
|
6
|
+
|
7
|
+
export const useAnimatedTheme = () => {
|
8
|
+
const theme = useSharedValue(UnistylesRuntime.getTheme())
|
9
|
+
|
10
|
+
useEffect(() => {
|
11
|
+
const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => theme.set(UnistylesRuntime.getTheme()))
|
12
|
+
|
13
|
+
return () => {
|
14
|
+
dispose()
|
15
|
+
}
|
16
|
+
}, [])
|
17
|
+
|
18
|
+
return theme as SharedValue<UnistylesTheme>
|
19
|
+
}
|
@@ -1,21 +1,26 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import { StyleSheet } from 'react-native'
|
3
|
-
import
|
3
|
+
import * as unistyles from '../web/services'
|
4
4
|
import { error, isServer } from '../web/utils'
|
5
|
+
import { serialize } from './serialize'
|
5
6
|
import { DefaultServerUnistylesSettings, type ServerUnistylesSettings } from './types'
|
6
7
|
|
7
8
|
export const getServerUnistyles = ({ includeRNWStyles = true }: ServerUnistylesSettings = DefaultServerUnistylesSettings) => {
|
8
9
|
if (!isServer()) {
|
9
10
|
throw error('Server styles should only be read on the server')
|
10
11
|
}
|
12
|
+
|
11
13
|
// @ts-ignore
|
12
14
|
const rnwStyle: string | null = includeRNWStyles ? (StyleSheet?.getSheet().textContent ?? '') : null
|
13
|
-
const css =
|
14
|
-
const state =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
15
|
+
const css = unistyles.services.registry.css.getStyles()
|
16
|
+
const state = unistyles.services.registry.css.getState()
|
17
|
+
|
18
|
+
return (
|
19
|
+
<>
|
20
|
+
{rnwStyle && <style id='rnw-style'>{rnwStyle}</style>}
|
21
|
+
<style id='unistyles-web'>{css}</style>
|
22
|
+
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: Needs the json quotes to be unescaped */}
|
23
|
+
<script id='unistyles-script' defer dangerouslySetInnerHTML={{ __html: `window.__UNISTYLES_STATE__ = ${serialize(state)}`}} />
|
24
|
+
</>
|
25
|
+
)
|
26
|
+
}
|