react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.21
Sign up to get free protection for your applications and to get access to all the features.
- package/Unistyles.podspec +3 -2
- package/cxx/common/Constants.h +3 -0
- package/cxx/common/Helpers.h +97 -5
- package/cxx/core/HostStyle.cpp +19 -13
- package/cxx/core/HostStyle.h +4 -0
- package/cxx/core/StyleSheet.h +0 -2
- package/cxx/core/StyleSheetRegistry.cpp +10 -13
- package/cxx/core/StyleSheetRegistry.h +4 -4
- package/cxx/core/Unistyle.h +7 -10
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +58 -10
- package/cxx/core/UnistylesCommitHook.cpp +22 -13
- package/cxx/core/UnistylesCommitHook.h +8 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +37 -0
- package/cxx/core/UnistylesMountHook.h +31 -0
- package/cxx/core/UnistylesRegistry.cpp +56 -81
- package/cxx/core/UnistylesRegistry.h +15 -13
- package/cxx/core/UnistylesState.cpp +14 -8
- package/cxx/core/UnistylesState.h +1 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +15 -9
- package/cxx/hybridObjects/HybridStyleSheet.cpp +43 -38
- package/cxx/hybridObjects/HybridStyleSheet.h +10 -7
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +35 -16
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +105 -164
- package/cxx/parser/Parser.h +8 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +33 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +13 -11
- package/cxx/shadowTree/ShadowTreeManager.h +1 -0
- package/ios/Unistyles.h +1 -0
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/lib/commonjs/index.js +4 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +7 -6
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +51 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/createUnistylesComponent.js +61 -0
- package/lib/commonjs/web/createUnistylesComponent.js.map +1 -0
- package/lib/commonjs/web/index.js +60 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +20 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listenToDependencies.js +38 -0
- package/lib/commonjs/web/listener/listenToDependencies.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +35 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +28 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +10 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +50 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +163 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/shadowRegistry.js +123 -0
- package/lib/commonjs/web/shadowRegistry.js.map +1 -0
- package/lib/commonjs/web/state.js +81 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +130 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +59 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NavigtionBar/index.js +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +7 -6
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +46 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/createUnistylesComponent.js +54 -0
- package/lib/module/web/createUnistylesComponent.js.map +1 -0
- package/lib/module/web/index.js +26 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +5 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listenToDependencies.js +33 -0
- package/lib/module/web/listener/listenToDependencies.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +24 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +5 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +46 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +159 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +119 -0
- package/lib/module/web/shadowRegistry.js.map +1 -0
- package/lib/module/web/state.js +77 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +112 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +54 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +12 -0
- package/lib/typescript/example/Typography.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/explore.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/explore.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/index.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/index.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/+html.d.ts +4 -0
- package/lib/typescript/expo-example/app/+html.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/+not-found.d.ts +3 -0
- package/lib/typescript/expo-example/app/+not-found.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/_layout.d.ts +3 -0
- package/lib/typescript/expo-example/app/_layout.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +2 -2
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
- package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/index.d.ts +14 -13
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts +3 -0
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
- package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/src/web/mock.d.ts +5 -0
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts +6 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/src/web/registry.d.ts +15 -0
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -9
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/src/web/utils.d.ts +35 -0
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
- package/package.json +3 -3
- package/plugin/__tests__/dependencies.spec.js +199 -111
- package/plugin/__tests__/ref.spec.js +638 -202
- package/plugin/__tests__/stylesheet.spec.js +182 -71
- package/plugin/index.js +110 -23
- package/plugin/ref.js +64 -13
- package/plugin/style.js +82 -22
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/index.ts +3 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +10 -9
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +2 -2
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +2 -2
- package/{web → src/web}/convert/types.ts +1 -1
- package/src/web/create.ts +50 -0
- package/src/web/createUnistylesComponent.tsx +54 -0
- package/{web → src/web}/index.ts +3 -2
- package/src/web/listener/index.ts +2 -0
- package/src/web/listener/listenToDependencies.ts +45 -0
- package/{web → src/web}/listener/listener.ts +2 -2
- package/{web → src/web}/mock.ts +2 -12
- package/src/web/pseudo.ts +137 -0
- package/src/web/registry.ts +60 -0
- package/{web → src/web}/runtime.ts +4 -6
- package/src/web/shadowRegistry.ts +124 -0
- package/{web → src/web}/state.ts +5 -49
- package/{web → src/web}/utils.ts +91 -17
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/src/web/variants/useVariants.ts +65 -0
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts +0 -2
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts +0 -14
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts +0 -4
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts +0 -12
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts +0 -18
- package/lib/typescript/web/utils.d.ts.map +0 -1
- package/web/create.ts +0 -102
- package/web/listener/index.ts +0 -1
- package/web/pseudo.ts +0 -11
- package/web/registry.ts +0 -41
- package/web/useVariants.ts +0 -99
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
package/plugin/ref.js
CHANGED
@@ -14,21 +14,39 @@ function hasStringRef(t, path) {
|
|
14
14
|
)
|
15
15
|
}
|
16
16
|
|
17
|
-
function
|
17
|
+
function memberExpressionFromArray(t, identifiers) {
|
18
|
+
// possible for inline styles
|
19
|
+
if (identifiers.length === 0) {
|
20
|
+
return undefined
|
21
|
+
}
|
22
|
+
|
23
|
+
const [base, ...members] = identifiers
|
24
|
+
|
25
|
+
return members.reduce((object, property) => t.memberExpression(object, t.identifier(property)), t.identifier(base))
|
26
|
+
}
|
27
|
+
|
28
|
+
function addRef(t, path, metadata, state) {
|
29
|
+
const hasVariants = state.file.hasVariants
|
30
|
+
|
18
31
|
const newRefFunction = t.arrowFunctionExpression(
|
19
32
|
[t.identifier('ref')],
|
20
33
|
t.blockStatement([
|
21
34
|
t.expressionStatement(
|
22
35
|
t.callExpression(
|
23
36
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
24
|
-
[
|
37
|
+
[
|
38
|
+
t.identifier('ref'),
|
39
|
+
memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
|
40
|
+
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
41
|
+
metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
|
42
|
+
]
|
25
43
|
)
|
26
44
|
),
|
27
45
|
t.returnStatement(
|
28
46
|
t.arrowFunctionExpression([],
|
29
47
|
t.callExpression(
|
30
48
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
31
|
-
[t.identifier('ref')
|
49
|
+
[t.identifier('ref')]
|
32
50
|
)
|
33
51
|
)
|
34
52
|
)
|
@@ -43,7 +61,8 @@ function addRef(t, path, styleObj, styleProp) {
|
|
43
61
|
path.node.openingElement.attributes.push(newRefProp)
|
44
62
|
}
|
45
63
|
|
46
|
-
function overrideRef(t, path, refProp,
|
64
|
+
function overrideRef(t, path, refProp, metadata, state) {
|
65
|
+
const hasVariants = state.file.hasVariants
|
47
66
|
const uniqueRefName = path.scope.generateUidIdentifier('ref').name
|
48
67
|
const isIdentifier = t.isIdentifier(refProp.value.expression)
|
49
68
|
const binding = path.scope.getBinding(refProp.value.expression.name)
|
@@ -55,19 +74,30 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
|
|
55
74
|
[t.identifier(uniqueRefName)],
|
56
75
|
t.blockStatement([
|
57
76
|
t.expressionStatement(
|
58
|
-
t.assignmentExpression(
|
77
|
+
t.assignmentExpression(
|
78
|
+
'=',
|
79
|
+
t.memberExpression(t.identifier(userVariableName), t.identifier('current')),
|
80
|
+
t.identifier(uniqueRefName)
|
81
|
+
)
|
59
82
|
),
|
60
83
|
t.expressionStatement(
|
61
84
|
t.callExpression(
|
62
85
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
63
|
-
[
|
86
|
+
[
|
87
|
+
t.identifier(uniqueRefName),
|
88
|
+
memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
|
89
|
+
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
90
|
+
metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
|
91
|
+
]
|
64
92
|
)
|
65
93
|
),
|
66
94
|
t.returnStatement(
|
67
95
|
t.arrowFunctionExpression([],
|
68
96
|
t.callExpression(
|
69
97
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
70
|
-
[
|
98
|
+
[
|
99
|
+
t.identifier(uniqueRefName)
|
100
|
+
]
|
71
101
|
)
|
72
102
|
)
|
73
103
|
)
|
@@ -87,15 +117,23 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
|
|
87
117
|
const userCleanupFunction = userReturnStatement
|
88
118
|
? userReturnStatement.argument
|
89
119
|
: null
|
120
|
+
const userRefName = refProp.value.expression.params.length >= 1
|
121
|
+
? refProp.value.expression.params.at(0).name
|
122
|
+
: 'ref'
|
90
123
|
|
91
124
|
const newRefFunction = t.arrowFunctionExpression(
|
92
|
-
[t.identifier(
|
125
|
+
[t.identifier(userRefName)],
|
93
126
|
t.blockStatement([
|
94
127
|
...userStatements.filter(statement => !t.isReturnStatement(statement)),
|
95
128
|
t.expressionStatement(
|
96
129
|
t.callExpression(
|
97
130
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
98
|
-
[
|
131
|
+
[
|
132
|
+
t.identifier(userRefName),
|
133
|
+
memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
|
134
|
+
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
135
|
+
metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
|
136
|
+
]
|
99
137
|
)
|
100
138
|
),
|
101
139
|
// Merged cleanup function
|
@@ -109,7 +147,9 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
|
|
109
147
|
t.expressionStatement(
|
110
148
|
t.callExpression(
|
111
149
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
112
|
-
[
|
150
|
+
[
|
151
|
+
t.identifier(userRefName)
|
152
|
+
]
|
113
153
|
)
|
114
154
|
)
|
115
155
|
]))
|
@@ -122,6 +162,10 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
|
|
122
162
|
return
|
123
163
|
}
|
124
164
|
|
165
|
+
if (!binding) {
|
166
|
+
return
|
167
|
+
}
|
168
|
+
|
125
169
|
// ref={scopedFunction}
|
126
170
|
const isArrowFunction = t.isArrowFunctionExpression(binding.path.node.init)
|
127
171
|
const isFunction = t.isFunctionDeclaration(binding.path.node)
|
@@ -146,7 +190,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
|
|
146
190
|
t.expressionStatement(
|
147
191
|
t.callExpression(
|
148
192
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
149
|
-
[
|
193
|
+
[
|
194
|
+
t.identifier(uniqueRefName),
|
195
|
+
memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
|
196
|
+
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
197
|
+
metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
|
198
|
+
]
|
150
199
|
)
|
151
200
|
),
|
152
201
|
t.returnStatement(
|
@@ -159,10 +208,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
|
|
159
208
|
t.expressionStatement(
|
160
209
|
t.callExpression(
|
161
210
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
162
|
-
[
|
211
|
+
[
|
212
|
+
t.identifier(uniqueRefName)
|
213
|
+
]
|
163
214
|
)
|
164
215
|
)
|
165
|
-
]))
|
216
|
+
].filter(Boolean)))
|
166
217
|
)
|
167
218
|
])
|
168
219
|
)
|
package/plugin/style.js
CHANGED
@@ -1,44 +1,69 @@
|
|
1
|
-
function
|
1
|
+
function getStyleMetadata(t, node, dynamicFunction = null) {
|
2
2
|
// {styles.container}
|
3
3
|
if (t.isMemberExpression(node)) {
|
4
|
-
|
4
|
+
const members = t.isMemberExpression(node.object)
|
5
|
+
? [node.object.object.name, node.object.property.name, node.property.name]
|
6
|
+
: [node.object.name, node.property.name]
|
7
|
+
|
8
|
+
return [
|
9
|
+
{
|
10
|
+
members: members.filter(Boolean),
|
11
|
+
inlineStyle: undefined,
|
12
|
+
dynamicFunction
|
13
|
+
}
|
14
|
+
]
|
5
15
|
}
|
6
16
|
|
7
17
|
// [styles.container]
|
8
18
|
if (t.isArrayExpression(node)) {
|
9
|
-
return node.elements.flatMap(element =>
|
19
|
+
return node.elements.flatMap(element => getStyleMetadata(t, element))
|
10
20
|
}
|
11
21
|
|
12
22
|
// [...styles.container]
|
13
23
|
if (t.isSpreadElement(node)) {
|
14
|
-
return
|
24
|
+
return getStyleMetadata(t, node.argument)
|
15
25
|
}
|
16
26
|
|
17
27
|
// {{ ...styles.container }}
|
18
28
|
if (t.isObjectExpression(node)) {
|
19
|
-
|
20
|
-
}
|
29
|
+
const inlineStyles = []
|
21
30
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
const partialResult = node
|
32
|
+
.properties
|
33
|
+
.flatMap(prop => {
|
34
|
+
// handle inline styles
|
35
|
+
if (t.isObjectProperty(prop)) {
|
36
|
+
inlineStyles.push(prop)
|
26
37
|
|
27
|
-
|
28
|
-
|
29
|
-
}
|
38
|
+
return null
|
39
|
+
}
|
30
40
|
|
31
|
-
|
32
|
-
|
33
|
-
|
41
|
+
return getStyleMetadata(t, prop.argument)
|
42
|
+
})
|
43
|
+
.filter(Boolean)
|
34
44
|
|
35
|
-
|
45
|
+
if (inlineStyles.length > 0) {
|
46
|
+
return partialResult.concat([{
|
47
|
+
members: [],
|
48
|
+
inlineStyle: t.objectExpression(inlineStyles),
|
49
|
+
dynamicFunction: undefined
|
50
|
+
}])
|
36
51
|
}
|
37
52
|
|
38
|
-
|
39
|
-
|
53
|
+
return partialResult
|
54
|
+
}
|
40
55
|
|
41
|
-
|
56
|
+
// {styles.container(arg1, arg2)}
|
57
|
+
if (t.isCallExpression(node)) {
|
58
|
+
return getStyleMetadata(t, node.callee, node)
|
59
|
+
}
|
60
|
+
|
61
|
+
if (t.isIdentifier(node)) {
|
62
|
+
return [{
|
63
|
+
members: [node.name],
|
64
|
+
inlineStyle: undefined,
|
65
|
+
dynamicFunction: undefined
|
66
|
+
}]
|
42
67
|
}
|
43
68
|
|
44
69
|
return []
|
@@ -52,7 +77,42 @@ function getStyleAttribute(t, path) {
|
|
52
77
|
)
|
53
78
|
}
|
54
79
|
|
80
|
+
function styleAttributeToArray(t, path) {
|
81
|
+
const styleAttribute = getStyleAttribute(t, path)
|
82
|
+
|
83
|
+
// {{...style.container, ...style.container}}
|
84
|
+
if (t.isObjectExpression(styleAttribute.value.expression)) {
|
85
|
+
const properties = styleAttribute.value.expression.properties
|
86
|
+
.map(property => t.isSpreadElement(property)
|
87
|
+
? property.argument
|
88
|
+
: t.objectExpression([property])
|
89
|
+
)
|
90
|
+
|
91
|
+
styleAttribute.value.expression = t.arrayExpression(properties)
|
92
|
+
|
93
|
+
return
|
94
|
+
}
|
95
|
+
|
96
|
+
// [{...style.container, ...style.container}]
|
97
|
+
if (t.isArrayExpression(styleAttribute.value.expression)) {
|
98
|
+
const properties = styleAttribute.value.expression.elements
|
99
|
+
.flatMap(property => {
|
100
|
+
if (t.isSpreadElement(property)) {
|
101
|
+
return property.argument
|
102
|
+
}
|
103
|
+
return property
|
104
|
+
})
|
105
|
+
|
106
|
+
styleAttribute.value.expression = t.arrayExpression(properties)
|
107
|
+
|
108
|
+
return
|
109
|
+
}
|
110
|
+
|
111
|
+
styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
|
112
|
+
}
|
113
|
+
|
55
114
|
module.exports = {
|
56
|
-
|
57
|
-
getStyleAttribute
|
115
|
+
getStyleMetadata,
|
116
|
+
getStyleAttribute,
|
117
|
+
styleAttributeToArray
|
58
118
|
}
|
package/plugin/stylesheet.js
CHANGED
@@ -17,6 +17,19 @@ const UnistyleDependency = {
|
|
17
17
|
NavigationBar: 13
|
18
18
|
}
|
19
19
|
|
20
|
+
function stringToUniqueId(str) {
|
21
|
+
let hash = 0;
|
22
|
+
|
23
|
+
for (let i = 0; i < str.length; i++) {
|
24
|
+
hash = (hash << 5) - hash + str.charCodeAt(i)
|
25
|
+
hash |= 0
|
26
|
+
}
|
27
|
+
|
28
|
+
const absHash = Math.abs(hash)
|
29
|
+
|
30
|
+
return absHash % 1000000000
|
31
|
+
}
|
32
|
+
|
20
33
|
function isUnistylesStyleSheet(t, path, state) {
|
21
34
|
const callee = path.get('callee')
|
22
35
|
|
@@ -28,6 +41,13 @@ function isUnistylesStyleSheet(t, path, state) {
|
|
28
41
|
)
|
29
42
|
}
|
30
43
|
|
44
|
+
function addStyleSheetTag(t, path, state) {
|
45
|
+
const callee = path.get('callee')
|
46
|
+
const uniqueId = stringToUniqueId(state.filename) + ++state.file.tagNumber
|
47
|
+
|
48
|
+
callee.container.arguments.push(t.numericLiteral(uniqueId))
|
49
|
+
}
|
50
|
+
|
31
51
|
function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
|
32
52
|
const debugMessage = deps => {
|
33
53
|
if (state.opts.debug) {
|
@@ -141,7 +161,30 @@ function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
|
|
141
161
|
}
|
142
162
|
}
|
143
163
|
|
164
|
+
function getUnistyle(t, property) {
|
165
|
+
const propertyValue = t.isArrowFunctionExpression(property.value)
|
166
|
+
? property.value.body
|
167
|
+
: property.value
|
168
|
+
|
169
|
+
if (t.isObjectExpression(propertyValue)) {
|
170
|
+
return propertyValue
|
171
|
+
}
|
172
|
+
|
173
|
+
if (t.isBlockStatement(propertyValue)) {
|
174
|
+
const returnStatement = propertyValue.body
|
175
|
+
.find(value => t.isReturnStatement(value))
|
176
|
+
|
177
|
+
return returnStatement
|
178
|
+
? returnStatement.argument
|
179
|
+
: null
|
180
|
+
}
|
181
|
+
|
182
|
+
return null
|
183
|
+
}
|
184
|
+
|
144
185
|
module.exports = {
|
145
186
|
isUnistylesStyleSheet,
|
146
|
-
analyzeDependencies
|
187
|
+
analyzeDependencies,
|
188
|
+
addStyleSheetTag,
|
189
|
+
getUnistyle
|
147
190
|
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
function isUsingVariants(t, path) {
|
2
|
+
const callee = path.get('callee')
|
3
|
+
|
4
|
+
return (
|
5
|
+
t.isMemberExpression(callee) &&
|
6
|
+
t.isIdentifier(callee.node.object, { name: 'styles' }) &&
|
7
|
+
t.isIdentifier(callee.node.property, { name: 'useVariants' }) &&
|
8
|
+
t.isObjectExpression(path.node.arguments[0])
|
9
|
+
)
|
10
|
+
}
|
11
|
+
|
12
|
+
function extractVariants(t, path, state) {
|
13
|
+
const arg = path.node.arguments[0]
|
14
|
+
|
15
|
+
const variantDeclaration = t.variableDeclaration('const', [
|
16
|
+
t.variableDeclarator(
|
17
|
+
t.identifier('__uni__variants'),
|
18
|
+
arg
|
19
|
+
)
|
20
|
+
])
|
21
|
+
|
22
|
+
// Replace useVariants argument with __uni__variants
|
23
|
+
path.node.arguments[0] = t.identifier('__uni__variants')
|
24
|
+
|
25
|
+
path.insertBefore(variantDeclaration)
|
26
|
+
|
27
|
+
state.file.hasVariants = true
|
28
|
+
}
|
29
|
+
|
30
|
+
module.exports = {
|
31
|
+
isUsingVariants,
|
32
|
+
extractVariants
|
33
|
+
}
|
package/src/index.ts
CHANGED
@@ -3,6 +3,9 @@ import React from 'react'
|
|
3
3
|
export * from './specs'
|
4
4
|
export { mq } from './mq'
|
5
5
|
export type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
6
|
+
// TODO: export Native createUnistylesComponent
|
7
|
+
// can't import it this way, it will break native build
|
8
|
+
// export { createUnistylesComponent } from './web/createUnistylesComponent'
|
6
9
|
|
7
10
|
// todo verify true min version
|
8
11
|
const minReactVersionRequiredByUnistyles = '18.3.1'
|
@@ -12,7 +12,7 @@ export const attachNavigationBarJSMethods = (hybridObject: UnistylesNavigationBa
|
|
12
12
|
|
13
13
|
privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
|
14
14
|
hybridObject.setBackgroundColor = (color?: string) => {
|
15
|
-
const parsedColor = processColor(color)
|
15
|
+
const parsedColor = processColor(color) ?? 0
|
16
16
|
|
17
17
|
privateHybrid._setBackgroundColor(parsedColor as number)
|
18
18
|
}
|
@@ -4,11 +4,11 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
|
|
4
4
|
|
5
5
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
6
6
|
// Babel API
|
7
|
-
add(handle?: ViewHandle, style?: Unistyle): void,
|
7
|
+
add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
|
8
8
|
remove(handle?: ViewHandle, style?: Unistyle): void,
|
9
9
|
// JSI
|
10
|
-
link(node: ShadowNode, style
|
11
|
-
unlink(node: ShadowNode
|
10
|
+
link(node: ShadowNode, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
|
11
|
+
unlink(node: ShadowNode): void
|
12
12
|
}
|
13
13
|
|
14
14
|
const HybridShadowRegistry = NitroModules.createHybridObject<ShadowRegistry>('UnistylesShadowRegistry')
|
@@ -26,20 +26,21 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
26
26
|
return node
|
27
27
|
}
|
28
28
|
|
29
|
-
HybridShadowRegistry.add = (handle, style) => {
|
30
|
-
|
29
|
+
HybridShadowRegistry.add = (handle, style, variants, args) => {
|
30
|
+
// virtualized nodes can be null
|
31
|
+
if (!handle || !style) {
|
31
32
|
return
|
32
33
|
}
|
33
34
|
|
34
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style)
|
35
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? [])
|
35
36
|
}
|
36
37
|
|
37
|
-
HybridShadowRegistry.remove =
|
38
|
-
if (!handle
|
38
|
+
HybridShadowRegistry.remove = handle => {
|
39
|
+
if (!handle) {
|
39
40
|
return
|
40
41
|
}
|
41
42
|
|
42
|
-
HybridShadowRegistry.unlink(findShadowNodeForHandle(handle)
|
43
|
+
HybridShadowRegistry.unlink(findShadowNodeForHandle(handle))
|
43
44
|
}
|
44
45
|
|
45
46
|
type PrivateMethods =
|
@@ -34,7 +34,7 @@ export const attachStatusBarJSMethods = (hybridObject: UnistylesStatusBar) => {
|
|
34
34
|
|
35
35
|
privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
|
36
36
|
hybridObject.setBackgroundColor = (color?: string) => {
|
37
|
-
const parsedColor = processColor(color)
|
37
|
+
const parsedColor = processColor(color) ?? 0
|
38
38
|
|
39
39
|
privateHybrid._setBackgroundColor(parsedColor as number)
|
40
40
|
}
|
@@ -41,4 +41,6 @@ HybridUnistylesStyleSheet.jsMethods = {
|
|
41
41
|
processColor
|
42
42
|
}
|
43
43
|
|
44
|
-
|
44
|
+
type PrivateMethods = 'jsMethods'
|
45
|
+
|
46
|
+
export const StyleSheet = HybridUnistylesStyleSheet as Omit<UnistylesStyleSheet, PrivateMethods>
|
@@ -45,7 +45,7 @@ HybridUnistylesRuntime.navigationBar = HybridUnistylesRuntime.createHybridNaviga
|
|
45
45
|
HybridUnistylesRuntime._setRootViewBackgroundColor = HybridUnistylesRuntime.setRootViewBackgroundColor
|
46
46
|
|
47
47
|
HybridUnistylesRuntime.setRootViewBackgroundColor = (color?: string) => {
|
48
|
-
const parsedColor = processColor(color)
|
48
|
+
const parsedColor = processColor(color) ?? 0
|
49
49
|
|
50
50
|
HybridUnistylesRuntime._setRootViewBackgroundColor(parsedColor as number)
|
51
51
|
}
|
package/src/specs/index.web.ts
CHANGED
package/src/types/stylesheet.ts
CHANGED
@@ -5,7 +5,7 @@ import type { UnistylesMiniRuntime } from '../specs'
|
|
5
5
|
import type { ReactNativeStyleSheet } from './breakpoints'
|
6
6
|
import type { ExtractVariantNames } from './variants'
|
7
7
|
import type { CSSProperties } from 'react'
|
8
|
-
import type { Pseudo } from '
|
8
|
+
import type { Pseudo } from '../web/pseudo'
|
9
9
|
|
10
10
|
// these props are treated differently to nest breakpoints and media queries
|
11
11
|
type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
|
@@ -27,7 +27,7 @@ type VariantsObject = {
|
|
27
27
|
}
|
28
28
|
|
29
29
|
type CustomClassName = {
|
30
|
-
|
30
|
+
_classNames?: string | Array<string>
|
31
31
|
}
|
32
32
|
|
33
33
|
type CompoundVariant = {
|
@@ -2,7 +2,7 @@ import type { MediaQuery } from 'typestyle/lib/types'
|
|
2
2
|
import { UnistylesState } from '../state'
|
3
3
|
import { keyInObject } from '../utils'
|
4
4
|
import { isUnistylesMq, parseMq } from '../mq'
|
5
|
-
import { Orientation } from '../../
|
5
|
+
import { Orientation } from '../../specs/types'
|
6
6
|
|
7
7
|
export const convertBreakpoint = (breakpoint: string): MediaQuery => {
|
8
8
|
if (Object.values(Orientation).includes(breakpoint as Orientation)) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { NestedCSSProperties } from 'typestyle/lib/types'
|
2
|
-
import type { UnistylesValues } from '../../
|
2
|
+
import type { UnistylesValues } from '../../types'
|
3
3
|
import { media } from 'typestyle'
|
4
4
|
import { isPseudo } from '../pseudo'
|
5
5
|
import { convertBreakpoint } from './breakpoint'
|
@@ -21,7 +21,7 @@ export const convertToTypeStyle = (value: UnistylesValues) => {
|
|
21
21
|
...value._web
|
22
22
|
}).flatMap(([unistylesKey, unistylesValue]) => {
|
23
23
|
// Keys to omit
|
24
|
-
if (['
|
24
|
+
if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies', '__unistyles-secrets__'].includes(unistylesKey) || unistylesKey.startsWith('variant-')) {
|
25
25
|
return []
|
26
26
|
}
|
27
27
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { TextStyle, ViewStyle } from 'react-native'
|
2
|
-
import type { ToDeepUnistyles } from '../../
|
2
|
+
import type { ToDeepUnistyles } from '../../types/stylesheet'
|
3
3
|
|
4
4
|
export type ShadowOffset = ToDeepUnistyles<{ width: number, height: number }>
|
5
5
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import type { ReactNativeStyleSheet } from '../types'
|
2
|
+
import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
|
3
|
+
import { assignSecrets, reduceObject, getStyles } from './utils'
|
4
|
+
import { UnistylesRuntime } from './runtime'
|
5
|
+
import { createUseVariants, getVariants } from './variants'
|
6
|
+
|
7
|
+
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
8
|
+
const computedStylesheet = typeof stylesheet === 'function'
|
9
|
+
? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
|
10
|
+
: stylesheet
|
11
|
+
const selectedVariants = new Map<string, any>()
|
12
|
+
|
13
|
+
const copyVariants = () => Object.fromEntries(selectedVariants.entries())
|
14
|
+
const addSecrets = (value: any, key: string, args?: Array<any>) => assignSecrets(value, {
|
15
|
+
__uni__key: key,
|
16
|
+
__uni__refs: new Set(),
|
17
|
+
__uni__stylesheet: stylesheet,
|
18
|
+
__uni__args: args,
|
19
|
+
__uni__variants: copyVariants()
|
20
|
+
})
|
21
|
+
|
22
|
+
const styles = reduceObject(computedStylesheet, (value, _key) => {
|
23
|
+
const key = String(_key)
|
24
|
+
|
25
|
+
if (typeof value === 'function') {
|
26
|
+
const dynamicStyle = (...args: Array<any>) => {
|
27
|
+
const result = value(...args)
|
28
|
+
const variants = Object.fromEntries(getVariants({ [key]: result } as ReactNativeStyleSheet<StyleSheet>, copyVariants()))
|
29
|
+
const resultWithVariants = {
|
30
|
+
...result,
|
31
|
+
...variants[key]
|
32
|
+
}
|
33
|
+
|
34
|
+
// Add secrets to result of dynamic styles function
|
35
|
+
return addSecrets(getStyles(resultWithVariants), key, args)
|
36
|
+
}
|
37
|
+
|
38
|
+
// Add secrets to dynamic styles function
|
39
|
+
return addSecrets(dynamicStyle, key)
|
40
|
+
}
|
41
|
+
|
42
|
+
// Add secrets to static styles
|
43
|
+
return addSecrets(getStyles(value), key)
|
44
|
+
}) as ReactNativeStyleSheet<StyleSheet>
|
45
|
+
|
46
|
+
// Inject useVariants hook to styles
|
47
|
+
createUseVariants(styles, newVariants => Object.entries(newVariants).forEach(([key, value]) => selectedVariants.set(key, value)))
|
48
|
+
|
49
|
+
return styles
|
50
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
2
|
+
import { extractHiddenProperties, extractSecrets } from './utils'
|
3
|
+
import { getVariants } from './variants'
|
4
|
+
import { UnistylesListener } from './listener'
|
5
|
+
import { UnistylesRegistry } from './registry'
|
6
|
+
|
7
|
+
const getStyles = (value: Record<string, any>) => {
|
8
|
+
const secrets = extractSecrets(value)
|
9
|
+
|
10
|
+
if (secrets.length === 0) {
|
11
|
+
return undefined
|
12
|
+
}
|
13
|
+
|
14
|
+
return secrets.reduce((acc, { __uni__stylesheet, __uni__key, __uni__args = [], __uni__variants }) => {
|
15
|
+
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
|
16
|
+
const style = newComputedStylesheet[__uni__key]
|
17
|
+
const resultHidden = typeof style === 'function'
|
18
|
+
? style(...__uni__args)
|
19
|
+
: style
|
20
|
+
const result = extractHiddenProperties(resultHidden)
|
21
|
+
const { variants } = Object.fromEntries(getVariants({ variants: result }, __uni__variants ))
|
22
|
+
const resultWithVariants = {
|
23
|
+
...result,
|
24
|
+
...variants
|
25
|
+
}
|
26
|
+
|
27
|
+
return {
|
28
|
+
...acc,
|
29
|
+
...resultWithVariants
|
30
|
+
}
|
31
|
+
}, {} as Record<string, any>)
|
32
|
+
}
|
33
|
+
|
34
|
+
export const createUnistylesComponent = <TProps extends object>(Component: React.ComponentType<TProps>) => (props: TProps) => {
|
35
|
+
const passedStyles = (props as TProps & { style: Record<string, any> }).style ?? {}
|
36
|
+
const [style, setStyle] = useState(getStyles(passedStyles))
|
37
|
+
|
38
|
+
useEffect(() => {
|
39
|
+
const newStyles = getStyles(passedStyles)
|
40
|
+
const dependencies = newStyles?.['uni__dependencies'] ?? []
|
41
|
+
const dispose = UnistylesListener.addListeners(dependencies, () => setStyle(getStyles(passedStyles)))
|
42
|
+
|
43
|
+
setStyle(newStyles)
|
44
|
+
|
45
|
+
return dispose
|
46
|
+
}, [passedStyles])
|
47
|
+
|
48
|
+
return (
|
49
|
+
<Component
|
50
|
+
{...props}
|
51
|
+
style={style}
|
52
|
+
/>
|
53
|
+
)
|
54
|
+
}
|