react-native-unistyles 3.0.0-rc.4 → 3.0.0
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 +9 -7
- package/Unistyles.podspec +12 -1
- package/android/build.gradle +1 -1
- package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -8
- package/android/src/main/cxx/NativeUnistylesModule.h +4 -4
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +21 -9
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +8 -7
- package/cxx/core/UnistyleWrapper.h +4 -1
- package/cxx/core/UnistylesCommitShadowNode.h +0 -21
- package/cxx/core/UnistylesRegistry.cpp +52 -49
- package/cxx/core/UnistylesRegistry.h +2 -1
- package/cxx/core/UnistylesState.cpp +10 -0
- package/cxx/core/UnistylesState.h +3 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +6 -1
- package/cxx/hybridObjects/HybridShadowRegistry.h +6 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +13 -16
- package/cxx/hybridObjects/HybridStyleSheet.h +2 -7
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +17 -2
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +175 -110
- package/cxx/parser/Parser.h +1 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
- package/cxx/shadowTree/ShadowTreeManager.h +0 -1
- package/get_rn_version.rb +28 -0
- package/ios/UnistylesModuleOnLoad.h +1 -5
- package/ios/UnistylesModuleOnLoad.mm +10 -13
- package/lib/commonjs/components/AdaptiveTheme.js +35 -0
- package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
- package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
- package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
- package/lib/commonjs/components/NamedTheme.js +31 -0
- package/lib/commonjs/components/NamedTheme.js.map +1 -0
- package/lib/commonjs/components/ScopedTheme.js +30 -21
- package/lib/commonjs/components/ScopedTheme.js.map +1 -1
- package/lib/commonjs/components/native/Image.js +1 -2
- package/lib/commonjs/components/native/Image.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.js +1 -2
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.js +1 -2
- package/lib/commonjs/components/native/Pressable.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +1 -2
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +5 -5
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +18 -31
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +6 -21
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +1 -2
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/core/parseBoxShadow.js +57 -0
- package/lib/commonjs/core/parseBoxShadow.js.map +1 -0
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +2 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +2 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +10 -5
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +10 -5
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mocks.js +26 -2
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/reanimated/index.js +7 -0
- package/lib/commonjs/reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated/variant/index.js +17 -0
- package/lib/commonjs/reanimated/variant/index.js.map +1 -0
- package/lib/commonjs/reanimated/variant/types.js +2 -0
- package/lib/commonjs/reanimated/variant/types.js.map +1 -0
- package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
- package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
- package/lib/commonjs/server/getServerUnistyles.js +1 -2
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js +1 -2
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js +1 -2
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +3 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/utils.js +0 -3
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
- package/lib/commonjs/web/convert/pseudo.js +13 -3
- package/lib/commonjs/web/convert/pseudo.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js +1 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -1
- package/lib/commonjs/web/create.js +2 -3
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/core.js +9 -2
- package/lib/commonjs/web/css/core.js.map +1 -1
- package/lib/commonjs/web/css/state.js +10 -7
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/index.js +1 -2
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/listener.js +4 -2
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/runtime.js +26 -2
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +5 -3
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/state.js +1 -10
- package/lib/commonjs/web/state.js.map +1 -1
- package/lib/commonjs/web/types.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +1 -2
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +26 -4
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/AdaptiveTheme.js +29 -0
- package/lib/module/components/AdaptiveTheme.js.map +1 -0
- package/lib/module/components/ApplyScopedTheme.js +14 -0
- package/lib/module/components/ApplyScopedTheme.js.map +1 -0
- package/lib/module/components/NamedTheme.js +25 -0
- package/lib/module/components/NamedTheme.js.map +1 -0
- package/lib/module/components/ScopedTheme.js +30 -20
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +5 -5
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +18 -30
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +5 -19
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/parseBoxShadow.js +52 -0
- package/lib/module/core/parseBoxShadow.js.map +1 -0
- package/lib/module/core/useProxifiedUnistyles/listener.js +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.native.js +2 -1
- package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.js +9 -3
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +9 -3
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mocks.js +26 -2
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/reanimated/index.js +1 -0
- package/lib/module/reanimated/index.js.map +1 -1
- package/lib/module/reanimated/variant/index.js +4 -0
- package/lib/module/reanimated/variant/index.js.map +1 -0
- package/lib/module/reanimated/variant/types.js +2 -0
- package/lib/module/reanimated/variant/types.js.map +1 -0
- package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
- package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
- package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +6 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +3 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +0 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/utils.js +0 -3
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/object/boxShadow.js.map +1 -1
- package/lib/module/web/convert/pseudo.js +10 -2
- package/lib/module/web/convert/pseudo.js.map +1 -1
- package/lib/module/web/convert/utils.js +1 -0
- package/lib/module/web/convert/utils.js.map +1 -1
- package/lib/module/web/create.js +1 -1
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/core.js +9 -2
- package/lib/module/web/css/core.js.map +1 -1
- package/lib/module/web/css/state.js +10 -7
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/listener.js +4 -2
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/runtime.js +27 -3
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +5 -3
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/state.js +1 -10
- package/lib/module/web/state.js.map +1 -1
- package/lib/module/web/types.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +24 -3
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/plugin/src/consts.d.ts +17 -0
- package/lib/typescript/plugin/src/consts.d.ts.map +1 -0
- package/lib/typescript/repack-plugin/src/index.d.ts +18 -0
- package/lib/typescript/repack-plugin/src/index.d.ts.map +1 -0
- package/lib/typescript/repack-plugin/src/loader.d.ts +9 -0
- package/lib/typescript/repack-plugin/src/loader.d.ts.map +1 -0
- package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
- package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
- package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
- package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/ScopedTheme.d.ts +10 -0
- package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Animated.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.map +1 -1
- package/lib/typescript/src/core/parseBoxShadow.d.ts +11 -0
- package/lib/typescript/src/core/parseBoxShadow.d.ts.map +1 -0
- 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/types.d.ts +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/types.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/types.d.ts +3 -1
- package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- 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/index.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/index.d.ts +1 -0
- package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
- package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
- package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
- package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
- package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/serialize.d.ts.map +1 -1
- package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -0
- 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/specs/StyleSheet/index.d.ts +2 -0
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +2 -0
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts.map +1 -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.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 +6 -3
- 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 +2 -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/listener.d.ts +4 -2
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +2 -0
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +2 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/state.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +4 -1
- 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.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
- 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.map +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
- package/package.json +33 -23
- package/plugin/index.d.ts +6 -5
- package/plugin/index.js +11 -6
- package/repack-plugin/index.d.ts +19 -0
- package/repack-plugin/index.js +149 -0
- package/src/components/AdaptiveTheme.tsx +34 -0
- package/src/components/ApplyScopedTheme.tsx +17 -0
- package/src/components/NamedTheme.tsx +33 -0
- package/src/components/ScopedTheme.tsx +51 -24
- package/src/core/createUnistylesElement.native.tsx +21 -31
- package/src/core/createUnistylesElement.tsx +8 -6
- package/src/core/createUnistylesImageBackground.tsx +7 -22
- package/src/core/parseBoxShadow.ts +87 -0
- package/src/core/useProxifiedUnistyles/listener.native.ts +3 -1
- package/src/core/useProxifiedUnistyles/listener.ts +1 -1
- package/src/core/useProxifiedUnistyles/types.ts +1 -1
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +19 -2
- package/src/core/withUnistyles/types.ts +1 -1
- package/src/core/withUnistyles/withUnistyles.native.tsx +10 -3
- package/src/core/withUnistyles/withUnistyles.tsx +11 -8
- package/src/index.ts +8 -0
- package/src/mocks.ts +28 -2
- package/src/reanimated/index.ts +1 -0
- package/src/reanimated/variant/index.ts +1 -0
- package/src/reanimated/variant/types.ts +14 -0
- package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
- package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
- package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
- package/src/specs/ShadowRegistry/index.ts +7 -1
- package/src/specs/StyleSheet/index.ts +5 -2
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +2 -0
- package/src/specs/UnistylesRuntime/index.ts +0 -1
- package/src/utils.ts +1 -3
- package/src/web/convert/object/boxShadow.ts +2 -2
- package/src/web/convert/pseudo.ts +23 -52
- package/src/web/convert/utils.ts +2 -1
- package/src/web/create.ts +1 -1
- package/src/web/css/core.ts +12 -2
- package/src/web/css/state.ts +10 -8
- package/src/web/listener.ts +10 -6
- package/src/web/runtime.ts +37 -3
- package/src/web/shadowRegistry.ts +5 -3
- package/src/web/state.ts +7 -17
- package/src/web/types.ts +4 -1
- package/src/web/utils/unistyle.ts +34 -4
- package/cxx/core/UnistylesCommitHook.cpp +0 -59
- package/cxx/core/UnistylesCommitHook.h +0 -27
- package/cxx/core/UnistylesMountHook.cpp +0 -26
- package/cxx/core/UnistylesMountHook.h +0 -24
- package/lib/module/package.json +0 -1
- /package/{web-only → web}/package.json +0 -0
@@ -7,14 +7,16 @@ import { createUnistylesRef } from '../web/utils/createUnistylesRef'
|
|
7
7
|
import { getClassName } from './getClassname'
|
8
8
|
import { maybeWarnAboutMultipleUnistyles } from './warn'
|
9
9
|
|
10
|
-
const STYLE_PROPS = ['
|
10
|
+
const STYLE_PROPS = ['contentContainerStyle', 'columnWrapperStyle'] as const
|
11
|
+
|
12
|
+
type StyleProp = typeof STYLE_PROPS[number] | 'style'
|
11
13
|
|
12
14
|
type ComponentProps = {
|
13
|
-
[K in
|
15
|
+
[K in StyleProp]?: UnistylesValues
|
14
16
|
}
|
15
17
|
|
16
18
|
const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef: React.ForwardedRef<unknown>) => {
|
17
|
-
const componentStyleProps = STYLE_PROPS.filter(styleProp => styleProp in props)
|
19
|
+
const componentStyleProps = ['style' as const, ...STYLE_PROPS.filter(styleProp => styleProp in props)]
|
18
20
|
const classNames = Object.fromEntries(componentStyleProps.map(styleProp => [styleProp, getClassName(props[styleProp])]))
|
19
21
|
const refs = componentStyleProps.map(styleProp => {
|
20
22
|
return createUnistylesRef(
|
@@ -34,14 +36,14 @@ const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef
|
|
34
36
|
}
|
35
37
|
|
36
38
|
export const createUnistylesElement = (Component: any) => {
|
37
|
-
const UnistylesComponent =
|
39
|
+
const UnistylesComponent = (props: any) => {
|
38
40
|
return (
|
39
41
|
<Component
|
40
42
|
{...props}
|
41
|
-
{...buildUnistylesProps(Component, props,
|
43
|
+
{...buildUnistylesProps(Component, props, props.ref)}
|
42
44
|
/>
|
43
45
|
)
|
44
|
-
}
|
46
|
+
}
|
45
47
|
|
46
48
|
return copyComponentProperties(Component, UnistylesComponent)
|
47
49
|
}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import React
|
2
|
-
import type {
|
1
|
+
import React from 'react'
|
2
|
+
import type { ImageBackground, ImageBackgroundProps } from 'react-native'
|
3
3
|
import { UnistylesShadowRegistry } from '../specs'
|
4
4
|
import { copyComponentProperties } from '../utils'
|
5
5
|
import { passForwardedRef } from './passForwardRef'
|
@@ -7,17 +7,6 @@ import { maybeWarnAboutMultipleUnistyles } from './warn'
|
|
7
7
|
|
8
8
|
export const createUnistylesImageBackground = (Component: typeof ImageBackground) => {
|
9
9
|
const UnistylesImageBackground = React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
|
10
|
-
const storedImageRef = useRef<Image | null>(null)
|
11
|
-
|
12
|
-
useLayoutEffect(() => {
|
13
|
-
return () => {
|
14
|
-
if (storedImageRef.current) {
|
15
|
-
// @ts-ignore
|
16
|
-
UnistylesShadowRegistry.remove(storedImageRef.current)
|
17
|
-
}
|
18
|
-
}
|
19
|
-
}, [])
|
20
|
-
|
21
10
|
// @ts-expect-error we don't know the type of the component
|
22
11
|
maybeWarnAboutMultipleUnistyles(props.style, 'ImageBackground')
|
23
12
|
// @ts-ignore we don't know the type of the component
|
@@ -37,21 +26,17 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
|
|
37
26
|
() => {
|
38
27
|
// @ts-expect-error - this is hidden from TS
|
39
28
|
UnistylesShadowRegistry.remove(ref)
|
40
|
-
|
41
|
-
if (storedImageRef.current) {
|
42
|
-
// @ts-expect-error - this is hidden from TS
|
43
|
-
UnistylesShadowRegistry.remove(storedImageRef.current)
|
44
|
-
}
|
45
29
|
}
|
46
30
|
)
|
47
31
|
}}
|
48
32
|
imageRef={ref => {
|
49
|
-
if (ref) {
|
50
|
-
storedImageRef.current = ref
|
51
|
-
}
|
52
|
-
|
53
33
|
// @ts-expect-error web types are not compatible with RN styles
|
54
34
|
UnistylesShadowRegistry.add(ref, props.imageStyle)
|
35
|
+
|
36
|
+
return () => {
|
37
|
+
// @ts-ignore this is hidden from TS
|
38
|
+
UnistylesShadowRegistry.remove(ref)
|
39
|
+
}
|
55
40
|
}}
|
56
41
|
/>
|
57
42
|
)
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { processColor } from 'react-native'
|
2
|
+
|
3
|
+
type BoxShadow = {
|
4
|
+
inset?: boolean
|
5
|
+
offsetX?: number
|
6
|
+
offsetY?: number
|
7
|
+
blurRadius?: number
|
8
|
+
spreadDistance?: number
|
9
|
+
color?: string
|
10
|
+
}
|
11
|
+
|
12
|
+
const isValue = (str: string | undefined) => str && (str === '0' || str.endsWith('px'))
|
13
|
+
|
14
|
+
const parseBoxShadow = (str: string): BoxShadow | undefined => {
|
15
|
+
if (str === 'none') {
|
16
|
+
return undefined
|
17
|
+
}
|
18
|
+
|
19
|
+
// split by space, but not if it's inside of ()
|
20
|
+
const parts = str.split(/\s+(?![^(]*\))/)
|
21
|
+
const lastIndex = parts.length - 1
|
22
|
+
const insetIndex = parts.findIndex(part => part === 'inset')
|
23
|
+
|
24
|
+
// inset can only be at the start or end
|
25
|
+
if (![-1, 0, lastIndex].includes(insetIndex)) {
|
26
|
+
return undefined
|
27
|
+
}
|
28
|
+
|
29
|
+
// if there is no inset, color can only be at the start or end
|
30
|
+
const maybeColorsIndexes = insetIndex === -1
|
31
|
+
? [0, lastIndex]
|
32
|
+
: insetIndex === lastIndex
|
33
|
+
? [0, lastIndex - 1]
|
34
|
+
: [1, lastIndex]
|
35
|
+
|
36
|
+
const colorIndex = maybeColorsIndexes.find(index => !isValue(parts[index])) ?? -1
|
37
|
+
const maybeColor = colorIndex !== -1
|
38
|
+
? parts[colorIndex]
|
39
|
+
: undefined
|
40
|
+
const color = maybeColor && processColor(maybeColor)
|
41
|
+
? parts[colorIndex]
|
42
|
+
: undefined
|
43
|
+
const values = parts.filter((_, index) => index !== colorIndex && index !== insetIndex)
|
44
|
+
|
45
|
+
// at this point there can be only 4 values
|
46
|
+
if (values.length > 4) {
|
47
|
+
return undefined
|
48
|
+
}
|
49
|
+
|
50
|
+
const [offsetX, offsetY, blurRadius, spreadRadius] = values
|
51
|
+
|
52
|
+
if (!isValue(offsetX) || !isValue(offsetY)) {
|
53
|
+
return undefined
|
54
|
+
}
|
55
|
+
|
56
|
+
const blurRadiusValue = isValue(blurRadius)
|
57
|
+
? Number.parseFloat(blurRadius as string)
|
58
|
+
: undefined
|
59
|
+
|
60
|
+
if (blurRadiusValue !== undefined && blurRadiusValue < 0) {
|
61
|
+
return undefined
|
62
|
+
}
|
63
|
+
|
64
|
+
return {
|
65
|
+
inset: insetIndex !== -1
|
66
|
+
? true
|
67
|
+
: undefined,
|
68
|
+
offsetX: Number.parseFloat(offsetX as string),
|
69
|
+
offsetY: Number.parseFloat(offsetY as string),
|
70
|
+
blurRadius: blurRadiusValue ?? 0,
|
71
|
+
spreadDistance: spreadRadius
|
72
|
+
? Number.parseFloat(spreadRadius as string)
|
73
|
+
: 0,
|
74
|
+
color
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
export const parseBoxShadowString = (str: string): Array<BoxShadow> => {
|
79
|
+
const parts = str
|
80
|
+
.split(/,(?![^()]*\))/)
|
81
|
+
.map(part => part.trim().replace('\n', ''))
|
82
|
+
.filter(Boolean)
|
83
|
+
.map(parseBoxShadow)
|
84
|
+
.filter(Boolean) as Array<BoxShadow>
|
85
|
+
|
86
|
+
return parts
|
87
|
+
}
|
@@ -10,7 +10,9 @@ export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerP
|
|
10
10
|
}
|
11
11
|
|
12
12
|
if (changedDependencies.some((dependency: UnistyleDependency) => dependencies.includes(dependency))) {
|
13
|
-
|
13
|
+
const hasThemeNameChange = changedDependencies.includes(UnistyleDependency.ThemeName)
|
14
|
+
|
15
|
+
updateRuntime(hasThemeNameChange)
|
14
16
|
}
|
15
17
|
})
|
16
18
|
|
@@ -4,7 +4,7 @@ import type { ListenerProps } from './types'
|
|
4
4
|
|
5
5
|
export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
|
6
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)
|
7
|
+
const disposeRuntime = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), dependency => updateRuntime(dependency === UnistyleDependency.ThemeName))
|
8
8
|
|
9
9
|
return () => {
|
10
10
|
disposeTheme()
|
@@ -28,7 +28,7 @@ const RTDependencyMap = {
|
|
28
28
|
} satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
|
29
29
|
|
30
30
|
export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
31
|
-
const scopedTheme = forcedTheme ?? UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
|
31
|
+
const [scopedTheme, setScopedTheme] = useState(forcedTheme ?? UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme)
|
32
32
|
const [dependencies] = useState(() => new Set<number>())
|
33
33
|
const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme))
|
34
34
|
const [_, runtimeChanged] = useReducer(() => ({}), {})
|
@@ -45,7 +45,13 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
45
45
|
|
46
46
|
setTheme(UnistylesRuntime.getTheme(scopedTheme))
|
47
47
|
},
|
48
|
-
updateRuntime: () =>
|
48
|
+
updateRuntime: (hasThemeNameChange: boolean) => {
|
49
|
+
if (hasThemeNameChange && scopedTheme) {
|
50
|
+
return
|
51
|
+
}
|
52
|
+
|
53
|
+
runtimeChanged()
|
54
|
+
}
|
49
55
|
})
|
50
56
|
}
|
51
57
|
|
@@ -55,6 +61,13 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
55
61
|
return () => disposeRef.current?.()
|
56
62
|
}, [dependencies.size])
|
57
63
|
|
64
|
+
|
65
|
+
const maybeNewScopedTheme = UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
|
66
|
+
|
67
|
+
if (scopedTheme && maybeNewScopedTheme && scopedTheme !== maybeNewScopedTheme) {
|
68
|
+
setScopedTheme(maybeNewScopedTheme)
|
69
|
+
}
|
70
|
+
|
58
71
|
const proxifiedTheme = new Proxy(theme, {
|
59
72
|
get: (target, prop) => {
|
60
73
|
dependencies.add(UnistyleDependency.Theme)
|
@@ -84,6 +97,10 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
|
84
97
|
dependencies.add(RTDependencyMap[prop as keyof typeof RTDependencyMap])
|
85
98
|
}
|
86
99
|
|
100
|
+
if (prop === 'themeName' && scopedTheme) {
|
101
|
+
return scopedTheme
|
102
|
+
}
|
103
|
+
|
87
104
|
return target[prop as keyof typeof target]
|
88
105
|
}
|
89
106
|
})
|
@@ -4,4 +4,4 @@ import type { UnistylesTheme } from '../../types';
|
|
4
4
|
export const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
|
5
5
|
|
6
6
|
export type SupportedStyleProps = typeof SUPPORTED_STYLE_PROPS[number]
|
7
|
-
export type Mappings<T = {}> = (theme: UnistylesTheme, rt: UnistylesMiniRuntime) => Omit<Partial<T>, SupportedStyleProps>
|
7
|
+
export type Mappings<T = {}> = (theme: UnistylesTheme, rt: UnistylesMiniRuntime) => Omit<Partial<T>, SupportedStyleProps> & { key?: string }
|
@@ -26,6 +26,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
26
26
|
type PropsWithUnistyles = Partial<TProps> & {
|
27
27
|
uniProps?: Mappings<TProps>
|
28
28
|
}
|
29
|
+
|
29
30
|
const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
|
30
31
|
const styles = Array.isArray(styleProps)
|
31
32
|
? styleProps.flat()
|
@@ -74,8 +75,8 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
74
75
|
addDependencies(Array.from(new Set([...styleSecrets.dependencies, ...contentContainerStyleSecrets.dependencies])))
|
75
76
|
}, [narrowedProps.style, narrowedProps.contentContainerStyle])
|
76
77
|
|
77
|
-
const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
|
78
|
-
const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
|
78
|
+
const { key: mappingsKey, ...mappingsProps } = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
|
79
|
+
const { key: uniPropsKey, ...unistyleProps } = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
|
79
80
|
|
80
81
|
const styleSecrets = getSecrets(narrowedProps.style)
|
81
82
|
const contentContainerStyleSecrets = getSecrets(narrowedProps.contentContainerStyle)
|
@@ -90,6 +91,12 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
90
91
|
} : {},
|
91
92
|
} as any
|
92
93
|
|
93
|
-
return
|
94
|
+
return (
|
95
|
+
<NativeComponent
|
96
|
+
key={uniPropsKey || mappingsKey}
|
97
|
+
{...finalProps as TProps}
|
98
|
+
ref={ref}
|
99
|
+
/>
|
100
|
+
)
|
94
101
|
})
|
95
102
|
}
|
@@ -27,16 +27,15 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
27
27
|
const contentContainerStyleClassNames = getClassName(narrowedProps.contentContainerStyle)
|
28
28
|
const { proxifiedRuntime, proxifiedTheme } = useProxifiedUnistyles()
|
29
29
|
|
30
|
-
const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
|
31
|
-
const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
|
32
|
-
|
30
|
+
const { key: mappingsKey, ...mappingsProps } = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
|
31
|
+
const { key: uniPropsKey, ...unistyleProps } = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
|
33
32
|
|
34
33
|
const emptyStyles = narrowedProps.style
|
35
34
|
? Object.fromEntries(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
|
36
|
+
.filter(([key]) => !key.startsWith("unistyles") && !key.startsWith("_"))
|
37
|
+
.map(([key]) => [key, undefined])
|
38
|
+
)
|
40
39
|
: undefined
|
41
40
|
|
42
41
|
const combinedProps = {
|
@@ -63,7 +62,11 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
63
62
|
className={classNames?.hash}
|
64
63
|
style={{ display: 'contents' }}
|
65
64
|
>
|
66
|
-
<NativeComponent
|
65
|
+
<NativeComponent
|
66
|
+
key={uniPropsKey || mappingsKey}
|
67
|
+
{...combinedProps}
|
68
|
+
ref={ref}
|
69
|
+
/>
|
67
70
|
</div>
|
68
71
|
)
|
69
72
|
})
|
package/src/index.ts
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
import React from 'react'
|
2
|
+
|
3
|
+
const [majorReactVersions] = React.version.split('.').map(Number.parseInt)
|
4
|
+
|
5
|
+
if (majorReactVersions === undefined || majorReactVersions < 19) {
|
6
|
+
throw new Error('Unistyles 🦄: To enable full Fabric power you need to use React 19.0.0 or higher')
|
7
|
+
}
|
8
|
+
|
1
9
|
export { StyleSheet, UnistylesRuntime, StatusBar, NavigationBar } from './specs'
|
2
10
|
export { mq } from './mq'
|
3
11
|
export type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
package/src/mocks.ts
CHANGED
@@ -65,6 +65,8 @@ jest.mock('react-native-unistyles', () => {
|
|
65
65
|
colorScheme: 'unspecified' as ColorScheme,
|
66
66
|
contentSizeCategory: 'Medium' as IOSContentSizeCategory,
|
67
67
|
orientation: 'portrait' as Orientation,
|
68
|
+
isPortrait: true,
|
69
|
+
isLandscape: false,
|
68
70
|
breakpoints: {},
|
69
71
|
dispose: () => { },
|
70
72
|
equals: () => false,
|
@@ -91,7 +93,7 @@ jest.mock('react-native-unistyles', () => {
|
|
91
93
|
pixelRatio: 0,
|
92
94
|
rtl: false,
|
93
95
|
getTheme: () => {
|
94
|
-
return {} as UnistylesTheme
|
96
|
+
return (Object.values(_REGISTRY.themes).at(0) ?? {}) as UnistylesTheme
|
95
97
|
},
|
96
98
|
setTheme: () => {},
|
97
99
|
updateTheme: () => {},
|
@@ -200,7 +202,8 @@ jest.mock('react-native-unistyles', () => {
|
|
200
202
|
}
|
201
203
|
},
|
202
204
|
jsMethods: {
|
203
|
-
processColor: () => null
|
205
|
+
processColor: () => null,
|
206
|
+
parseBoxShadowString: () => []
|
204
207
|
},
|
205
208
|
hairlineWidth: 1,
|
206
209
|
unid: -1,
|
@@ -214,4 +217,27 @@ jest.mock('react-native-unistyles', () => {
|
|
214
217
|
}
|
215
218
|
})
|
216
219
|
|
220
|
+
jest.mock('react-native-unistyles/reanimated', () => {
|
221
|
+
const unistyles = require('react-native-unistyles')
|
222
|
+
const mockedSharedValue = (value: any) => ({
|
223
|
+
value
|
224
|
+
})
|
217
225
|
|
226
|
+
return {
|
227
|
+
useAnimatedTheme: () => {
|
228
|
+
const theme = unistyles.useUnistyles().theme
|
229
|
+
const sharedTheme = mockedSharedValue(theme)
|
230
|
+
|
231
|
+
return sharedTheme
|
232
|
+
},
|
233
|
+
useAnimatedVariantColor: () => {
|
234
|
+
const fromValue = mockedSharedValue('#000000')
|
235
|
+
const toValue = mockedSharedValue('#FFFFFF')
|
236
|
+
|
237
|
+
return {
|
238
|
+
fromValue,
|
239
|
+
toValue
|
240
|
+
}
|
241
|
+
},
|
242
|
+
}
|
243
|
+
})
|
package/src/reanimated/index.ts
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './useAnimatedVariantColor'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export type ColorKeys<T> = {
|
2
|
+
[K in keyof T]: K extends string
|
3
|
+
? K extends `${string}color${string}` | `${string}Color${string}`
|
4
|
+
? K
|
5
|
+
: never
|
6
|
+
: never
|
7
|
+
}[keyof T]
|
8
|
+
|
9
|
+
export type UseUpdateVariantColorConfig<T extends Record<string, any>> = {
|
10
|
+
animateCallback?: (from: string, to: string) => void,
|
11
|
+
colorKey: ColorKeys<T>,
|
12
|
+
style: T,
|
13
|
+
secretKey: string | undefined
|
14
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { interpolateColor, useDerivedValue, useSharedValue } from 'react-native-reanimated'
|
2
|
+
import type { ColorKeys } from './types'
|
3
|
+
import { useUpdateVariantColor } from './useUpdateVariantColor'
|
4
|
+
|
5
|
+
export const useAnimatedVariantColor = <T extends Record<string, any>>(style: T, colorKey: ColorKeys<T>) => {
|
6
|
+
const secretKey = Object.keys(style).find(key => key.startsWith('unistyles_'))
|
7
|
+
// @ts-ignore this is hidden from TS
|
8
|
+
const hasVariants = style[secretKey]?.__stylesheetVariants
|
9
|
+
|
10
|
+
if (!hasVariants || !colorKey.toLowerCase().includes('color')) {
|
11
|
+
throw new Error('useAnimatedVariantColor: Style was not created by Unistyles, does not have variants or has no color property')
|
12
|
+
}
|
13
|
+
|
14
|
+
const { fromValue, toValue } = useUpdateVariantColor({
|
15
|
+
animateCallback: (from, to) => animate(from, to),
|
16
|
+
colorKey,
|
17
|
+
secretKey,
|
18
|
+
style,
|
19
|
+
})
|
20
|
+
|
21
|
+
const progress = useSharedValue(1)
|
22
|
+
const animate = (from: string, to: string) => {
|
23
|
+
'worklet'
|
24
|
+
|
25
|
+
fromValue.set(from)
|
26
|
+
toValue.set(to)
|
27
|
+
}
|
28
|
+
|
29
|
+
const derivedColor = useDerivedValue(() => {
|
30
|
+
return interpolateColor(
|
31
|
+
progress.value,
|
32
|
+
[0, 1],
|
33
|
+
[fromValue.get(), toValue.get()]
|
34
|
+
)
|
35
|
+
})
|
36
|
+
|
37
|
+
return derivedColor
|
38
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { useEffect, useLayoutEffect } from 'react'
|
2
|
+
import { useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { StyleSheet, UnistyleDependency } from '../../specs'
|
4
|
+
import type { UseUpdateVariantColorConfig } from './types'
|
5
|
+
|
6
|
+
export const useUpdateVariantColor = <T extends Record<string, any>>({
|
7
|
+
colorKey,
|
8
|
+
style,
|
9
|
+
secretKey
|
10
|
+
}: UseUpdateVariantColorConfig<T>) => {
|
11
|
+
const fromValue = useSharedValue<string>(style[colorKey])
|
12
|
+
const toValue = useSharedValue<string>(style[colorKey])
|
13
|
+
|
14
|
+
useEffect(() => {
|
15
|
+
// @ts-ignore this is hidden from TS
|
16
|
+
const dispose = StyleSheet.addChangeListener(changedDependencies => {
|
17
|
+
if (changedDependencies.includes(UnistyleDependency.Theme) || changedDependencies.includes(UnistyleDependency.Breakpoints)) {
|
18
|
+
// @ts-ignore
|
19
|
+
const newStyles = style[secretKey]?.uni__getStyles()
|
20
|
+
|
21
|
+
fromValue.set(toValue.value)
|
22
|
+
toValue.set(newStyles[colorKey])
|
23
|
+
}
|
24
|
+
})
|
25
|
+
|
26
|
+
return () => dispose()
|
27
|
+
}, [style, colorKey])
|
28
|
+
|
29
|
+
useLayoutEffect(() => {
|
30
|
+
fromValue.set(toValue.value)
|
31
|
+
toValue.set(style[colorKey])
|
32
|
+
}, [style, colorKey])
|
33
|
+
|
34
|
+
return {
|
35
|
+
fromValue,
|
36
|
+
toValue
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react'
|
2
|
+
import { runOnUI, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { UnistyleDependency } from '../../specs'
|
4
|
+
import type { UnistylesValues } from '../../types'
|
5
|
+
import { services } from '../../web/services'
|
6
|
+
import { getClosestBreakpointValue } from '../../web/utils'
|
7
|
+
import type { UseUpdateVariantColorConfig } from './types'
|
8
|
+
|
9
|
+
export const useUpdateVariantColor = <T extends Record<string, any>>({
|
10
|
+
animateCallback,
|
11
|
+
colorKey,
|
12
|
+
style
|
13
|
+
}: UseUpdateVariantColorConfig<T>) => {
|
14
|
+
const [dummyDiv] = useState(() => {
|
15
|
+
const div = document.createElement('div')
|
16
|
+
|
17
|
+
div.style.display = 'none'
|
18
|
+
document.body.appendChild(div)
|
19
|
+
|
20
|
+
return div
|
21
|
+
})
|
22
|
+
const parsedStyles = useMemo(() => {
|
23
|
+
return services.shadowRegistry.addStyles([style]).parsedStyles
|
24
|
+
}, [style])
|
25
|
+
const getCurrentColor = useCallback(
|
26
|
+
() => {
|
27
|
+
if (!parsedStyles) {
|
28
|
+
return 'rgb(0, 0, 0)'
|
29
|
+
}
|
30
|
+
|
31
|
+
const currentColor = parsedStyles[colorKey as keyof UnistylesValues] as string | Record<string, string>
|
32
|
+
const currentColorVar = typeof currentColor === 'string'
|
33
|
+
? currentColor
|
34
|
+
: getClosestBreakpointValue<string>(services.runtime, currentColor) ?? 'rgb(0, 0, 0)'
|
35
|
+
|
36
|
+
if (currentColorVar.startsWith('var(--')) {
|
37
|
+
dummyDiv.style.color = currentColorVar
|
38
|
+
|
39
|
+
return getComputedStyle(dummyDiv).color
|
40
|
+
}
|
41
|
+
|
42
|
+
return currentColorVar
|
43
|
+
},
|
44
|
+
[style, colorKey]
|
45
|
+
)
|
46
|
+
const fromValue = useSharedValue<string>(getCurrentColor())
|
47
|
+
const toValue = useSharedValue<string>(getCurrentColor())
|
48
|
+
|
49
|
+
useEffect(() => {
|
50
|
+
const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => {
|
51
|
+
runOnUI(() => {
|
52
|
+
animateCallback?.(toValue.get(), getCurrentColor())
|
53
|
+
})()
|
54
|
+
})
|
55
|
+
|
56
|
+
return () => dispose()
|
57
|
+
}, [style, colorKey])
|
58
|
+
|
59
|
+
useLayoutEffect(() => {
|
60
|
+
animateCallback?.(toValue.get(), getCurrentColor())
|
61
|
+
|
62
|
+
const colorStyle = parsedStyles?.[colorKey as keyof UnistylesValues]
|
63
|
+
|
64
|
+
if (typeof colorStyle !== 'object' || colorStyle === null) {
|
65
|
+
return
|
66
|
+
}
|
67
|
+
|
68
|
+
const dispose = services.listener.addListeners([UnistyleDependency.Breakpoints], () => {
|
69
|
+
animateCallback?.(toValue.get(), getCurrentColor())
|
70
|
+
})
|
71
|
+
|
72
|
+
return () => dispose()
|
73
|
+
}, [style, colorKey])
|
74
|
+
|
75
|
+
useEffect(() => () => dummyDiv.remove(), [])
|
76
|
+
|
77
|
+
return {
|
78
|
+
fromValue,
|
79
|
+
toValue
|
80
|
+
}
|
81
|
+
}
|
@@ -9,6 +9,7 @@ interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
|
9
9
|
// JSI
|
10
10
|
link(node: ShadowNode, styles?: Array<Unistyle>): void,
|
11
11
|
unlink(node: ShadowNode): void,
|
12
|
+
flush(): void,
|
12
13
|
setScopedTheme(themeName?: string): void,
|
13
14
|
getScopedTheme(): string | undefined
|
14
15
|
}
|
@@ -23,8 +24,13 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
23
24
|
?? handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node
|
24
25
|
?? handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node
|
25
26
|
|
27
|
+
// @ts-ignore we don't know the type of handle
|
28
|
+
if (!node && handle?.props?.horizontal && handle?.constructor?.name === 'FlatList') {
|
29
|
+
throw new Error('Unistyles: detected an unsupported FlatList with the horizontal prop. This will cause crashes on Android due to a bug in React Native core. Read more: https://github.com/facebook/react-native/issues/51601')
|
30
|
+
}
|
31
|
+
|
26
32
|
if (!node) {
|
27
|
-
throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.
|
33
|
+
throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.constructor?.name ?? 'unknown'}`)
|
28
34
|
}
|
29
35
|
|
30
36
|
return node
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { StyleSheet as NativeStyleSheet, processColor } from 'react-native'
|
2
2
|
import type { StyleSheet as NativeStyleSheetType } from 'react-native'
|
3
3
|
import { NitroModules } from 'react-native-nitro-modules'
|
4
|
+
import { parseBoxShadowString } from '../../core/parseBoxShadow'
|
4
5
|
import type { UnistylesBreakpoints, UnistylesThemes } from '../../global'
|
5
6
|
import type { CreateUnistylesStyleSheet } from '../../types'
|
6
7
|
import type { UnistylesStyleSheet as UnistylesStyleSheetSpec } from './UnistylesStyleSheet.nitro'
|
@@ -33,7 +34,8 @@ export interface UnistylesStyleSheet extends UnistylesStyleSheetSpec {
|
|
33
34
|
create: CreateUnistylesStyleSheet,
|
34
35
|
configure(config: UnistylesConfig): void,
|
35
36
|
jsMethods: {
|
36
|
-
processColor: typeof processColor
|
37
|
+
processColor: typeof processColor,
|
38
|
+
parseBoxShadowString: typeof parseBoxShadowString
|
37
39
|
}
|
38
40
|
}
|
39
41
|
|
@@ -45,7 +47,8 @@ HybridUnistylesStyleSheet.absoluteFill = NativeStyleSheet.absoluteFill
|
|
45
47
|
HybridUnistylesStyleSheet.flatten = NativeStyleSheet.flatten
|
46
48
|
HybridUnistylesStyleSheet.compose = NativeStyleSheet.compose
|
47
49
|
HybridUnistylesStyleSheet.jsMethods = {
|
48
|
-
processColor
|
50
|
+
processColor,
|
51
|
+
parseBoxShadowString
|
49
52
|
}
|
50
53
|
|
51
54
|
HybridUnistylesStyleSheet.init()
|
@@ -36,6 +36,8 @@ export interface UnistylesRuntime extends HybridObject<{ ios: 'c++', android: 'c
|
|
36
36
|
readonly pixelRatio: number,
|
37
37
|
readonly fontScale: number,
|
38
38
|
readonly rtl: boolean,
|
39
|
+
readonly isLandscape: boolean,
|
40
|
+
readonly isPortrait: boolean,
|
39
41
|
|
40
42
|
setTheme(themeName: string): void,
|
41
43
|
setAdaptiveThemes(isEnabled: boolean): void,
|
@@ -44,7 +44,6 @@ const HybridUnistylesRuntime = NitroModules
|
|
44
44
|
|
45
45
|
HybridUnistylesRuntime.statusBar = HybridUnistylesRuntime.createHybridStatusBar()
|
46
46
|
HybridUnistylesRuntime.navigationBar = HybridUnistylesRuntime.createHybridNavigationBar()
|
47
|
-
HybridUnistylesRuntime._setRootViewBackgroundColor = HybridUnistylesRuntime.setRootViewBackgroundColor
|
48
47
|
|
49
48
|
HybridUnistylesRuntime.setRootViewBackgroundColor = (color?: string) => {
|
50
49
|
const parsedColor = processColor(color) ?? 0
|