react-native-unistyles 3.0.0-rc.3 → 3.0.0-rc.5
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 +10 -8
- 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/UnistylesModule.kt +1 -7
- package/cxx/core/UnistyleWrapper.h +4 -1
- package/cxx/core/UnistylesCommitShadowNode.h +0 -21
- package/cxx/core/UnistylesRegistry.cpp +45 -49
- 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 +8 -0
- 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/ios/UnistylesModuleOnLoad.h +1 -5
- package/ios/UnistylesModuleOnLoad.mm +5 -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 +24 -20
- 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 +3 -3
- 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 +1 -2
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +1 -2
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +1 -2
- 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 +5 -2
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/reanimated/index.js +20 -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/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/utils.js +0 -3
- package/lib/commonjs/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 +6 -1
- 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 +2 -0
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/runtime.js +15 -1
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +12 -4
- 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 +2 -0
- 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 +30 -3
- 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/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 +24 -19
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +3 -3
- 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/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 +5 -2
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/reanimated/index.js +5 -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/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/utils.js +0 -3
- package/lib/module/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 +6 -1
- 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 +2 -0
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/runtime.js +16 -2
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +13 -5
- 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 +1 -1
- package/lib/module/web/types.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +27 -2
- 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/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 +4 -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/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.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 +3 -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/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/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.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.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 +4 -2
- 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 +6 -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.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +7 -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 +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/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 +57 -25
- package/plugin/index.d.ts +6 -5
- package/plugin/index.js +103 -99
- package/reanimated/package.json +6 -0
- 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 +42 -22
- package/src/core/createUnistylesElement.native.tsx +21 -31
- package/src/core/createUnistylesElement.tsx +3 -3
- package/src/core/createUnistylesImageBackground.tsx +7 -22
- package/src/core/parseBoxShadow.ts +87 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +1 -0
- package/src/index.ts +8 -0
- package/src/mocks.ts +5 -2
- package/src/reanimated/index.ts +2 -0
- package/src/reanimated/useAnimatedTheme.native.ts +21 -0
- package/src/reanimated/useAnimatedTheme.ts +19 -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/utils.ts +1 -3
- package/src/web/create.ts +1 -1
- package/src/web/css/core.ts +9 -1
- package/src/web/css/state.ts +10 -8
- package/src/web/listener.ts +2 -0
- package/src/web/runtime.ts +23 -2
- package/src/web/shadowRegistry.ts +15 -6
- package/src/web/state.ts +7 -17
- package/src/web/types.ts +12 -4
- package/src/web/utils/unistyle.ts +38 -3
- package/src/web-only/getWebProps.ts +18 -0
- package/src/web-only/index.ts +2 -0
- package/web/package.json +6 -0
- package/cxx/core/UnistylesCommitHook.cpp +0 -52
- package/cxx/core/UnistylesCommitHook.h +0 -27
- package/cxx/core/UnistylesMountHook.cpp +0 -28
- package/cxx/core/UnistylesMountHook.h +0 -24
- package/lib/module/package.json +0 -1
@@ -0,0 +1,149 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// repack-plugin/src/index.ts
|
21
|
+
var index_exports = {};
|
22
|
+
__export(index_exports, {
|
23
|
+
BASE_REPACK_EXCLUDE_PATHS: () => BASE_REPACK_EXCLUDE_PATHS,
|
24
|
+
RepackUnistylePlugin: () => RepackUnistylePlugin,
|
25
|
+
default: () => index_default
|
26
|
+
});
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
28
|
+
var import_repack = require("@callstack/repack");
|
29
|
+
|
30
|
+
// repack-plugin/src/loader.ts
|
31
|
+
var import_core = require("@babel/core");
|
32
|
+
|
33
|
+
// plugin/src/consts.ts
|
34
|
+
var REACT_NATIVE_COMPONENT_NAMES = [
|
35
|
+
"ActivityIndicator",
|
36
|
+
"View",
|
37
|
+
"Text",
|
38
|
+
"Image",
|
39
|
+
"ImageBackground",
|
40
|
+
"KeyboardAvoidingView",
|
41
|
+
"Pressable",
|
42
|
+
"ScrollView",
|
43
|
+
"FlatList",
|
44
|
+
"SectionList",
|
45
|
+
"Switch",
|
46
|
+
"TextInput",
|
47
|
+
"RefreshControl",
|
48
|
+
"TouchableHighlight",
|
49
|
+
"TouchableOpacity",
|
50
|
+
"VirtualizedList",
|
51
|
+
"Animated"
|
52
|
+
// Modal - there is no exposed native handle
|
53
|
+
// TouchableWithoutFeedback - can't accept a ref
|
54
|
+
];
|
55
|
+
var REPLACE_WITH_UNISTYLES_PATHS = [
|
56
|
+
"react-native-reanimated/src/component",
|
57
|
+
"react-native-reanimated/lib/module/component"
|
58
|
+
];
|
59
|
+
|
60
|
+
// repack-plugin/src/loader.ts
|
61
|
+
var importName = "react-native-unistyles";
|
62
|
+
var UNISTYLES_REGEX = new RegExp(
|
63
|
+
[...REACT_NATIVE_COMPONENT_NAMES, ...REPLACE_WITH_UNISTYLES_PATHS, importName].join("|")
|
64
|
+
);
|
65
|
+
function unistylesLoader(source) {
|
66
|
+
this.cacheable();
|
67
|
+
const callback = this.async();
|
68
|
+
const options = this.getOptions();
|
69
|
+
if (!UNISTYLES_REGEX.test(source)) {
|
70
|
+
callback(null, source);
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
const unistylesOptions = options.unistylesPluginOptions;
|
74
|
+
const unistylesPlugin = unistylesOptions ? ["react-native-unistyles/plugin", unistylesOptions] : "react-native-unistyles/plugin";
|
75
|
+
const babelPlugins = options.babelPlugins ?? [];
|
76
|
+
(0, import_core.transform)(
|
77
|
+
source,
|
78
|
+
{
|
79
|
+
filename: this.resourcePath,
|
80
|
+
babelrc: false,
|
81
|
+
configFile: false,
|
82
|
+
compact: false,
|
83
|
+
comments: true,
|
84
|
+
plugins: [...babelPlugins, unistylesPlugin]
|
85
|
+
},
|
86
|
+
(err, result) => {
|
87
|
+
if (err) {
|
88
|
+
callback(err);
|
89
|
+
return;
|
90
|
+
}
|
91
|
+
callback(null, result.code, result.map);
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
);
|
95
|
+
}
|
96
|
+
|
97
|
+
// repack-plugin/src/index.ts
|
98
|
+
var BASE_REPACK_EXCLUDE_PATHS = (0, import_repack.getModulePaths)([
|
99
|
+
"react",
|
100
|
+
"react-native",
|
101
|
+
"@react-native",
|
102
|
+
"react-native-macos",
|
103
|
+
"react-native-windows",
|
104
|
+
"react-native-tvos",
|
105
|
+
"@callstack/react-native-visionos",
|
106
|
+
"@module-federation",
|
107
|
+
"react-native-unistyles",
|
108
|
+
"whatwg-fetch",
|
109
|
+
"@callstack",
|
110
|
+
"react-native-nitro-modules",
|
111
|
+
"@callstack/repack"
|
112
|
+
]);
|
113
|
+
var getUnistyleModuleRules = (excludePathLoader, unistylesPluginOptions) => {
|
114
|
+
const createRule = (test, babelPlugins) => ({
|
115
|
+
test,
|
116
|
+
use: {
|
117
|
+
loader: "react-native-unistyles/repack-plugin",
|
118
|
+
options: {
|
119
|
+
babelPlugins,
|
120
|
+
unistylesPluginOptions
|
121
|
+
}
|
122
|
+
}
|
123
|
+
});
|
124
|
+
return {
|
125
|
+
exclude: excludePathLoader,
|
126
|
+
oneOf: [
|
127
|
+
createRule(/\.[cm]?ts$/, [["@babel/plugin-syntax-typescript", { isTSX: false, allowNamespaces: true }]]),
|
128
|
+
createRule(/\.[cm]?tsx$/, [["@babel/plugin-syntax-typescript", { isTSX: true, allowNamespaces: true }]]),
|
129
|
+
createRule(/\.[cm]?jsx?$/, ["babel-plugin-syntax-hermes-parser"])
|
130
|
+
]
|
131
|
+
};
|
132
|
+
};
|
133
|
+
var RepackUnistylePlugin = class {
|
134
|
+
ruleExcludePaths;
|
135
|
+
unistylesPluginOptions;
|
136
|
+
constructor({ ruleExcludePaths = BASE_REPACK_EXCLUDE_PATHS, unistylesPluginOptions } = {}) {
|
137
|
+
this.ruleExcludePaths = ruleExcludePaths;
|
138
|
+
this.unistylesPluginOptions = unistylesPluginOptions;
|
139
|
+
}
|
140
|
+
apply(compiler) {
|
141
|
+
compiler.options.module.rules.push(getUnistyleModuleRules(this.ruleExcludePaths, this.unistylesPluginOptions));
|
142
|
+
}
|
143
|
+
};
|
144
|
+
var index_default = unistylesLoader;
|
145
|
+
// Annotate the CommonJS export names for ESM import in node:
|
146
|
+
0 && (module.exports = {
|
147
|
+
BASE_REPACK_EXCLUDE_PATHS,
|
148
|
+
RepackUnistylePlugin
|
149
|
+
});
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import React, { useLayoutEffect } from 'react'
|
2
|
+
import type { PropsWithChildren } from 'react'
|
3
|
+
import { useUnistyles } from '../core'
|
4
|
+
import type { UnistylesThemes } from '../global'
|
5
|
+
import { UnistylesShadowRegistry } from '../specs'
|
6
|
+
import { ApplyScopedTheme } from './ApplyScopedTheme'
|
7
|
+
|
8
|
+
interface AdaptiveThemeProps extends PropsWithChildren {
|
9
|
+
previousScopedTheme?: string
|
10
|
+
}
|
11
|
+
|
12
|
+
export const AdaptiveTheme: React.FunctionComponent<AdaptiveThemeProps> = ({
|
13
|
+
children,
|
14
|
+
previousScopedTheme
|
15
|
+
}) => {
|
16
|
+
const { rt } = useUnistyles()
|
17
|
+
const name = (rt.themeName === 'dark' ? 'light' : 'dark') as keyof UnistylesThemes
|
18
|
+
const mappedChildren = [
|
19
|
+
<ApplyScopedTheme key={name} name={name} />,
|
20
|
+
children,
|
21
|
+
<ApplyScopedTheme key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
|
22
|
+
]
|
23
|
+
|
24
|
+
useLayoutEffect(() => {
|
25
|
+
// this will affect only scoped styles as other styles are not yet mounted
|
26
|
+
UnistylesShadowRegistry.flush()
|
27
|
+
})
|
28
|
+
|
29
|
+
return (
|
30
|
+
<React.Fragment key={name}>
|
31
|
+
{mappedChildren}
|
32
|
+
</React.Fragment>
|
33
|
+
)
|
34
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { useLayoutEffect } from 'react'
|
2
|
+
import type { UnistylesThemes } from '../global'
|
3
|
+
import { UnistylesShadowRegistry } from '../specs'
|
4
|
+
|
5
|
+
type ApplyScopedThemeProps = {
|
6
|
+
name?: keyof UnistylesThemes
|
7
|
+
}
|
8
|
+
|
9
|
+
export const ApplyScopedTheme: React.FunctionComponent<ApplyScopedThemeProps> = ({ name }) => {
|
10
|
+
UnistylesShadowRegistry.setScopedTheme(name)
|
11
|
+
|
12
|
+
useLayoutEffect(() => {
|
13
|
+
UnistylesShadowRegistry.setScopedTheme(name)
|
14
|
+
})
|
15
|
+
|
16
|
+
return null
|
17
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import React, { useLayoutEffect } from 'react'
|
2
|
+
import type { PropsWithChildren } from 'react'
|
3
|
+
import type { UnistylesThemes } from '../global'
|
4
|
+
import { UnistylesShadowRegistry } from '../specs'
|
5
|
+
import { ApplyScopedTheme } from './ApplyScopedTheme'
|
6
|
+
|
7
|
+
interface NamedThemeProps extends PropsWithChildren {
|
8
|
+
name: keyof UnistylesThemes,
|
9
|
+
previousScopedTheme?: string
|
10
|
+
}
|
11
|
+
|
12
|
+
export const NamedTheme: React.FunctionComponent<NamedThemeProps> = ({
|
13
|
+
name,
|
14
|
+
children,
|
15
|
+
previousScopedTheme
|
16
|
+
}) => {
|
17
|
+
const mappedChildren = [
|
18
|
+
<ApplyScopedTheme key={name} name={name} />,
|
19
|
+
children,
|
20
|
+
<ApplyScopedTheme key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
|
21
|
+
]
|
22
|
+
|
23
|
+
useLayoutEffect(() => {
|
24
|
+
// this will affect only scoped styles as other styles are not yet mounted
|
25
|
+
UnistylesShadowRegistry.flush()
|
26
|
+
})
|
27
|
+
|
28
|
+
return (
|
29
|
+
<React.Fragment>
|
30
|
+
{mappedChildren}
|
31
|
+
</React.Fragment>
|
32
|
+
)
|
33
|
+
}
|
@@ -1,32 +1,52 @@
|
|
1
|
-
import React
|
1
|
+
import React from 'react'
|
2
2
|
import type { UnistylesThemes } from '../global'
|
3
|
-
import { UnistylesShadowRegistry } from '../specs'
|
3
|
+
import { UnistylesRuntime, UnistylesShadowRegistry } from '../specs'
|
4
|
+
import { AdaptiveTheme } from './AdaptiveTheme'
|
5
|
+
import { NamedTheme } from './NamedTheme'
|
4
6
|
|
5
7
|
type ThemeProps = {
|
6
|
-
name: keyof UnistylesThemes
|
8
|
+
name: keyof UnistylesThemes,
|
9
|
+
invertedAdaptive?: boolean
|
10
|
+
} | {
|
11
|
+
name?: undefined,
|
12
|
+
invertedAdaptive: true
|
7
13
|
}
|
8
14
|
|
9
|
-
const
|
10
|
-
|
15
|
+
export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({
|
16
|
+
name,
|
17
|
+
children,
|
18
|
+
invertedAdaptive
|
19
|
+
}) => {
|
20
|
+
const hasAdaptiveThemes = UnistylesRuntime.hasAdaptiveThemes
|
21
|
+
const isAdaptiveTheme = invertedAdaptive && hasAdaptiveThemes
|
11
22
|
|
12
|
-
|
13
|
-
|
14
|
-
}
|
23
|
+
if (invertedAdaptive && !hasAdaptiveThemes) {
|
24
|
+
return children
|
25
|
+
}
|
15
26
|
|
16
|
-
|
17
|
-
|
27
|
+
if (!invertedAdaptive && !name) {
|
28
|
+
if (__DEV__) {
|
29
|
+
console.error('ScopedTheme: name or invertedAdaptive must be provided')
|
30
|
+
}
|
31
|
+
|
32
|
+
return null
|
33
|
+
}
|
18
34
|
|
19
|
-
export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({ name, children }) => {
|
20
35
|
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
|
37
|
+
return isAdaptiveTheme
|
38
|
+
? (
|
39
|
+
<AdaptiveTheme previousScopedTheme={previousScopedTheme}>
|
40
|
+
{children}
|
41
|
+
</AdaptiveTheme>
|
42
|
+
)
|
43
|
+
: (
|
44
|
+
<NamedTheme
|
45
|
+
name={name as keyof UnistylesThemes}
|
46
|
+
previousScopedTheme={previousScopedTheme}
|
47
|
+
>
|
48
|
+
{children}
|
49
|
+
</NamedTheme>
|
50
|
+
)
|
51
|
+
|
32
52
|
}
|
@@ -1,49 +1,39 @@
|
|
1
|
-
import React, {
|
1
|
+
import React, { useRef } from 'react'
|
2
|
+
import type { ScrollView } from 'react-native'
|
2
3
|
import { UnistylesShadowRegistry } from '../specs'
|
3
4
|
import { copyComponentProperties } from '../utils'
|
4
5
|
import { passForwardedRef } from './passForwardRef'
|
5
6
|
import { maybeWarnAboutMultipleUnistyles } from './warn'
|
6
7
|
|
7
|
-
const getNativeRef = (Component: any, ref: any) => {
|
8
|
-
switch (Component.name) {
|
9
|
-
case 'KeyboardAvoidingView':
|
10
|
-
return ref.viewRef?.current
|
11
|
-
case 'FlatList':
|
12
|
-
return ref.getNativeScrollRef?.()
|
13
|
-
case 'VirtualizedList':
|
14
|
-
return ref.getScrollRef?.()
|
15
|
-
default:
|
16
|
-
return ref
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
8
|
export const createUnistylesElement = (Component: any) => {
|
21
|
-
const UnistylesComponent =
|
22
|
-
const
|
23
|
-
|
24
|
-
useLayoutEffect(() => {
|
25
|
-
return () => {
|
26
|
-
if (storedRef.current) {
|
27
|
-
// @ts-ignore
|
28
|
-
UnistylesShadowRegistry.remove(storedRef.current)
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}, [])
|
9
|
+
const UnistylesComponent = (props: any) => {
|
10
|
+
const scrollViewRef = useRef<ScrollView>(null)
|
32
11
|
|
33
12
|
return (
|
34
13
|
<Component
|
35
14
|
{...props}
|
36
15
|
ref={(ref: unknown) => {
|
37
|
-
|
38
|
-
|
16
|
+
maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
|
17
|
+
|
18
|
+
// https://github.com/facebook/react-native/issues/51878
|
19
|
+
// tested with ScrollView, REA ScrolLView and Animated ScrollView
|
20
|
+
const isScrollView = Component.displayName === 'ScrollView'
|
21
|
+
|
22
|
+
if (isScrollView && ref) {
|
23
|
+
scrollViewRef.current = ref as ScrollView
|
39
24
|
}
|
40
25
|
|
41
|
-
|
42
|
-
|
26
|
+
if (isScrollView && !ref) {
|
27
|
+
// @ts-ignore this is hidden from TS
|
28
|
+
UnistylesShadowRegistry.remove(scrollViewRef.current)
|
29
|
+
scrollViewRef.current = null
|
30
|
+
|
31
|
+
return
|
32
|
+
}
|
43
33
|
|
44
34
|
return passForwardedRef(
|
45
35
|
ref,
|
46
|
-
|
36
|
+
props.ref,
|
47
37
|
() => {
|
48
38
|
// @ts-ignore this is hidden from TS
|
49
39
|
UnistylesShadowRegistry.add(ref, props.style)
|
@@ -56,7 +46,7 @@ export const createUnistylesElement = (Component: any) => {
|
|
56
46
|
}}
|
57
47
|
/>
|
58
48
|
)
|
59
|
-
}
|
49
|
+
}
|
60
50
|
|
61
51
|
return copyComponentProperties(Component, UnistylesComponent)
|
62
52
|
}
|
@@ -34,14 +34,14 @@ const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef
|
|
34
34
|
}
|
35
35
|
|
36
36
|
export const createUnistylesElement = (Component: any) => {
|
37
|
-
const UnistylesComponent =
|
37
|
+
const UnistylesComponent = (props: any) => {
|
38
38
|
return (
|
39
39
|
<Component
|
40
40
|
{...props}
|
41
|
-
{...buildUnistylesProps(Component, props,
|
41
|
+
{...buildUnistylesProps(Component, props, props.ref)}
|
42
42
|
/>
|
43
43
|
)
|
44
|
-
}
|
44
|
+
}
|
45
45
|
|
46
46
|
return copyComponentProperties(Component, UnistylesComponent)
|
47
47
|
}
|
@@ -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
|
+
}
|
@@ -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()
|
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,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { useEffect } from 'react'
|
2
|
+
import { type SharedValue, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
|
4
|
+
import type { UnistylesTheme } from '../types'
|
5
|
+
|
6
|
+
export const useAnimatedTheme = () => {
|
7
|
+
const theme = useSharedValue(UnistylesRuntime.getTheme())
|
8
|
+
|
9
|
+
useEffect(() => {
|
10
|
+
// @ts-ignore this is hidden from TS
|
11
|
+
const dispose = StyleSheet.addChangeListener(changedDependencies => {
|
12
|
+
if (changedDependencies.includes(UnistyleDependency.Theme)) {
|
13
|
+
theme.set(UnistylesRuntime.getTheme())
|
14
|
+
}
|
15
|
+
})
|
16
|
+
|
17
|
+
return () => dispose()
|
18
|
+
}, [])
|
19
|
+
|
20
|
+
return theme as SharedValue<UnistylesTheme>
|
21
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { useEffect } from 'react'
|
2
|
+
import { type SharedValue, useSharedValue } from 'react-native-reanimated'
|
3
|
+
import { UnistyleDependency, UnistylesRuntime } from '../specs'
|
4
|
+
import type { UnistylesTheme } from '../types'
|
5
|
+
import { services } from '../web/services'
|
6
|
+
|
7
|
+
export const useAnimatedTheme = () => {
|
8
|
+
const theme = useSharedValue(UnistylesRuntime.getTheme())
|
9
|
+
|
10
|
+
useEffect(() => {
|
11
|
+
const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => theme.set(UnistylesRuntime.getTheme()))
|
12
|
+
|
13
|
+
return () => {
|
14
|
+
dispose()
|
15
|
+
}
|
16
|
+
}, [])
|
17
|
+
|
18
|
+
return theme as SharedValue<UnistylesTheme>
|
19
|
+
}
|
@@ -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
|
+
}
|