react-native-unistyles 3.0.0-alpha.43 → 3.0.0-alpha.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/lib/commonjs/components/Pressable.js +6 -14
  2. package/lib/commonjs/components/Pressable.js.map +1 -1
  3. package/lib/commonjs/components/Pressable.web.js +35 -17
  4. package/lib/commonjs/components/Pressable.web.js.map +1 -1
  5. package/lib/commonjs/web/shadowRegistry.js +18 -17
  6. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  7. package/lib/commonjs/web/utils/unistyle.js +2 -8
  8. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  9. package/lib/module/components/Pressable.js +6 -14
  10. package/lib/module/components/Pressable.js.map +1 -1
  11. package/lib/module/components/Pressable.web.js +35 -17
  12. package/lib/module/components/Pressable.web.js.map +1 -1
  13. package/lib/module/web/shadowRegistry.js +18 -17
  14. package/lib/module/web/shadowRegistry.js.map +1 -1
  15. package/lib/module/web/utils/unistyle.js +2 -8
  16. package/lib/module/web/utils/unistyle.js.map +1 -1
  17. package/lib/typescript/src/components/Pressable.d.ts +2 -1
  18. package/lib/typescript/src/components/Pressable.d.ts.map +1 -1
  19. package/lib/typescript/src/components/Pressable.web.d.ts +2 -1
  20. package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -1
  21. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -1
  22. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  23. package/lib/typescript/src/web/utils/unistyle.d.ts +1 -1
  24. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  25. package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
  26. package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
  27. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +5 -1
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +5 -1
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +5 -1
  31. package/package.json +3 -3
  32. package/plugin/index.js +1 -1
  33. package/plugin/style.js +94 -20
  34. package/plugin/stylesheet.js +1 -1
  35. package/src/components/Pressable.tsx +10 -22
  36. package/src/components/Pressable.web.tsx +54 -28
  37. package/src/web/shadowRegistry.ts +51 -47
  38. package/src/web/utils/unistyle.ts +2 -10
@@ -21,18 +21,18 @@ class UnistylesShadowRegistryBuilder {
21
21
  private hashMap = new Map<HTMLElement, string>()
22
22
  private classNamesMap = new Map<HTMLElement, Array<string>>()
23
23
 
24
- add = (ref: any, _style: Array<Style>, _variants: Record<string, any> | undefined, _args: Array<Array<any>>) => {
25
- // Style is not provided
26
- if (!_style) {
24
+ add = (ref: any, styles: Array<Style>, _variants: Record<string, any> | undefined, _args: Array<Array<any>>) => {
25
+ // Styles are not provided
26
+ if (!styles) {
27
27
  return
28
28
  }
29
29
 
30
30
  // Ref is unmounted, remove style tags from the document
31
31
  if (ref === null) {
32
- const secrets = extractSecrets(_style)
32
+ const secrets = extractSecrets(styles)
33
33
 
34
- secrets.forEach(({ __uni__refs }) => {
35
- __uni__refs.forEach(ref => {
34
+ if (secrets) {
35
+ secrets.__uni__refs.forEach(ref => {
36
36
  if (isInDocument(ref)) {
37
37
  return
38
38
  }
@@ -45,7 +45,7 @@ class UnistylesShadowRegistryBuilder {
45
45
  UnistylesRegistry.remove(oldResult)
46
46
  }
47
47
  })
48
- })
48
+ }
49
49
 
50
50
  return
51
51
  }
@@ -55,56 +55,60 @@ class UnistylesShadowRegistryBuilder {
55
55
  return
56
56
  }
57
57
 
58
- const styles = _style.filter(style => Object.keys(style ?? {}).some(key => key.startsWith('__uni__')))
58
+ const parsedStyles = styles.flat().flatMap((unistyleStyle, styleIndex) => {
59
+ if (!unistyleStyle) {
60
+ return []
61
+ }
59
62
 
60
- // No unistyles
61
- if (styles.length === 0) {
62
- return
63
- }
63
+ const secrets = extractSecrets(unistyleStyle)
64
64
 
65
- const parsedStyles = styles.flatMap((style, styleIndex) => extractSecrets(style).map(secret => {
66
- const { __uni__key, __uni__stylesheet, __uni__variants, __uni__args = [], __uni__refs } = secret
67
- const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
68
- const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
69
- const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
70
- const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args
71
- const result = typeof style === 'function'
72
- ? style(...args)
73
- : style
74
- const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
75
- const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
76
- const dependencies = extractUnistyleDependencies(resultWithVariants)
77
-
78
- if (typeof __uni__stylesheet === 'function') {
79
- // Add dependencies from dynamic styles to stylesheet
80
- UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
65
+ // Regular style
66
+ if (!secrets) {
67
+ return unistyleStyle as UnistylesValues
81
68
  }
82
69
 
83
- __uni__refs.add(ref)
70
+ const { __uni__key, __uni__stylesheet, __uni__variants, __uni__args = [], __uni__refs } = secrets
71
+ const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
72
+ const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
73
+ const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
74
+ const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args
75
+ const result = typeof style === 'function'
76
+ ? style(...args)
77
+ : style
78
+ const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
79
+ const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
80
+ const dependencies = extractUnistyleDependencies(resultWithVariants)
84
81
 
85
- const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(resultWithVariants), () => {
86
- const hash = this.hashMap.get(ref)
82
+ if (typeof __uni__stylesheet === 'function') {
83
+ // Add dependencies from dynamic styles to stylesheet
84
+ UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
85
+ }
87
86
 
88
- // Dispose listener if there is no hash
89
- if (!hash) {
90
- dispose()
87
+ __uni__refs.add(ref)
91
88
 
92
- return
93
- }
89
+ const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(resultWithVariants), () => {
90
+ const hash = this.hashMap.get(ref)
94
91
 
95
- const newComputedStyleSheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
96
- const newValue = newComputedStyleSheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
97
- const result = typeof newValue === 'function'
98
- ? newValue(...args)
99
- : newValue
100
- const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
101
- const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
92
+ // Dispose listener if there is no hash
93
+ if (!hash) {
94
+ dispose()
102
95
 
103
- UnistylesRegistry.applyStyles(hash, convertUnistyles(resultWithVariants))
104
- })
96
+ return
97
+ }
98
+
99
+ const newComputedStyleSheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
100
+ const newValue = newComputedStyleSheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
101
+ const result = typeof newValue === 'function'
102
+ ? newValue(...args)
103
+ : newValue
104
+ const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
105
+ const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
106
+
107
+ UnistylesRegistry.applyStyles(hash, convertUnistyles(resultWithVariants))
108
+ })
105
109
 
106
- return resultWithVariants as UnistylesValues
107
- }))
110
+ return resultWithVariants as UnistylesValues
111
+ })
108
112
  const combinedStyles = deepMergeObjects(...parsedStyles)
109
113
  const oldStyles = this.resultsMap.get(ref)
110
114
 
@@ -25,21 +25,13 @@ export type UnistyleSecrets = {
25
25
 
26
26
  export const assignSecrets = <T>(object: T, secrets: UnistyleSecrets) => {
27
27
  // @ts-expect-error - assign secrets to object
28
- object[`__uni__secrets__${Math.random().toString(16).slice(2)}`] = secrets
28
+ object.__uni__secrets__ = secrets
29
29
 
30
30
  return object
31
31
  }
32
32
 
33
33
  export const extractSecrets = (object: any) => {
34
- const secrets = Object.entries(object).reduce((acc, [key, value]) => {
35
- if (key.startsWith('__uni__secrets__')) {
36
- acc.push(value as UnistyleSecrets)
37
- }
38
-
39
- return acc
40
- }, [] as Array<UnistyleSecrets>)
41
-
42
- return secrets
34
+ return keyInObject(object, '__uni__secrets__') ? object.__uni__secrets__ as UnistyleSecrets : undefined
43
35
  }
44
36
 
45
37
  export const getStyles = (values: UnistylesValues) => {