react-native-unistyles 3.0.0-beta.7 → 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 +41 -19
- package/Unistyles.podspec +1 -0
- package/android/CMakeLists.txt +2 -1
- 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 +11 -4
- 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 +89 -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 +74 -69
- package/cxx/core/UnistylesRegistry.h +1 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
- package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
- package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
- package/cxx/parser/Parser.cpp +200 -89
- package/cxx/parser/Parser.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +13 -9
- package/cxx/shadowTree/ShadowTreeManager.cpp +64 -59
- 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 +21 -36
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +16 -2
- 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 +7 -1
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +10 -4
- 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 +15 -2
- 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 +14 -7
- 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 +22 -37
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +16 -2
- 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 +7 -1
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +10 -4
- 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 +15 -2
- 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 +14 -7
- 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/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 +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++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +22 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
- package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
- package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -0
- package/nitrogen/generated/shared/c++/Insets.hpp +1 -0
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -0
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -0
- package/package.json +77 -33
- package/plugin/index.d.ts +51 -18
- package/plugin/index.js +878 -177
- 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 +20 -36
- package/src/components/native/Pressable.native.tsx +25 -2
- package/src/core/createUnistylesElement.native.tsx +13 -2
- package/src/core/createUnistylesElement.tsx +26 -27
- package/src/core/createUnistylesImageBackground.tsx +16 -5
- 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 +18 -1
- package/src/core/withUnistyles/withUnistyles.native.tsx +42 -17
- 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 +2 -2
- package/src/types/common.ts +0 -1
- package/src/types/stylesheet.ts +1 -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 -49
- package/cxx/core/UnistylesCommitHook.h +0 -27
- package/cxx/core/UnistylesMountHook.cpp +0 -28
- package/cxx/core/UnistylesMountHook.h +0 -27
- package/lib/module/package.json +0 -1
- package/plugin/consts.js +0 -63
- package/plugin/exotic.js +0 -54
- package/plugin/import.js +0 -51
- package/plugin/ref.js +0 -11
- package/plugin/stylesheet.js +0 -565
- package/plugin/variants.js +0 -66
- /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
@@ -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)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import { forwardRef } from 'react'
|
3
|
-
import { ImageBackground as NativeImageBackground } from 'react-native'
|
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,45 +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
|
-
// @ts-expect-error - RN types are not compatible with RNW styles
|
23
28
|
<NativeImageBackground
|
24
29
|
{...props}
|
25
|
-
style={styleClassNames}
|
26
|
-
imageStyle={
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
// @ts-expect-error hidden from TS
|
35
|
-
UnistylesShadowRegistry.add(ref, styleClassNames?.hash)
|
36
|
-
|
37
|
-
if (typeof forwardedRef === 'function') {
|
38
|
-
return forwardedRef(ref)
|
39
|
-
}
|
40
|
-
|
41
|
-
if (forwardedRef) {
|
42
|
-
forwardedRef.current = ref
|
43
|
-
}
|
44
|
-
}}
|
45
|
-
imageRef={isServer() ? undefined : ref => {
|
46
|
-
if (!ref) {
|
47
|
-
// @ts-expect-error hidden from TS
|
48
|
-
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
|
49
|
-
}
|
50
|
-
|
51
|
-
storedImageRef = ref
|
52
|
-
// @ts-expect-error hidden from TS
|
53
|
-
UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
|
54
|
-
}}
|
30
|
+
style={styleClassNames as StyleProp<ViewStyle>}
|
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}
|
55
39
|
/>
|
56
40
|
)
|
57
41
|
})
|
@@ -25,7 +25,8 @@ const getStyles = (styleProps: Record<string, any> = {}) => {
|
|
25
25
|
}
|
26
26
|
|
27
27
|
export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, forwardedRef) => {
|
28
|
-
const storedRef = useRef<View | null>()
|
28
|
+
const storedRef = useRef<View | null>(null)
|
29
|
+
const scopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
29
30
|
|
30
31
|
useLayoutEffect(() => {
|
31
32
|
return () => {
|
@@ -40,14 +41,34 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
40
41
|
<NativePressableReactNative
|
41
42
|
{...props}
|
42
43
|
ref={ref => {
|
44
|
+
const isPropStyleAFunction = typeof style === 'function'
|
45
|
+
const unistyles = isPropStyleAFunction
|
46
|
+
? style.call(style, { pressed: false })
|
47
|
+
: getStyles(style as unknown as Record<string, any>)
|
48
|
+
|
43
49
|
if (ref) {
|
44
50
|
storedRef.current = ref
|
45
51
|
}
|
46
52
|
|
47
|
-
return passForwardedRef(
|
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
|
+
)
|
48
65
|
}}
|
49
66
|
style={state => {
|
50
67
|
const isPropStyleAFunction = typeof style === 'function'
|
68
|
+
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
69
|
+
|
70
|
+
UnistylesShadowRegistry.setScopedTheme(scopedTheme)
|
71
|
+
|
51
72
|
const unistyles = isPropStyleAFunction
|
52
73
|
? style.call(style, state)
|
53
74
|
: getStyles(style as unknown as Record<string, any>)
|
@@ -62,6 +83,8 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
62
83
|
// @ts-expect-error - this is hidden from TS
|
63
84
|
UnistylesShadowRegistry.add(storedRef.current, unistyles)
|
64
85
|
|
86
|
+
UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
|
87
|
+
|
65
88
|
return unistyles
|
66
89
|
}}
|
67
90
|
/>
|
@@ -38,10 +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)
|
43
|
+
|
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
|
+
)
|
45
56
|
}}
|
46
57
|
/>
|
47
58
|
)
|
@@ -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,12 +27,23 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
|
|
27
27
|
<Component
|
28
28
|
{...props}
|
29
29
|
ref={ref => {
|
30
|
-
passForwardedRef(
|
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)
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
41
|
+
if (storedImageRef.current) {
|
42
|
+
// @ts-expect-error - this is hidden from TS
|
43
|
+
UnistylesShadowRegistry.remove(storedImageRef.current)
|
44
|
+
}
|
45
|
+
}
|
46
|
+
)
|
36
47
|
}}
|
37
48
|
imageRef={ref => {
|
38
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) => {
|
@@ -31,7 +32,7 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
31
32
|
const [dependencies] = useState(() => new Set<number>())
|
32
33
|
const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme))
|
33
34
|
const [_, runtimeChanged] = useReducer(() => ({}), {})
|
34
|
-
const disposeRef = useRef<VoidFunction>()
|
35
|
+
const disposeRef = useRef<VoidFunction>(undefined)
|
35
36
|
|
36
37
|
const reinitListener = () => {
|
37
38
|
disposeRef.current?.()
|
@@ -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,33 +1,58 @@
|
|
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>
|
12
11
|
// @ts-expect-error
|
13
12
|
type GenericComponentRef<T> = ComponentRef<T>
|
14
13
|
|
14
|
+
type UnistylesSecrets = {
|
15
|
+
uni__getStyles: () => Record<string, any>,
|
16
|
+
uni__dependencies: Array<UnistyleDependency>
|
17
|
+
}
|
18
|
+
|
19
|
+
type MappedSecrets = {
|
20
|
+
styles: Record<string, any>,
|
21
|
+
dependencies: Array<UnistyleDependency>
|
22
|
+
}
|
23
|
+
|
15
24
|
export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
|
16
25
|
type TProps = GenericComponentProps<TComponent>
|
17
|
-
type PropsWithUnistyles =
|
26
|
+
type PropsWithUnistyles = Partial<TProps> & {
|
18
27
|
uniProps?: Mappings<TProps>
|
19
28
|
}
|
20
|
-
const getSecrets = (styleProps: Record<string, any> = {}):
|
21
|
-
const
|
22
|
-
.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
|
30
|
+
const styles = Array.isArray(styleProps)
|
31
|
+
? styleProps.flat()
|
32
|
+
: [styleProps]
|
33
|
+
|
34
|
+
const secrets: Array<UnistylesSecrets> = styles
|
35
|
+
.filter(Boolean)
|
36
|
+
.reduce((acc, style) => {
|
37
|
+
const unistyleKey = Object
|
38
|
+
.keys(style)
|
39
|
+
.find(key => key.startsWith('unistyles_'))
|
40
|
+
|
41
|
+
return acc.concat([
|
42
|
+
unistyleKey
|
43
|
+
? style[unistyleKey]
|
44
|
+
: {
|
45
|
+
uni__getStyles: () => style,
|
46
|
+
uni__dependencies: [],
|
47
|
+
}
|
48
|
+
])
|
49
|
+
}, [])
|
50
|
+
|
51
|
+
return {
|
52
|
+
styles: secrets.reduce((acc, secret) => Object
|
53
|
+
.assign(acc, secret.uni__getStyles()), {} as Record<string, any>),
|
54
|
+
dependencies: secrets.flatMap(secret => secret.uni__dependencies),
|
55
|
+
}
|
31
56
|
}
|
32
57
|
|
33
58
|
return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
|
@@ -46,7 +71,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
46
71
|
const styleSecrets = getSecrets(narrowedProps.style)
|
47
72
|
const contentContainerStyleSecrets = getSecrets(narrowedProps.contentContainerStyle)
|
48
73
|
|
49
|
-
addDependencies(Array.from(new Set([...styleSecrets.
|
74
|
+
addDependencies(Array.from(new Set([...styleSecrets.dependencies, ...contentContainerStyleSecrets.dependencies])))
|
50
75
|
}, [narrowedProps.style, narrowedProps.contentContainerStyle])
|
51
76
|
|
52
77
|
const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
|
@@ -58,10 +83,10 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
58
83
|
const finalProps = {
|
59
84
|
...deepMergeObjects(mappingsProps, unistyleProps, props),
|
60
85
|
...narrowedProps.style ? {
|
61
|
-
style: styleSecrets.
|
86
|
+
style: styleSecrets.styles,
|
62
87
|
} : {},
|
63
88
|
...narrowedProps.contentContainerStyle ? {
|
64
|
-
contentContainerStyle: contentContainerStyleSecrets.
|
89
|
+
contentContainerStyle: contentContainerStyleSecrets.styles,
|
65
90
|
} : {},
|
66
91
|
} as any
|
67
92
|
|
@@ -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(() => {})
|