react-native-unistyles 3.0.0-alpha.1 → 3.0.0-alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- package/Unistyles.podspec +33 -0
- package/cxx/common/Constants.h +1 -0
- package/cxx/common/Helpers.h +92 -0
- package/cxx/core/HostStyle.cpp +18 -12
- package/cxx/core/HostStyle.h +3 -0
- package/cxx/core/StyleSheet.h +0 -1
- 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 +25 -7
- package/cxx/core/UnistylesCommitHook.cpp +8 -7
- package/cxx/core/UnistylesCommitHook.h +6 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +40 -0
- package/cxx/core/UnistylesMountHook.h +30 -0
- package/cxx/core/UnistylesRegistry.cpp +44 -75
- package/cxx/core/UnistylesRegistry.h +10 -11
- package/cxx/core/UnistylesState.cpp +4 -4
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +13 -6
- package/cxx/hybridObjects/HybridStyleSheet.cpp +35 -39
- package/cxx/hybridObjects/HybridStyleSheet.h +9 -6
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +34 -15
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +87 -165
- package/cxx/parser/Parser.h +8 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTreeManager.cpp +3 -8
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -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 +3 -3
- 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 +89 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +51 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +13 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +36 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +37 -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 +11 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +37 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +164 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/state.js +121 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +78 -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 +75 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- 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 +3 -3
- 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 +84 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +24 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +4 -0
- package/lib/module/web/listener/index.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 +33 -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 +6 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +33 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +160 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/state.js +117 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +65 -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 +70 -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 +2 -2
- 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 +1 -1
- 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/{web → src/web}/index.d.ts +12 -12
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
- 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.map +1 -0
- package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -4
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
- 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/package.json +2 -2
- package/plugin/__tests__/dependencies.spec.js +195 -107
- package/plugin/__tests__/ref.spec.js +537 -179
- package/plugin/__tests__/stylesheet.spec.js +174 -63
- package/plugin/index.js +68 -23
- package/plugin/ref.js +74 -12
- package/plugin/style.js +57 -24
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +5 -5
- 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 +1 -1
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +1 -1
- package/{web → src/web}/convert/types.ts +1 -1
- package/{web → src/web}/create.ts +36 -33
- package/{web → src/web}/listener/listener.ts +1 -1
- package/{web → src/web}/mock.ts +2 -2
- package/{web → src/web}/registry.ts +1 -1
- package/{web → src/web}/runtime.ts +4 -4
- package/{web → src/web}/state.ts +5 -5
- package/{web → src/web}/utils.ts +5 -5
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/{web → src/web/variants}/useVariants.ts +24 -44
- 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.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- 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.map +0 -1
- 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.map +0 -1
- /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}/listener/index.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/pseudo.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}/index.ts +0 -0
- /package/{web → src/web}/listener/index.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
- /package/{web → src/web}/pseudo.ts +0 -0
@@ -14,9 +14,9 @@ pluginTester({
|
|
14
14
|
},
|
15
15
|
tests: [
|
16
16
|
{
|
17
|
-
title: 'Does nothing if there is no import from
|
17
|
+
title: 'Does nothing if there is no import from React Native',
|
18
18
|
code: `
|
19
|
-
import { StyleSheet } from '
|
19
|
+
import { StyleSheet, View, Text } from 'custom-lib'
|
20
20
|
|
21
21
|
export const Example = () => {
|
22
22
|
return (
|
@@ -33,7 +33,7 @@ pluginTester({
|
|
33
33
|
})
|
34
34
|
`,
|
35
35
|
output: `
|
36
|
-
import { StyleSheet } from '
|
36
|
+
import { StyleSheet, View, Text } from 'custom-lib'
|
37
37
|
|
38
38
|
export const Example = () => {
|
39
39
|
return (
|
@@ -51,9 +51,9 @@ pluginTester({
|
|
51
51
|
`
|
52
52
|
},
|
53
53
|
{
|
54
|
-
title: 'Adds ref if there is any import from
|
54
|
+
title: 'Adds ref if there is any import from React Native',
|
55
55
|
code: `
|
56
|
-
import 'react-native
|
56
|
+
import { View, Text } from 'react-native'
|
57
57
|
|
58
58
|
export const Example = () => {
|
59
59
|
return (
|
@@ -71,14 +71,14 @@ pluginTester({
|
|
71
71
|
`,
|
72
72
|
output: `
|
73
73
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
74
|
-
import 'react-native
|
74
|
+
import { View, Text } from 'react-native'
|
75
75
|
|
76
76
|
export const Example = () => {
|
77
77
|
return (
|
78
78
|
<View
|
79
|
-
style={styles.container}
|
79
|
+
style={[styles.container]}
|
80
80
|
ref={ref => {
|
81
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
81
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
82
82
|
return () => UnistylesShadowRegistry.remove(ref, styles.container)
|
83
83
|
}}
|
84
84
|
>
|
@@ -94,10 +94,63 @@ pluginTester({
|
|
94
94
|
})
|
95
95
|
`
|
96
96
|
},
|
97
|
+
{
|
98
|
+
title: 'Adds ref only for React Native components',
|
99
|
+
code: `
|
100
|
+
import { View } from 'react-native'
|
101
|
+
import { Text } from 'custom-lib'
|
102
|
+
|
103
|
+
export const Example = () => {
|
104
|
+
return (
|
105
|
+
<View style={styles.container}>
|
106
|
+
<Text style={styles.text}>Hello world</Text>
|
107
|
+
</View>
|
108
|
+
)
|
109
|
+
}
|
110
|
+
|
111
|
+
const styles = StyleSheet.create({
|
112
|
+
container: {
|
113
|
+
backgroundColor: 'red'
|
114
|
+
},
|
115
|
+
text: {
|
116
|
+
color: 'blue'
|
117
|
+
}
|
118
|
+
})
|
119
|
+
`,
|
120
|
+
output: `
|
121
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
122
|
+
import { View } from 'react-native'
|
123
|
+
import { Text } from 'custom-lib'
|
124
|
+
|
125
|
+
export const Example = () => {
|
126
|
+
return (
|
127
|
+
<View
|
128
|
+
style={[styles.container]}
|
129
|
+
ref={ref => {
|
130
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
131
|
+
return () => UnistylesShadowRegistry.remove(ref, styles.container)
|
132
|
+
}}
|
133
|
+
>
|
134
|
+
<Text style={styles.text}>Hello world</Text>
|
135
|
+
</View>
|
136
|
+
)
|
137
|
+
}
|
138
|
+
|
139
|
+
const styles = StyleSheet.create({
|
140
|
+
container: {
|
141
|
+
backgroundColor: 'red'
|
142
|
+
},
|
143
|
+
text: {
|
144
|
+
color: 'blue'
|
145
|
+
}
|
146
|
+
})
|
147
|
+
`
|
148
|
+
},
|
97
149
|
{
|
98
150
|
title: 'Preserves user\'s ref',
|
99
151
|
code: `
|
100
152
|
import React from 'react'
|
153
|
+
import { View, Text } from 'react-native'
|
101
154
|
import { StyleSheet } from 'react-native-unistyles'
|
102
155
|
|
103
156
|
export const Example = () => {
|
@@ -122,6 +175,7 @@ pluginTester({
|
|
122
175
|
output: `
|
123
176
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
124
177
|
import React from 'react'
|
178
|
+
import { View, Text } from 'react-native'
|
125
179
|
import { StyleSheet } from 'react-native-unistyles'
|
126
180
|
|
127
181
|
export const Example = () => {
|
@@ -130,38 +184,42 @@ pluginTester({
|
|
130
184
|
return (
|
131
185
|
<View
|
132
186
|
ref={_ref => {
|
133
|
-
ref = _ref
|
134
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
187
|
+
ref.current = _ref
|
188
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
|
135
189
|
return () => UnistylesShadowRegistry.remove(_ref, styles.container)
|
136
190
|
}}
|
137
|
-
style={styles.container}
|
191
|
+
style={[styles.container]}
|
138
192
|
>
|
139
193
|
<Text>Hello world</Text>
|
140
194
|
</View>
|
141
195
|
)
|
142
196
|
}
|
143
197
|
|
144
|
-
const styles = StyleSheet.create(
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
198
|
+
const styles = StyleSheet.create(
|
199
|
+
{
|
200
|
+
container: {
|
201
|
+
backgroundColor: 'red'
|
202
|
+
}
|
203
|
+
},
|
204
|
+
921918562
|
205
|
+
)
|
149
206
|
`
|
150
207
|
},
|
151
208
|
{
|
152
209
|
title: 'Preserves user\'s ref as function',
|
153
210
|
code: `
|
154
211
|
import { useRef } from 'react'
|
212
|
+
import { View, Text } from 'react-native'
|
155
213
|
import { StyleSheet } from 'react-native-unistyles'
|
156
214
|
|
157
215
|
export const Example = () => {
|
158
|
-
|
216
|
+
const myRef = useRef()
|
159
217
|
|
160
218
|
return (
|
161
219
|
<View
|
162
220
|
ref={ref => {
|
163
221
|
doSomething(ref)
|
164
|
-
myRef = ref
|
222
|
+
myRef.current = ref
|
165
223
|
}}
|
166
224
|
style={styles.container}
|
167
225
|
>
|
@@ -179,49 +237,54 @@ pluginTester({
|
|
179
237
|
output: `
|
180
238
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
181
239
|
import { useRef } from 'react'
|
240
|
+
import { View, Text } from 'react-native'
|
182
241
|
import { StyleSheet } from 'react-native-unistyles'
|
183
242
|
|
184
243
|
export const Example = () => {
|
185
|
-
|
244
|
+
const myRef = useRef()
|
186
245
|
|
187
246
|
return (
|
188
247
|
<View
|
189
248
|
ref={ref => {
|
190
249
|
doSomething(ref)
|
191
|
-
myRef = ref
|
192
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
250
|
+
myRef.current = ref
|
251
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
193
252
|
return () => {
|
194
253
|
UnistylesShadowRegistry.remove(ref, styles.container)
|
195
254
|
}
|
196
255
|
}}
|
197
|
-
style={styles.container}
|
256
|
+
style={[styles.container]}
|
198
257
|
>
|
199
258
|
<Text>Hello world</Text>
|
200
259
|
</View>
|
201
260
|
)
|
202
261
|
}
|
203
262
|
|
204
|
-
const styles = StyleSheet.create(
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
263
|
+
const styles = StyleSheet.create(
|
264
|
+
{
|
265
|
+
container: {
|
266
|
+
backgroundColor: 'red'
|
267
|
+
}
|
268
|
+
},
|
269
|
+
921918562
|
270
|
+
)
|
209
271
|
`
|
210
272
|
},
|
211
273
|
{
|
212
274
|
title: 'Preserves user\'s ref as function with cleanup',
|
213
275
|
code: `
|
214
276
|
import React from 'react'
|
277
|
+
import { View, Text } from 'react-native'
|
215
278
|
import { StyleSheet } from 'react-native-unistyles'
|
216
279
|
|
217
280
|
export const Example = () => {
|
218
|
-
|
281
|
+
const myRef = React.useRef()
|
219
282
|
|
220
283
|
return (
|
221
284
|
<View
|
222
285
|
ref={ref => {
|
223
286
|
doSomething(ref)
|
224
|
-
myRef = ref
|
287
|
+
myRef.current = ref
|
225
288
|
|
226
289
|
return () => {
|
227
290
|
customCleanup()
|
@@ -243,17 +306,18 @@ pluginTester({
|
|
243
306
|
output: `
|
244
307
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
245
308
|
import React from 'react'
|
309
|
+
import { View, Text } from 'react-native'
|
246
310
|
import { StyleSheet } from 'react-native-unistyles'
|
247
311
|
|
248
312
|
export const Example = () => {
|
249
|
-
|
313
|
+
const myRef = React.useRef()
|
250
314
|
|
251
315
|
return (
|
252
316
|
<View
|
253
317
|
ref={ref => {
|
254
318
|
doSomething(ref)
|
255
|
-
myRef = ref
|
256
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
319
|
+
myRef.current = ref
|
320
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
257
321
|
return () => {
|
258
322
|
;(() => {
|
259
323
|
customCleanup()
|
@@ -261,31 +325,35 @@ pluginTester({
|
|
261
325
|
UnistylesShadowRegistry.remove(ref, styles.container)
|
262
326
|
}
|
263
327
|
}}
|
264
|
-
style={styles.container}
|
328
|
+
style={[styles.container]}
|
265
329
|
>
|
266
330
|
<Text>Hello world</Text>
|
267
331
|
</View>
|
268
332
|
)
|
269
333
|
}
|
270
334
|
|
271
|
-
const styles = StyleSheet.create(
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
335
|
+
const styles = StyleSheet.create(
|
336
|
+
{
|
337
|
+
container: {
|
338
|
+
backgroundColor: 'red'
|
339
|
+
}
|
340
|
+
},
|
341
|
+
921918562
|
342
|
+
)
|
276
343
|
`
|
277
344
|
},
|
278
345
|
{
|
279
346
|
title: 'Preserves user\'s ref as assigned arrow function',
|
280
347
|
code: `
|
281
348
|
import React from 'react'
|
349
|
+
import { View, Text } from 'react-native'
|
282
350
|
import { StyleSheet } from 'react-native-unistyles'
|
283
351
|
|
284
352
|
export const Example = () => {
|
285
|
-
|
353
|
+
const myRef = React.useRef()
|
286
354
|
const fn = ref => {
|
287
355
|
doSomething(ref)
|
288
|
-
myRef = ref
|
356
|
+
myRef.current = ref
|
289
357
|
|
290
358
|
return () => {
|
291
359
|
customCleanup2()
|
@@ -311,20 +379,21 @@ pluginTester({
|
|
311
379
|
output: `
|
312
380
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
313
381
|
import React from 'react'
|
382
|
+
import { View, Text } from 'react-native'
|
314
383
|
import { StyleSheet } from 'react-native-unistyles'
|
315
384
|
|
316
385
|
export const Example = () => {
|
317
|
-
|
386
|
+
const myRef = React.useRef()
|
318
387
|
const fn = ref => {
|
319
388
|
doSomething(ref)
|
320
|
-
myRef = ref
|
389
|
+
myRef.current = ref
|
321
390
|
}
|
322
391
|
|
323
392
|
return (
|
324
393
|
<View
|
325
394
|
ref={_ref => {
|
326
395
|
fn(_ref)
|
327
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
396
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
|
328
397
|
return () => {
|
329
398
|
;(() => {
|
330
399
|
customCleanup2()
|
@@ -332,31 +401,35 @@ pluginTester({
|
|
332
401
|
UnistylesShadowRegistry.remove(_ref, styles.container)
|
333
402
|
}
|
334
403
|
}}
|
335
|
-
style={styles.container}
|
404
|
+
style={[styles.container]}
|
336
405
|
>
|
337
406
|
<Text>Hello world</Text>
|
338
407
|
</View>
|
339
408
|
)
|
340
409
|
}
|
341
410
|
|
342
|
-
const styles = StyleSheet.create(
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
411
|
+
const styles = StyleSheet.create(
|
412
|
+
{
|
413
|
+
container: {
|
414
|
+
backgroundColor: 'red'
|
415
|
+
}
|
416
|
+
},
|
417
|
+
921918562
|
418
|
+
)
|
347
419
|
`
|
348
420
|
},
|
349
421
|
{
|
350
422
|
title: 'Preserves user\'s ref as assigned function function',
|
351
423
|
code: `
|
352
424
|
import React from 'react'
|
425
|
+
import { View, Text } from 'react-native'
|
353
426
|
import { StyleSheet } from 'react-native-unistyles'
|
354
427
|
|
355
428
|
export const Example = () => {
|
356
|
-
|
429
|
+
const myRef = React.useRef()
|
357
430
|
function fn(ref) {
|
358
431
|
doSomething(ref)
|
359
|
-
myRef = ref
|
432
|
+
myRef.current = ref
|
360
433
|
|
361
434
|
return () => {
|
362
435
|
customCleanup2()
|
@@ -382,20 +455,21 @@ pluginTester({
|
|
382
455
|
output: `
|
383
456
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
384
457
|
import React from 'react'
|
458
|
+
import { View, Text } from 'react-native'
|
385
459
|
import { StyleSheet } from 'react-native-unistyles'
|
386
460
|
|
387
461
|
export const Example = () => {
|
388
|
-
|
462
|
+
const myRef = React.useRef()
|
389
463
|
function fn(ref) {
|
390
464
|
doSomething(ref)
|
391
|
-
myRef = ref
|
465
|
+
myRef.current = ref
|
392
466
|
}
|
393
467
|
|
394
468
|
return (
|
395
469
|
<View
|
396
470
|
ref={_ref => {
|
397
471
|
fn(_ref)
|
398
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
472
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
|
399
473
|
return () => {
|
400
474
|
;(() => {
|
401
475
|
customCleanup2()
|
@@ -403,28 +477,32 @@ pluginTester({
|
|
403
477
|
UnistylesShadowRegistry.remove(_ref, styles.container)
|
404
478
|
}
|
405
479
|
}}
|
406
|
-
style={styles.container}
|
480
|
+
style={[styles.container]}
|
407
481
|
>
|
408
482
|
<Text>Hello world</Text>
|
409
483
|
</View>
|
410
484
|
)
|
411
485
|
}
|
412
486
|
|
413
|
-
const styles = StyleSheet.create(
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
487
|
+
const styles = StyleSheet.create(
|
488
|
+
{
|
489
|
+
container: {
|
490
|
+
backgroundColor: 'red'
|
491
|
+
}
|
492
|
+
},
|
493
|
+
921918562
|
494
|
+
)
|
418
495
|
`
|
419
496
|
},
|
420
497
|
{
|
421
498
|
title: 'Should not modify ref if user is using inline styles',
|
422
499
|
code: `
|
423
500
|
import { useRef } from 'react'
|
501
|
+
import { View, Text } from 'react-native'
|
424
502
|
import { StyleSheet } from 'react-native-unistyles'
|
425
503
|
|
426
504
|
export const Example = () => {
|
427
|
-
|
505
|
+
const myRef = useRef()
|
428
506
|
|
429
507
|
return (
|
430
508
|
<View
|
@@ -446,10 +524,11 @@ pluginTester({
|
|
446
524
|
`,
|
447
525
|
output: `
|
448
526
|
import { useRef } from 'react'
|
527
|
+
import { View, Text } from 'react-native'
|
449
528
|
import { StyleSheet } from 'react-native-unistyles'
|
450
529
|
|
451
530
|
export const Example = () => {
|
452
|
-
|
531
|
+
const myRef = useRef()
|
453
532
|
|
454
533
|
return (
|
455
534
|
<View
|
@@ -463,21 +542,25 @@ pluginTester({
|
|
463
542
|
)
|
464
543
|
}
|
465
544
|
|
466
|
-
const styles = StyleSheet.create(
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
545
|
+
const styles = StyleSheet.create(
|
546
|
+
{
|
547
|
+
container: {
|
548
|
+
backgroundColor: 'red'
|
549
|
+
}
|
550
|
+
},
|
551
|
+
921918562
|
552
|
+
)
|
471
553
|
`
|
472
554
|
},
|
473
555
|
{
|
474
|
-
title: 'Should
|
556
|
+
title: 'Should modify ref if user is not member accessing styles',
|
475
557
|
code: `
|
476
558
|
import { useRef } from 'react'
|
559
|
+
import { View, Text } from 'react-native'
|
477
560
|
import { StyleSheet } from 'react-native-unistyles'
|
478
561
|
|
479
562
|
export const Example = () => {
|
480
|
-
|
563
|
+
const myRef = useRef()
|
481
564
|
|
482
565
|
return (
|
483
566
|
<View
|
@@ -499,40 +582,51 @@ pluginTester({
|
|
499
582
|
})
|
500
583
|
`,
|
501
584
|
output: `
|
585
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
502
586
|
import { useRef } from 'react'
|
587
|
+
import { View, Text } from 'react-native'
|
503
588
|
import { StyleSheet } from 'react-native-unistyles'
|
504
589
|
|
505
590
|
export const Example = () => {
|
506
|
-
|
591
|
+
const myRef = useRef()
|
507
592
|
|
508
593
|
return (
|
509
594
|
<View
|
510
|
-
ref={
|
511
|
-
|
512
|
-
|
513
|
-
|
595
|
+
ref={_ref => {
|
596
|
+
myRef.current = _ref
|
597
|
+
UnistylesShadowRegistry.add(_ref, obj1, undefined, undefined)
|
598
|
+
UnistylesShadowRegistry.add(_ref, obj2, undefined, undefined)
|
599
|
+
return () => {
|
600
|
+
;(() => UnistylesShadowRegistry.remove(_ref, obj1))()
|
601
|
+
UnistylesShadowRegistry.remove(_ref, obj2)
|
602
|
+
}
|
514
603
|
}}
|
604
|
+
style={[obj1, obj2]}
|
515
605
|
>
|
516
606
|
<Text>Hello world</Text>
|
517
607
|
</View>
|
518
608
|
)
|
519
609
|
}
|
520
610
|
|
521
|
-
const styles = StyleSheet.create(
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
611
|
+
const styles = StyleSheet.create(
|
612
|
+
{
|
613
|
+
container: {
|
614
|
+
backgroundColor: 'red'
|
615
|
+
}
|
616
|
+
},
|
617
|
+
921918562
|
618
|
+
)
|
526
619
|
`
|
527
620
|
},
|
528
621
|
{
|
529
|
-
title: 'Should
|
622
|
+
title: 'Should modify ref if user is not member accessing styles in array',
|
530
623
|
code: `
|
531
624
|
import { useRef } from 'react'
|
625
|
+
import { View, Text } from 'react-native'
|
532
626
|
import { StyleSheet } from 'react-native-unistyles'
|
533
627
|
|
534
628
|
export const Example = () => {
|
535
|
-
|
629
|
+
const myRef = useRef()
|
536
630
|
|
537
631
|
return (
|
538
632
|
<View
|
@@ -551,34 +645,51 @@ pluginTester({
|
|
551
645
|
})
|
552
646
|
`,
|
553
647
|
output: `
|
648
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
554
649
|
import { useRef } from 'react'
|
650
|
+
import { View, Text } from 'react-native'
|
555
651
|
import { StyleSheet } from 'react-native-unistyles'
|
556
652
|
|
557
653
|
export const Example = () => {
|
558
|
-
|
654
|
+
const myRef = useRef()
|
559
655
|
|
560
656
|
return (
|
561
|
-
<View
|
657
|
+
<View
|
658
|
+
ref={_ref => {
|
659
|
+
myRef.current = _ref
|
660
|
+
UnistylesShadowRegistry.add(_ref, obj1, undefined, undefined)
|
661
|
+
UnistylesShadowRegistry.add(_ref, obj2, undefined, undefined)
|
662
|
+
return () => {
|
663
|
+
;(() => UnistylesShadowRegistry.remove(_ref, obj1))()
|
664
|
+
UnistylesShadowRegistry.remove(_ref, obj2)
|
665
|
+
}
|
666
|
+
}}
|
667
|
+
style={[obj1, obj2]}
|
668
|
+
>
|
562
669
|
<Text>Hello world</Text>
|
563
670
|
</View>
|
564
671
|
)
|
565
672
|
}
|
566
673
|
|
567
|
-
const styles = StyleSheet.create(
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
674
|
+
const styles = StyleSheet.create(
|
675
|
+
{
|
676
|
+
container: {
|
677
|
+
backgroundColor: 'red'
|
678
|
+
}
|
679
|
+
},
|
680
|
+
921918562
|
681
|
+
)
|
572
682
|
`
|
573
683
|
},
|
574
684
|
{
|
575
685
|
title: 'Should modify ref if user is using spreads on styles',
|
576
686
|
code: `
|
577
687
|
import { useRef } from 'react'
|
688
|
+
import { View, Text } from 'react-native'
|
578
689
|
import { StyleSheet } from 'react-native-unistyles'
|
579
690
|
|
580
691
|
export const Example = () => {
|
581
|
-
|
692
|
+
const myRef = useRef()
|
582
693
|
|
583
694
|
return (
|
584
695
|
<View
|
@@ -604,45 +715,50 @@ pluginTester({
|
|
604
715
|
output: `
|
605
716
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
606
717
|
import { useRef } from 'react'
|
718
|
+
import { View, Text } from 'react-native'
|
607
719
|
import { StyleSheet } from 'react-native-unistyles'
|
608
720
|
|
609
721
|
export const Example = () => {
|
610
|
-
|
722
|
+
const myRef = useRef()
|
611
723
|
|
612
724
|
return (
|
613
725
|
<View
|
614
726
|
ref={_ref => {
|
615
|
-
myRef = _ref
|
616
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
727
|
+
myRef.current = _ref
|
728
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
|
617
729
|
return () => UnistylesShadowRegistry.remove(_ref, styles.container)
|
618
730
|
}}
|
619
|
-
style={
|
620
|
-
|
621
|
-
|
731
|
+
style={[
|
732
|
+
styles.container,
|
733
|
+
{
|
622
734
|
backgroundColor: 'red'
|
623
735
|
}
|
624
|
-
}
|
736
|
+
]}
|
625
737
|
>
|
626
738
|
<Text>Hello world</Text>
|
627
739
|
</View>
|
628
740
|
)
|
629
741
|
}
|
630
742
|
|
631
|
-
const styles = StyleSheet.create(
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
743
|
+
const styles = StyleSheet.create(
|
744
|
+
{
|
745
|
+
container: {
|
746
|
+
backgroundColor: 'red'
|
747
|
+
}
|
748
|
+
},
|
749
|
+
921918562
|
750
|
+
)
|
636
751
|
`
|
637
752
|
},
|
638
753
|
{
|
639
754
|
title: 'Should modify ref if user is using array for styles',
|
640
755
|
code: `
|
641
756
|
import { useRef } from 'react'
|
757
|
+
import { View, Text } from 'react-native'
|
642
758
|
import { StyleSheet } from 'react-native-unistyles'
|
643
759
|
|
644
760
|
export const Example = () => {
|
645
|
-
|
761
|
+
const myRef = useRef()
|
646
762
|
|
647
763
|
return (
|
648
764
|
<View
|
@@ -668,16 +784,17 @@ pluginTester({
|
|
668
784
|
output: `
|
669
785
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
670
786
|
import { useRef } from 'react'
|
787
|
+
import { View, Text } from 'react-native'
|
671
788
|
import { StyleSheet } from 'react-native-unistyles'
|
672
789
|
|
673
790
|
export const Example = () => {
|
674
|
-
|
791
|
+
const myRef = useRef()
|
675
792
|
|
676
793
|
return (
|
677
794
|
<View
|
678
795
|
ref={_ref => {
|
679
|
-
myRef = _ref
|
680
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
796
|
+
myRef.current = _ref
|
797
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
|
681
798
|
return () => UnistylesShadowRegistry.remove(_ref, styles.container)
|
682
799
|
}}
|
683
800
|
style={[
|
@@ -692,26 +809,30 @@ pluginTester({
|
|
692
809
|
)
|
693
810
|
}
|
694
811
|
|
695
|
-
const styles = StyleSheet.create(
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
812
|
+
const styles = StyleSheet.create(
|
813
|
+
{
|
814
|
+
container: {
|
815
|
+
backgroundColor: 'red'
|
816
|
+
}
|
817
|
+
},
|
818
|
+
921918562
|
819
|
+
)
|
700
820
|
`
|
701
821
|
},
|
702
822
|
{
|
703
823
|
title: 'Should modify ref if user is using single style in array',
|
704
824
|
code: `
|
705
825
|
import { useRef } from 'react'
|
826
|
+
import { View, Text } from 'react-native'
|
706
827
|
import { StyleSheet } from 'react-native-unistyles'
|
707
828
|
|
708
829
|
export const Example = () => {
|
709
|
-
|
830
|
+
const myRef = useRef()
|
710
831
|
|
711
832
|
return (
|
712
833
|
<View
|
713
834
|
ref={myRef}
|
714
|
-
style={
|
835
|
+
style={styles.container}
|
715
836
|
>
|
716
837
|
<Text>Hello world</Text>
|
717
838
|
</View>
|
@@ -727,16 +848,17 @@ pluginTester({
|
|
727
848
|
output: `
|
728
849
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
729
850
|
import { useRef } from 'react'
|
851
|
+
import { View, Text } from 'react-native'
|
730
852
|
import { StyleSheet } from 'react-native-unistyles'
|
731
853
|
|
732
854
|
export const Example = () => {
|
733
|
-
|
855
|
+
const myRef = useRef()
|
734
856
|
|
735
857
|
return (
|
736
858
|
<View
|
737
859
|
ref={_ref => {
|
738
|
-
myRef = _ref
|
739
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
860
|
+
myRef.current = _ref
|
861
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
|
740
862
|
return () => UnistylesShadowRegistry.remove(_ref, styles.container)
|
741
863
|
}}
|
742
864
|
style={[styles.container]}
|
@@ -746,21 +868,25 @@ pluginTester({
|
|
746
868
|
)
|
747
869
|
}
|
748
870
|
|
749
|
-
const styles = StyleSheet.create(
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
871
|
+
const styles = StyleSheet.create(
|
872
|
+
{
|
873
|
+
container: {
|
874
|
+
backgroundColor: 'red'
|
875
|
+
}
|
876
|
+
},
|
877
|
+
921918562
|
878
|
+
)
|
754
879
|
`
|
755
880
|
},
|
756
881
|
{
|
757
882
|
title: 'Should modify ref if user is using dynamic function in array',
|
758
883
|
code: `
|
759
884
|
import { useRef } from 'react'
|
885
|
+
import { View, Text } from 'react-native'
|
760
886
|
import { StyleSheet } from 'react-native-unistyles'
|
761
887
|
|
762
888
|
export const Example = () => {
|
763
|
-
|
889
|
+
const myRef = useRef()
|
764
890
|
|
765
891
|
return (
|
766
892
|
<View
|
@@ -783,40 +909,45 @@ pluginTester({
|
|
783
909
|
output: `
|
784
910
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
785
911
|
import { useRef } from 'react'
|
912
|
+
import { View, Text } from 'react-native'
|
786
913
|
import { StyleSheet } from 'react-native-unistyles'
|
787
914
|
|
788
915
|
export const Example = () => {
|
789
|
-
|
916
|
+
const myRef = useRef()
|
790
917
|
|
791
918
|
return (
|
792
919
|
<View
|
793
920
|
ref={_ref => {
|
794
|
-
myRef = _ref
|
795
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
921
|
+
myRef.current = _ref
|
922
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, [1, 2])
|
796
923
|
return () => UnistylesShadowRegistry.remove(_ref, styles.container)
|
797
924
|
}}
|
798
|
-
style={[styles.container(1, 2
|
925
|
+
style={[styles.container(1, 2)]}
|
799
926
|
>
|
800
927
|
<Text>Hello world</Text>
|
801
928
|
</View>
|
802
929
|
)
|
803
930
|
}
|
804
931
|
|
805
|
-
const styles = StyleSheet.create(
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
932
|
+
const styles = StyleSheet.create(
|
933
|
+
{
|
934
|
+
container: () => ({
|
935
|
+
backgroundColor: 'red'
|
936
|
+
})
|
937
|
+
},
|
938
|
+
921918562
|
939
|
+
)
|
810
940
|
`
|
811
941
|
},
|
812
942
|
{
|
813
943
|
title: 'Should modify ref if user is using dynamic function in object',
|
814
944
|
code: `
|
815
945
|
import { useRef } from 'react'
|
946
|
+
import { View, Text } from 'react-native'
|
816
947
|
import { StyleSheet } from 'react-native-unistyles'
|
817
948
|
|
818
949
|
export const Example = () => {
|
819
|
-
|
950
|
+
const myRef = useRef()
|
820
951
|
|
821
952
|
return (
|
822
953
|
<View
|
@@ -832,51 +963,57 @@ pluginTester({
|
|
832
963
|
}
|
833
964
|
|
834
965
|
const styles = StyleSheet.create({
|
835
|
-
container:
|
966
|
+
container: {
|
836
967
|
backgroundColor: 'red'
|
837
|
-
}
|
968
|
+
}
|
838
969
|
})
|
839
970
|
`,
|
840
971
|
output: `
|
841
972
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
842
973
|
import { useRef } from 'react'
|
974
|
+
import { View, Text } from 'react-native'
|
843
975
|
import { StyleSheet } from 'react-native-unistyles'
|
844
976
|
|
845
977
|
export const Example = () => {
|
846
|
-
|
978
|
+
const myRef = useRef()
|
847
979
|
|
848
980
|
return (
|
849
981
|
<View
|
850
982
|
ref={_ref => {
|
851
|
-
myRef = _ref
|
852
|
-
UnistylesShadowRegistry.add(_ref, styles.container)
|
983
|
+
myRef.current = _ref
|
984
|
+
UnistylesShadowRegistry.add(_ref, styles.container, undefined, [1, 2])
|
853
985
|
return () => UnistylesShadowRegistry.remove(_ref, styles.container)
|
854
986
|
}}
|
855
|
-
style={{
|
856
|
-
backgroundColor: 'red',
|
857
|
-
...styles.container(1, 2, 1)
|
858
|
-
}}
|
987
|
+
style={[{ backgroundColor: 'red' }, styles.container(1, 2)]}
|
859
988
|
>
|
860
989
|
<Text>Hello world</Text>
|
861
990
|
</View>
|
862
991
|
)
|
863
992
|
}
|
864
993
|
|
865
|
-
const styles = StyleSheet.create(
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
994
|
+
const styles = StyleSheet.create(
|
995
|
+
{
|
996
|
+
container: {
|
997
|
+
backgroundColor: 'red'
|
998
|
+
}
|
999
|
+
},
|
1000
|
+
921918562
|
1001
|
+
)
|
870
1002
|
`
|
871
1003
|
},
|
872
1004
|
{
|
873
|
-
title: '
|
1005
|
+
title: 'It should extract variants and pass them to ShadowReigstry',
|
874
1006
|
code: `
|
875
1007
|
import { useRef } from 'react'
|
1008
|
+
import { View, Text } from 'react-native'
|
876
1009
|
import { StyleSheet } from 'react-native-unistyles'
|
877
1010
|
|
878
1011
|
export const Example = () => {
|
879
|
-
|
1012
|
+
const myRef = useRef()
|
1013
|
+
|
1014
|
+
styles.useVariants({
|
1015
|
+
size: 'default'
|
1016
|
+
})
|
880
1017
|
|
881
1018
|
return (
|
882
1019
|
<View
|
@@ -890,62 +1027,90 @@ pluginTester({
|
|
890
1027
|
|
891
1028
|
const uhh = StyleSheet.create({
|
892
1029
|
dkk: () => ({
|
893
|
-
backgroundColor: 'red'
|
1030
|
+
backgroundColor: 'red',
|
1031
|
+
variants: {
|
1032
|
+
size: {
|
1033
|
+
small: {
|
1034
|
+
backgroundColor: 'blue'
|
1035
|
+
},
|
1036
|
+
default: {
|
1037
|
+
backgroundColor: 'green'
|
1038
|
+
}
|
1039
|
+
}
|
1040
|
+
}
|
894
1041
|
})
|
895
1042
|
})
|
896
1043
|
`,
|
897
1044
|
output: `
|
898
1045
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
899
1046
|
import { useRef } from 'react'
|
1047
|
+
import { View, Text } from 'react-native'
|
900
1048
|
import { StyleSheet } from 'react-native-unistyles'
|
901
1049
|
|
902
1050
|
export const Example = () => {
|
903
|
-
|
1051
|
+
const myRef = useRef()
|
1052
|
+
const __uni__variants = {
|
1053
|
+
size: 'default'
|
1054
|
+
}
|
1055
|
+
styles.useVariants(__uni__variants)
|
904
1056
|
|
905
1057
|
return (
|
906
1058
|
<View
|
907
1059
|
ref={_ref => {
|
908
|
-
myRef = _ref
|
909
|
-
UnistylesShadowRegistry.add(_ref, uhh.dkk)
|
1060
|
+
myRef.current = _ref
|
1061
|
+
UnistylesShadowRegistry.add(_ref, uhh.dkk, __uni__variants, [])
|
910
1062
|
return () => UnistylesShadowRegistry.remove(_ref, uhh.dkk)
|
911
1063
|
}}
|
912
|
-
style={uhh.dkk(
|
1064
|
+
style={[uhh.dkk()]}
|
913
1065
|
>
|
914
1066
|
<Text>Hello world</Text>
|
915
1067
|
</View>
|
916
1068
|
)
|
917
1069
|
}
|
918
1070
|
|
919
|
-
const uhh = StyleSheet.create(
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
1071
|
+
const uhh = StyleSheet.create(
|
1072
|
+
{
|
1073
|
+
dkk: () => ({
|
1074
|
+
backgroundColor: 'red',
|
1075
|
+
variants: {
|
1076
|
+
size: {
|
1077
|
+
small: {
|
1078
|
+
backgroundColor: 'blue'
|
1079
|
+
},
|
1080
|
+
default: {
|
1081
|
+
backgroundColor: 'green'
|
1082
|
+
}
|
1083
|
+
}
|
1084
|
+
},
|
1085
|
+
uni__dependencies: [4]
|
1086
|
+
})
|
1087
|
+
},
|
1088
|
+
921918562
|
1089
|
+
)
|
924
1090
|
`
|
925
1091
|
},
|
926
1092
|
{
|
927
|
-
title: 'Should
|
1093
|
+
title: 'Should modify registry names if user changes name of member expression',
|
928
1094
|
code: `
|
929
1095
|
import { useRef } from 'react'
|
1096
|
+
import { View, Text } from 'react-native'
|
930
1097
|
import { StyleSheet } from 'react-native-unistyles'
|
931
1098
|
|
932
1099
|
export const Example = () => {
|
933
|
-
|
1100
|
+
const myRef = useRef()
|
934
1101
|
|
935
1102
|
return (
|
936
1103
|
<View
|
937
1104
|
ref={myRef}
|
938
|
-
style={
|
1105
|
+
style={uhh.dkk()}
|
939
1106
|
>
|
940
|
-
<Text
|
941
|
-
Hello world
|
942
|
-
</Text>
|
1107
|
+
<Text>Hello world</Text>
|
943
1108
|
</View>
|
944
1109
|
)
|
945
1110
|
}
|
946
1111
|
|
947
|
-
const
|
948
|
-
|
1112
|
+
const uhh = StyleSheet.create({
|
1113
|
+
dkk: () => ({
|
949
1114
|
backgroundColor: 'red'
|
950
1115
|
})
|
951
1116
|
})
|
@@ -953,39 +1118,232 @@ pluginTester({
|
|
953
1118
|
output: `
|
954
1119
|
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
955
1120
|
import { useRef } from 'react'
|
1121
|
+
import { View, Text } from 'react-native'
|
956
1122
|
import { StyleSheet } from 'react-native-unistyles'
|
957
1123
|
|
958
1124
|
export const Example = () => {
|
959
|
-
|
1125
|
+
const myRef = useRef()
|
960
1126
|
|
961
1127
|
return (
|
962
1128
|
<View
|
963
1129
|
ref={_ref => {
|
964
|
-
myRef = _ref
|
965
|
-
UnistylesShadowRegistry.add(_ref,
|
966
|
-
return () => UnistylesShadowRegistry.remove(_ref,
|
1130
|
+
myRef.current = _ref
|
1131
|
+
UnistylesShadowRegistry.add(_ref, uhh.dkk, undefined, [])
|
1132
|
+
return () => UnistylesShadowRegistry.remove(_ref, uhh.dkk)
|
967
1133
|
}}
|
968
|
-
style={
|
1134
|
+
style={[uhh.dkk()]}
|
969
1135
|
>
|
970
|
-
<Text
|
971
|
-
|
1136
|
+
<Text>Hello world</Text>
|
1137
|
+
</View>
|
1138
|
+
)
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
const uhh = StyleSheet.create(
|
1142
|
+
{
|
1143
|
+
dkk: () => ({
|
1144
|
+
backgroundColor: 'red'
|
1145
|
+
})
|
1146
|
+
},
|
1147
|
+
921918562
|
1148
|
+
)
|
1149
|
+
`
|
1150
|
+
},
|
1151
|
+
{
|
1152
|
+
title: 'Should pass ref for dynamic functions to bind it to shadow node',
|
1153
|
+
code: `
|
1154
|
+
import { View } from 'react-native'
|
1155
|
+
import { StyleSheet } from 'react-native-unistyles'
|
1156
|
+
|
1157
|
+
export const Example = () => {
|
1158
|
+
return (
|
1159
|
+
<React.Fragment>
|
1160
|
+
<View style={styles.container(1, 5)} />
|
1161
|
+
<View style={styles.container(2, 6)} />
|
1162
|
+
<View style={styles.container(5, 1)} />
|
1163
|
+
</React.Fragment>
|
1164
|
+
)
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
const styles = StyleSheet.create({
|
1168
|
+
container: (flex, gap) => ({
|
1169
|
+
flex,
|
1170
|
+
gap
|
1171
|
+
})
|
1172
|
+
})
|
1173
|
+
`,
|
1174
|
+
output: `
|
1175
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
1176
|
+
import { View } from 'react-native'
|
1177
|
+
import { StyleSheet } from 'react-native-unistyles'
|
1178
|
+
|
1179
|
+
export const Example = () => {
|
1180
|
+
return (
|
1181
|
+
<React.Fragment>
|
1182
|
+
<View
|
1183
|
+
style={[styles.container(1, 5)]}
|
972
1184
|
ref={ref => {
|
973
|
-
UnistylesShadowRegistry.add(ref, styles.container)
|
1185
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, [1, 5])
|
974
1186
|
return () => UnistylesShadowRegistry.remove(ref, styles.container)
|
975
1187
|
}}
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
1188
|
+
/>
|
1189
|
+
<View
|
1190
|
+
style={[styles.container(2, 6)]}
|
1191
|
+
ref={ref => {
|
1192
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, [2, 6])
|
1193
|
+
return () => UnistylesShadowRegistry.remove(ref, styles.container)
|
1194
|
+
}}
|
1195
|
+
/>
|
1196
|
+
<View
|
1197
|
+
style={[styles.container(5, 1)]}
|
1198
|
+
ref={ref => {
|
1199
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, [5, 1])
|
1200
|
+
return () => UnistylesShadowRegistry.remove(ref, styles.container)
|
1201
|
+
}}
|
1202
|
+
/>
|
1203
|
+
</React.Fragment>
|
1204
|
+
)
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
const styles = StyleSheet.create(
|
1208
|
+
{
|
1209
|
+
container: (flex, gap) => ({
|
1210
|
+
flex,
|
1211
|
+
gap
|
1212
|
+
})
|
1213
|
+
},
|
1214
|
+
921918562
|
1215
|
+
)
|
1216
|
+
`
|
1217
|
+
},
|
1218
|
+
{
|
1219
|
+
title: 'Should pass refs for dynamic functions',
|
1220
|
+
code: `
|
1221
|
+
import { View } from 'react-native'
|
1222
|
+
import { StyleSheet } from 'react-native-unistyles'
|
1223
|
+
|
1224
|
+
export const Example = () => {
|
1225
|
+
return (
|
1226
|
+
<React.Fragment>
|
1227
|
+
<View style={[styles.container(1, 5), styles.container2(1, 6)]} />
|
1228
|
+
</React.Fragment>
|
980
1229
|
)
|
981
1230
|
}
|
982
1231
|
|
983
1232
|
const styles = StyleSheet.create({
|
984
|
-
container: () => ({
|
985
|
-
|
1233
|
+
container: (flex, gap) => ({
|
1234
|
+
flex,
|
1235
|
+
gap
|
986
1236
|
})
|
987
1237
|
})
|
1238
|
+
`,
|
1239
|
+
output: `
|
1240
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
1241
|
+
import { View } from 'react-native'
|
1242
|
+
import { StyleSheet } from 'react-native-unistyles'
|
1243
|
+
|
1244
|
+
export const Example = () => {
|
1245
|
+
return (
|
1246
|
+
<React.Fragment>
|
1247
|
+
<View
|
1248
|
+
style={[styles.container(1, 5), styles.container2(1, 6)]}
|
1249
|
+
ref={ref => {
|
1250
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, [1, 5])
|
1251
|
+
UnistylesShadowRegistry.add(ref, styles.container2, undefined, [1, 6])
|
1252
|
+
return () => {
|
1253
|
+
;(() => UnistylesShadowRegistry.remove(ref, styles.container))()
|
1254
|
+
UnistylesShadowRegistry.remove(ref, styles.container2)
|
1255
|
+
}
|
1256
|
+
}}
|
1257
|
+
/>
|
1258
|
+
</React.Fragment>
|
1259
|
+
)
|
1260
|
+
}
|
1261
|
+
|
1262
|
+
const styles = StyleSheet.create(
|
1263
|
+
{
|
1264
|
+
container: (flex, gap) => ({
|
1265
|
+
flex,
|
1266
|
+
gap
|
1267
|
+
})
|
1268
|
+
},
|
1269
|
+
921918562
|
1270
|
+
)
|
988
1271
|
`
|
989
1272
|
},
|
1273
|
+
{
|
1274
|
+
title: 'Should keep order of spreads',
|
1275
|
+
code: `
|
1276
|
+
import { View } from 'react-native'
|
1277
|
+
import { StyleSheet } from 'react-native-unistyles'
|
1278
|
+
|
1279
|
+
export const Example = () => {
|
1280
|
+
return (
|
1281
|
+
<View style={{...styles.container, ...styles.secondProp, ...styles.thirdProp}} />
|
1282
|
+
)
|
1283
|
+
}
|
1284
|
+
|
1285
|
+
const styles = StyleSheet.create(theme => ({
|
1286
|
+
container: {
|
1287
|
+
flex: 1,
|
1288
|
+
alignItems: 'center',
|
1289
|
+
justifyContent: 'center',
|
1290
|
+
backgroundColor: theme.colors.backgroundColor
|
1291
|
+
},
|
1292
|
+
secondProp: {
|
1293
|
+
marginHorizontal: theme.gap(10),
|
1294
|
+
backgroundColor: 'red'
|
1295
|
+
},
|
1296
|
+
thirdProp: {
|
1297
|
+
backgroundColor: 'blue'
|
1298
|
+
}
|
1299
|
+
}))
|
1300
|
+
`,
|
1301
|
+
output: `
|
1302
|
+
import { UnistylesShadowRegistry } from 'react-native-unistyles'
|
1303
|
+
import { View } from 'react-native'
|
1304
|
+
import { StyleSheet } from 'react-native-unistyles'
|
1305
|
+
|
1306
|
+
export const Example = () => {
|
1307
|
+
return (
|
1308
|
+
<View
|
1309
|
+
style={[styles.container, styles.secondProp, styles.thirdProp]}
|
1310
|
+
ref={ref => {
|
1311
|
+
UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
|
1312
|
+
UnistylesShadowRegistry.add(ref, styles.secondProp, undefined, undefined)
|
1313
|
+
UnistylesShadowRegistry.add(ref, styles.thirdProp, undefined, undefined)
|
1314
|
+
return () => {
|
1315
|
+
;(() => {
|
1316
|
+
;(() => UnistylesShadowRegistry.remove(ref, styles.container))()
|
1317
|
+
UnistylesShadowRegistry.remove(ref, styles.secondProp)
|
1318
|
+
})()
|
1319
|
+
UnistylesShadowRegistry.remove(ref, styles.thirdProp)
|
1320
|
+
}
|
1321
|
+
}}
|
1322
|
+
/>
|
1323
|
+
)
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
const styles = StyleSheet.create(
|
1327
|
+
theme => ({
|
1328
|
+
container: {
|
1329
|
+
flex: 1,
|
1330
|
+
alignItems: 'center',
|
1331
|
+
justifyContent: 'center',
|
1332
|
+
backgroundColor: theme.colors.backgroundColor,
|
1333
|
+
uni__dependencies: [0]
|
1334
|
+
},
|
1335
|
+
secondProp: {
|
1336
|
+
marginHorizontal: theme.gap(10),
|
1337
|
+
backgroundColor: 'red',
|
1338
|
+
uni__dependencies: [0]
|
1339
|
+
},
|
1340
|
+
thirdProp: {
|
1341
|
+
backgroundColor: 'blue'
|
1342
|
+
}
|
1343
|
+
}),
|
1344
|
+
921918562
|
1345
|
+
)
|
1346
|
+
`
|
1347
|
+
}
|
990
1348
|
]
|
991
1349
|
})
|