react-native-unistyles 3.0.0-alpha.26 → 3.0.0-alpha.27

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