react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +2 -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 +78 -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/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
@@ -16,6 +16,7 @@ pluginTester({
|
|
16
16
|
{
|
17
17
|
title: 'Should not add dependencies to StyleSheet if user is not using theme or miniRuntime',
|
18
18
|
code: `
|
19
|
+
import { View, Text } from 'react-native'
|
19
20
|
import { StyleSheet } from 'react-native-unistyles'
|
20
21
|
|
21
22
|
export const Example = () => {
|
@@ -34,15 +35,16 @@ pluginTester({
|
|
34
35
|
`,
|
35
36
|
output: `
|
36
37
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
38
|
+
import { View, Text } from 'react-native'
|
37
39
|
import { StyleSheet } from 'react-native-unistyles'
|
38
40
|
|
39
41
|
export const Example = () => {
|
40
42
|
return (
|
41
43
|
<View
|
42
|
-
style={styles.container}
|
44
|
+
style={[styles.container]}
|
43
45
|
ref={ref => {
|
44
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
45
|
-
return () => UnistylesShadowRegistry.remove(ref
|
46
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
47
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
46
48
|
}}
|
47
49
|
>
|
48
50
|
<Text>Hello world</Text>
|
@@ -50,16 +52,20 @@ pluginTester({
|
|
50
52
|
)
|
51
53
|
}
|
52
54
|
|
53
|
-
const styles = StyleSheet.create(
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
const styles = StyleSheet.create(
|
56
|
+
{
|
57
|
+
container: {
|
58
|
+
backgroundColor: 'red'
|
59
|
+
}
|
60
|
+
},
|
61
|
+
793953373
|
62
|
+
)
|
58
63
|
`
|
59
64
|
},
|
60
65
|
{
|
61
66
|
title: 'Should add dependencies to StyleSheet if user is using theme',
|
62
67
|
code: `
|
68
|
+
import { View, Text } from 'react-native'
|
63
69
|
import { StyleSheet } from 'react-native-unistyles'
|
64
70
|
|
65
71
|
export const Example = () => {
|
@@ -78,15 +84,16 @@ pluginTester({
|
|
78
84
|
`,
|
79
85
|
output: `
|
80
86
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
87
|
+
import { View, Text } from 'react-native'
|
81
88
|
import { StyleSheet } from 'react-native-unistyles'
|
82
89
|
|
83
90
|
export const Example = () => {
|
84
91
|
return (
|
85
92
|
<View
|
86
|
-
style={styles.container}
|
93
|
+
style={[styles.container]}
|
87
94
|
ref={ref => {
|
88
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
89
|
-
return () => UnistylesShadowRegistry.remove(ref
|
95
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
96
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
90
97
|
}}
|
91
98
|
>
|
92
99
|
<Text>Hello world</Text>
|
@@ -94,17 +101,21 @@ pluginTester({
|
|
94
101
|
)
|
95
102
|
}
|
96
103
|
|
97
|
-
const styles = StyleSheet.create(
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
104
|
+
const styles = StyleSheet.create(
|
105
|
+
theme => ({
|
106
|
+
container: {
|
107
|
+
backgroundColor: theme.colors.background,
|
108
|
+
uni__dependencies: [0]
|
109
|
+
}
|
110
|
+
}),
|
111
|
+
793953373
|
112
|
+
)
|
103
113
|
`
|
104
114
|
},
|
105
115
|
{
|
106
116
|
title: 'Should add dependencies to StyleSheet even if user did rename import',
|
107
117
|
code: `
|
118
|
+
import { View, Text } from 'react-native'
|
108
119
|
import { StyleSheet as ST } from 'react-native-unistyles'
|
109
120
|
|
110
121
|
export const Example = () => {
|
@@ -123,15 +134,16 @@ pluginTester({
|
|
123
134
|
`,
|
124
135
|
output: `
|
125
136
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
137
|
+
import { View, Text } from 'react-native'
|
126
138
|
import { StyleSheet as ST } from 'react-native-unistyles'
|
127
139
|
|
128
140
|
export const Example = () => {
|
129
141
|
return (
|
130
142
|
<View
|
131
|
-
style={styles.container}
|
143
|
+
style={[styles.container]}
|
132
144
|
ref={ref => {
|
133
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
134
|
-
return () => UnistylesShadowRegistry.remove(ref
|
145
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
146
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
135
147
|
}}
|
136
148
|
>
|
137
149
|
<Text>Hello world</Text>
|
@@ -139,17 +151,21 @@ pluginTester({
|
|
139
151
|
)
|
140
152
|
}
|
141
153
|
|
142
|
-
const styles = ST.create(
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
154
|
+
const styles = ST.create(
|
155
|
+
theme => ({
|
156
|
+
container: {
|
157
|
+
backgroundColor: theme.colors.background,
|
158
|
+
uni__dependencies: [0]
|
159
|
+
}
|
160
|
+
}),
|
161
|
+
793953373
|
162
|
+
)
|
148
163
|
`
|
149
164
|
},
|
150
165
|
{
|
151
166
|
title: 'Should detect variants for object StyleSheet',
|
152
167
|
code: `
|
168
|
+
import { View, Text } from 'react-native'
|
153
169
|
import { StyleSheet } from 'react-native-unistyles'
|
154
170
|
|
155
171
|
export const Example = () => {
|
@@ -169,15 +185,16 @@ pluginTester({
|
|
169
185
|
`,
|
170
186
|
output: `
|
171
187
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
188
|
+
import { View, Text } from 'react-native'
|
172
189
|
import { StyleSheet } from 'react-native-unistyles'
|
173
190
|
|
174
191
|
export const Example = () => {
|
175
192
|
return (
|
176
193
|
<View
|
177
|
-
style={styles.container}
|
194
|
+
style={[styles.container]}
|
178
195
|
ref={ref => {
|
179
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
180
|
-
return () => UnistylesShadowRegistry.remove(ref
|
196
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
197
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
181
198
|
}}
|
182
199
|
>
|
183
200
|
<Text>Hello world</Text>
|
@@ -185,18 +202,22 @@ pluginTester({
|
|
185
202
|
)
|
186
203
|
}
|
187
204
|
|
188
|
-
const styles = StyleSheet.create(
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
205
|
+
const styles = StyleSheet.create(
|
206
|
+
{
|
207
|
+
container: {
|
208
|
+
backgroundColor: 'red',
|
209
|
+
variants: {},
|
210
|
+
uni__dependencies: [4]
|
211
|
+
}
|
212
|
+
},
|
213
|
+
793953373
|
214
|
+
)
|
195
215
|
`
|
196
216
|
},
|
197
217
|
{
|
198
218
|
title: 'Should detect variants for object StyleSheet and dynamic function',
|
199
219
|
code: `
|
220
|
+
import { View, Text } from 'react-native'
|
200
221
|
import { StyleSheet } from 'react-native-unistyles'
|
201
222
|
|
202
223
|
export const Example = () => {
|
@@ -216,15 +237,16 @@ pluginTester({
|
|
216
237
|
`,
|
217
238
|
output: `
|
218
239
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
240
|
+
import { View, Text } from 'react-native'
|
219
241
|
import { StyleSheet } from 'react-native-unistyles'
|
220
242
|
|
221
243
|
export const Example = () => {
|
222
244
|
return (
|
223
245
|
<View
|
224
|
-
style={styles.container}
|
246
|
+
style={[styles.container]}
|
225
247
|
ref={ref => {
|
226
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
227
|
-
return () => UnistylesShadowRegistry.remove(ref
|
248
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
249
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
228
250
|
}}
|
229
251
|
>
|
230
252
|
<Text>Hello world</Text>
|
@@ -232,18 +254,22 @@ pluginTester({
|
|
232
254
|
)
|
233
255
|
}
|
234
256
|
|
235
|
-
const styles = StyleSheet.create(
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
257
|
+
const styles = StyleSheet.create(
|
258
|
+
{
|
259
|
+
container: () => ({
|
260
|
+
backgroundColor: 'red',
|
261
|
+
variants: {},
|
262
|
+
uni__dependencies: [4]
|
263
|
+
})
|
264
|
+
},
|
265
|
+
793953373
|
266
|
+
)
|
242
267
|
`
|
243
268
|
},
|
244
269
|
{
|
245
270
|
title: 'Should detect miniRuntime dependency',
|
246
271
|
code: `
|
272
|
+
import { View, Text } from 'react-native'
|
247
273
|
import { StyleSheet } from 'react-native-unistyles'
|
248
274
|
|
249
275
|
export const Example = () => {
|
@@ -264,15 +290,16 @@ pluginTester({
|
|
264
290
|
`,
|
265
291
|
output: `
|
266
292
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
293
|
+
import { View, Text } from 'react-native'
|
267
294
|
import { StyleSheet } from 'react-native-unistyles'
|
268
295
|
|
269
296
|
export const Example = () => {
|
270
297
|
return (
|
271
298
|
<View
|
272
|
-
style={styles.container}
|
299
|
+
style={[styles.container]}
|
273
300
|
ref={ref => {
|
274
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
275
|
-
return () => UnistylesShadowRegistry.remove(ref
|
301
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
302
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
276
303
|
}}
|
277
304
|
>
|
278
305
|
<Text>Hello world</Text>
|
@@ -280,19 +307,23 @@ pluginTester({
|
|
280
307
|
)
|
281
308
|
}
|
282
309
|
|
283
|
-
const styles = StyleSheet.create(
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
310
|
+
const styles = StyleSheet.create(
|
311
|
+
(_, rt) => ({
|
312
|
+
container: () => ({
|
313
|
+
backgroundColor: 'red',
|
314
|
+
variants: {},
|
315
|
+
paddingTop: rt.insets.top,
|
316
|
+
uni__dependencies: [4, 9]
|
317
|
+
})
|
318
|
+
}),
|
319
|
+
793953373
|
320
|
+
)
|
291
321
|
`
|
292
322
|
},
|
293
323
|
{
|
294
324
|
title: 'Should detect miniRuntime and theme dependencies even if user renamed it\'s names',
|
295
325
|
code: `
|
326
|
+
import { View, Text } from 'react-native'
|
296
327
|
import { StyleSheet } from 'react-native-unistyles'
|
297
328
|
|
298
329
|
export const Example = () => {
|
@@ -313,15 +344,16 @@ pluginTester({
|
|
313
344
|
`,
|
314
345
|
output: `
|
315
346
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
347
|
+
import { View, Text } from 'react-native'
|
316
348
|
import { StyleSheet } from 'react-native-unistyles'
|
317
349
|
|
318
350
|
export const Example = () => {
|
319
351
|
return (
|
320
352
|
<View
|
321
|
-
style={styles.container}
|
353
|
+
style={[styles.container]}
|
322
354
|
ref={ref => {
|
323
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
324
|
-
return () => UnistylesShadowRegistry.remove(ref
|
355
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
356
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
325
357
|
}}
|
326
358
|
>
|
327
359
|
<Text>Hello world</Text>
|
@@ -329,19 +361,23 @@ pluginTester({
|
|
329
361
|
)
|
330
362
|
}
|
331
363
|
|
332
|
-
const styles = StyleSheet.create(
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
364
|
+
const styles = StyleSheet.create(
|
365
|
+
(hhsa, dee) => ({
|
366
|
+
container: () => ({
|
367
|
+
backgroundColor: hhsa.colors.background,
|
368
|
+
variants: {},
|
369
|
+
paddingTop: dee.colorScheme === 'dark' ? 0 : 10,
|
370
|
+
uni__dependencies: [0, 4, 5]
|
371
|
+
})
|
372
|
+
}),
|
373
|
+
793953373
|
374
|
+
)
|
340
375
|
`
|
341
376
|
},
|
342
377
|
{
|
343
378
|
title: 'Should detect dependencies in function',
|
344
379
|
code: `
|
380
|
+
import { View, Text } from 'react-native'
|
345
381
|
import { StyleSheet } from 'react-native-unistyles'
|
346
382
|
|
347
383
|
export const Example = () => {
|
@@ -364,15 +400,16 @@ pluginTester({
|
|
364
400
|
`,
|
365
401
|
output: `
|
366
402
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
403
|
+
import { View, Text } from 'react-native'
|
367
404
|
import { StyleSheet } from 'react-native-unistyles'
|
368
405
|
|
369
406
|
export const Example = () => {
|
370
407
|
return (
|
371
408
|
<View
|
372
|
-
style={styles.container}
|
409
|
+
style={[styles.container]}
|
373
410
|
ref={ref => {
|
374
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
375
|
-
return () => UnistylesShadowRegistry.remove(ref
|
411
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
412
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
376
413
|
}}
|
377
414
|
>
|
378
415
|
<Text>Hello world</Text>
|
@@ -389,7 +426,81 @@ pluginTester({
|
|
389
426
|
uni__dependencies: [0, 4, 9]
|
390
427
|
})
|
391
428
|
}
|
429
|
+
}, 793953373)
|
430
|
+
`
|
431
|
+
},
|
432
|
+
{
|
433
|
+
title: 'Should generates two different ids for 2 stylesheets in the same file',
|
434
|
+
code: `
|
435
|
+
import { View, Text } from 'react-native'
|
436
|
+
import { StyleSheet } from 'react-native-unistyles'
|
437
|
+
|
438
|
+
export const Example = () => {
|
439
|
+
return (
|
440
|
+
<View style={styles.container}>
|
441
|
+
<Text>Hello world</Text>
|
442
|
+
</View>
|
443
|
+
)
|
444
|
+
}
|
445
|
+
|
446
|
+
const styles = StyleSheet.create((theme, rt) => {
|
447
|
+
return {
|
448
|
+
container: () => ({
|
449
|
+
backgroundColor: theme.colors.background,
|
450
|
+
variants: {},
|
451
|
+
paddingTop: rt.insets.top
|
452
|
+
})
|
453
|
+
}
|
454
|
+
})
|
455
|
+
const styles2 = StyleSheet.create((theme, rt) => {
|
456
|
+
return {
|
457
|
+
container: () => ({
|
458
|
+
backgroundColor: theme.colors.background,
|
459
|
+
variants: {},
|
460
|
+
paddingTop: rt.insets.top
|
461
|
+
})
|
462
|
+
}
|
392
463
|
})
|
464
|
+
`,
|
465
|
+
output: `
|
466
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
467
|
+
import { View, Text } from 'react-native'
|
468
|
+
import { StyleSheet } from 'react-native-unistyles'
|
469
|
+
|
470
|
+
export const Example = () => {
|
471
|
+
return (
|
472
|
+
<View
|
473
|
+
style={[styles.container]}
|
474
|
+
ref={ref => {
|
475
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
476
|
+
return () => UnistylesShadowRegistry.remove(ref)
|
477
|
+
}}
|
478
|
+
>
|
479
|
+
<Text>Hello world</Text>
|
480
|
+
</View>
|
481
|
+
)
|
482
|
+
}
|
483
|
+
|
484
|
+
const styles = StyleSheet.create((theme, rt) => {
|
485
|
+
return {
|
486
|
+
container: () => ({
|
487
|
+
backgroundColor: theme.colors.background,
|
488
|
+
variants: {},
|
489
|
+
paddingTop: rt.insets.top,
|
490
|
+
uni__dependencies: [0, 4, 9]
|
491
|
+
})
|
492
|
+
}
|
493
|
+
}, 793953373)
|
494
|
+
const styles2 = StyleSheet.create((theme, rt) => {
|
495
|
+
return {
|
496
|
+
container: () => ({
|
497
|
+
backgroundColor: theme.colors.background,
|
498
|
+
variants: {},
|
499
|
+
paddingTop: rt.insets.top,
|
500
|
+
uni__dependencies: [0, 4, 9]
|
501
|
+
})
|
502
|
+
}
|
503
|
+
}, 793953374)
|
393
504
|
`
|
394
505
|
},
|
395
506
|
]
|
package/plugin/index.js
CHANGED
@@ -1,7 +1,28 @@
|
|
1
1
|
const addShadowRegistryImport = require('./import')
|
2
|
-
const {
|
2
|
+
const { getStyleMetadata, getStyleAttribute, styleAttributeToArray } = require('./style')
|
3
3
|
const { getRefProp, addRef, overrideRef, hasStringRef } = require('./ref')
|
4
|
-
const { isUnistylesStyleSheet, analyzeDependencies } = require('./stylesheet')
|
4
|
+
const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyle } = require('./stylesheet')
|
5
|
+
const { isUsingVariants, extractVariants } = require('./variants')
|
6
|
+
|
7
|
+
const reactNativeComponentNames = [
|
8
|
+
'View',
|
9
|
+
'Text',
|
10
|
+
'Image',
|
11
|
+
'ImageBackground',
|
12
|
+
'KeyboardAvoidingView',
|
13
|
+
'Modal',
|
14
|
+
'Pressable',
|
15
|
+
'ScrollView',
|
16
|
+
'FlatList',
|
17
|
+
'SectionList',
|
18
|
+
'Switch',
|
19
|
+
'Text',
|
20
|
+
'TextInput',
|
21
|
+
'TouchableHighlight',
|
22
|
+
'TouchableOpacity',
|
23
|
+
'TouchableWithoutFeedback',
|
24
|
+
'VirtualizedList'
|
25
|
+
]
|
5
26
|
|
6
27
|
module.exports = function ({ types: t }) {
|
7
28
|
return {
|
@@ -12,7 +33,9 @@ module.exports = function ({ types: t }) {
|
|
12
33
|
state.file.hasAnyUnistyle = false
|
13
34
|
state.file.hasUnistylesImport = false
|
14
35
|
state.file.styleSheetLocalName = ''
|
15
|
-
state.file.
|
36
|
+
state.file.tagNumber = 0
|
37
|
+
state.file.isClassComponent = false
|
38
|
+
state.reactNativeImports = {}
|
16
39
|
},
|
17
40
|
exit(path, state) {
|
18
41
|
if (state.file.hasAnyUnistyle) {
|
@@ -20,6 +43,38 @@ module.exports = function ({ types: t }) {
|
|
20
43
|
}
|
21
44
|
}
|
22
45
|
},
|
46
|
+
FunctionDeclaration(path, state) {
|
47
|
+
const componentName = path.node.id
|
48
|
+
? path.node.id.name
|
49
|
+
: null
|
50
|
+
|
51
|
+
if (componentName) {
|
52
|
+
state.file.hasVariants = false
|
53
|
+
}
|
54
|
+
},
|
55
|
+
ClassDeclaration(path, state) {
|
56
|
+
const componentName = path.node.id
|
57
|
+
? path.node.id.name
|
58
|
+
: null
|
59
|
+
|
60
|
+
if (componentName) {
|
61
|
+
state.file.hasVariants = false
|
62
|
+
state.file.isClassComponent = true
|
63
|
+
}
|
64
|
+
},
|
65
|
+
VariableDeclaration(path, state) {
|
66
|
+
path.node.declarations.forEach((declaration) => {
|
67
|
+
if (t.isArrowFunctionExpression(declaration.init) || t.isFunctionExpression(declaration.init)) {
|
68
|
+
const componentName = declaration.id
|
69
|
+
? declaration.id.name
|
70
|
+
: null
|
71
|
+
|
72
|
+
if (componentName) {
|
73
|
+
state.file.hasVariants = false
|
74
|
+
}
|
75
|
+
}
|
76
|
+
})
|
77
|
+
},
|
23
78
|
ImportDeclaration(path, state) {
|
24
79
|
const importSource = path.node.source.value
|
25
80
|
|
@@ -32,9 +87,30 @@ module.exports = function ({ types: t }) {
|
|
32
87
|
}
|
33
88
|
})
|
34
89
|
}
|
90
|
+
|
91
|
+
if (importSource.includes('react-native')) {
|
92
|
+
path.node.specifiers.forEach(specifier => {
|
93
|
+
if (specifier.imported && reactNativeComponentNames.includes(specifier.imported.name)) {
|
94
|
+
state.reactNativeImports[specifier.local.name] = true
|
95
|
+
}
|
96
|
+
})
|
97
|
+
}
|
35
98
|
},
|
36
99
|
JSXElement(path, state) {
|
37
|
-
if (
|
100
|
+
if (state.file.isClassComponent) {
|
101
|
+
return
|
102
|
+
}
|
103
|
+
|
104
|
+
const openingElement = path.node.openingElement
|
105
|
+
const openingElementName = openingElement.name.name
|
106
|
+
const isReactNativeComponent = Boolean(state.reactNativeImports[openingElementName])
|
107
|
+
const isAnimatedComponent = (
|
108
|
+
!isReactNativeComponent &&
|
109
|
+
openingElement.name.object &&
|
110
|
+
openingElement.name.object.name === 'Animated'
|
111
|
+
)
|
112
|
+
|
113
|
+
if (!isReactNativeComponent && !isAnimatedComponent) {
|
38
114
|
return
|
39
115
|
}
|
40
116
|
|
@@ -45,43 +121,52 @@ module.exports = function ({ types: t }) {
|
|
45
121
|
return
|
46
122
|
}
|
47
123
|
|
48
|
-
const
|
124
|
+
const metadata = getStyleMetadata(t, styleAttr.value.expression)
|
49
125
|
|
50
|
-
// style prop is
|
51
|
-
if (
|
126
|
+
// style prop is using unexpected expression
|
127
|
+
if (metadata.length === 0) {
|
52
128
|
return
|
53
129
|
}
|
54
130
|
|
131
|
+
styleAttributeToArray(t, path)
|
132
|
+
|
55
133
|
// to add import
|
56
134
|
state.file.hasAnyUnistyle = true
|
57
135
|
|
58
|
-
|
136
|
+
metadata.forEach(meta => {
|
137
|
+
const refProp = getRefProp(t, path)
|
59
138
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
const styleObj = stylePath[0]
|
65
|
-
const styleProp = stylePath[1]
|
139
|
+
if (!refProp && hasStringRef(t, path)) {
|
140
|
+
throw new Error("Detected string based ref which is not supported by Unistyles.")
|
141
|
+
}
|
66
142
|
|
67
|
-
|
68
|
-
|
69
|
-
|
143
|
+
refProp
|
144
|
+
? overrideRef(t, path, refProp, meta, state)
|
145
|
+
: addRef(t, path, meta, state)
|
146
|
+
})
|
70
147
|
},
|
71
148
|
CallExpression(path, state) {
|
149
|
+
if (isUsingVariants(t, path)) {
|
150
|
+
extractVariants(t, path, state)
|
151
|
+
}
|
152
|
+
|
72
153
|
if (!isUnistylesStyleSheet(t, path, state)) {
|
73
154
|
return
|
74
155
|
}
|
75
156
|
|
157
|
+
addStyleSheetTag(t, path, state)
|
158
|
+
|
76
159
|
const arg = path.node.arguments[0]
|
77
160
|
|
78
161
|
// Object passed to StyleSheet.create
|
79
162
|
if (t.isObjectExpression(arg)) {
|
80
163
|
arg.properties.forEach(property => {
|
81
164
|
if (t.isObjectProperty(property)) {
|
82
|
-
const propertyValue = t
|
83
|
-
|
84
|
-
|
165
|
+
const propertyValue = getUnistyle(t, property)
|
166
|
+
|
167
|
+
if (!propertyValue) {
|
168
|
+
return
|
169
|
+
}
|
85
170
|
|
86
171
|
analyzeDependencies(t, state, property.key.name, propertyValue)
|
87
172
|
}
|
@@ -107,9 +192,11 @@ module.exports = function ({ types: t }) {
|
|
107
192
|
if (t.isObjectExpression(body)) {
|
108
193
|
body.properties.forEach(property => {
|
109
194
|
if (t.isObjectProperty(property)) {
|
110
|
-
const propertyValue = t
|
111
|
-
|
112
|
-
|
195
|
+
const propertyValue = getUnistyle(t, property)
|
196
|
+
|
197
|
+
if (!propertyValue) {
|
198
|
+
return
|
199
|
+
}
|
113
200
|
|
114
201
|
analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
|
115
202
|
}
|