react-native-unistyles 3.0.0-rc.1 → 3.0.0-rc.3

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 (200) hide show
  1. package/README.md +18 -18
  2. package/Unistyles.podspec +1 -0
  3. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
  4. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +2 -3
  5. package/components/native/ActivityIndicator/package.json +1 -0
  6. package/components/native/Animated/package.json +1 -0
  7. package/components/native/FlatList/package.json +1 -0
  8. package/components/native/Image/package.json +2 -1
  9. package/components/native/ImageBackground/package.json +1 -0
  10. package/components/native/KeyboardAvoidingView/package.json +1 -0
  11. package/components/native/NativeText/package.json +1 -0
  12. package/components/native/NativeView/package.json +1 -0
  13. package/components/native/Pressable/package.json +1 -0
  14. package/components/native/RefreshControl/package.json +1 -0
  15. package/components/native/ScrollView/package.json +1 -0
  16. package/components/native/SectionList/package.json +1 -0
  17. package/components/native/Switch/package.json +1 -0
  18. package/components/native/Text/package.json +1 -0
  19. package/components/native/TextInput/package.json +1 -0
  20. package/components/native/TouchableHighlight/package.json +1 -0
  21. package/components/native/TouchableOpacity/package.json +1 -0
  22. package/components/native/View/package.json +1 -0
  23. package/components/native/VirtualizedList/package.json +1 -0
  24. package/ios/NativePlatform+ios.swift +1 -1
  25. package/ios/NativePlatformListener+ios.swift +12 -7
  26. package/lib/commonjs/components/native/Image.js +4 -3
  27. package/lib/commonjs/components/native/Image.js.map +1 -1
  28. package/lib/commonjs/components/native/ImageBackground.js +3 -2
  29. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  30. package/lib/commonjs/core/createUnistylesElement.js +17 -5
  31. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  32. package/lib/commonjs/core/getClassname.js +10 -4
  33. package/lib/commonjs/core/getClassname.js.map +1 -1
  34. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  35. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  36. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -1
  37. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  38. package/lib/commonjs/core/withUnistyles/withUnistyles.js +2 -1
  39. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  40. package/lib/commonjs/hooks/useMedia.js +4 -4
  41. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  42. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  43. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  44. package/lib/commonjs/mocks.js +203 -0
  45. package/lib/commonjs/mocks.js.map +1 -0
  46. package/lib/commonjs/mq.js +1 -23
  47. package/lib/commonjs/mq.js.map +1 -1
  48. package/lib/commonjs/server/getServerUnistyles.js +5 -3
  49. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  50. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  51. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  52. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  53. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  54. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  55. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  56. package/lib/commonjs/utils.js +23 -1
  57. package/lib/commonjs/utils.js.map +1 -1
  58. package/lib/commonjs/web/convert/index.js +4 -7
  59. package/lib/commonjs/web/convert/index.js.map +1 -1
  60. package/lib/commonjs/web/convert/object/filter.js +7 -8
  61. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  62. package/lib/commonjs/web/create.js +6 -4
  63. package/lib/commonjs/web/create.js.map +1 -1
  64. package/lib/commonjs/web/css/core.js +2 -2
  65. package/lib/commonjs/web/css/core.js.map +1 -1
  66. package/lib/commonjs/web/css/state.js +1 -1
  67. package/lib/commonjs/web/css/state.js.map +1 -1
  68. package/lib/commonjs/web/index.js +7 -12
  69. package/lib/commonjs/web/index.js.map +1 -1
  70. package/lib/commonjs/web/services.js +7 -2
  71. package/lib/commonjs/web/services.js.map +1 -1
  72. package/lib/commonjs/web/shadowRegistry.js +11 -3
  73. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  74. package/lib/commonjs/web/utils/createUnistylesRef.js +7 -4
  75. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  76. package/lib/commonjs/web/utils/index.js +0 -11
  77. package/lib/commonjs/web/utils/index.js.map +1 -1
  78. package/lib/commonjs/web/utils/unistyle.js +35 -12
  79. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  80. package/lib/module/components/native/Image.js +4 -3
  81. package/lib/module/components/native/Image.js.map +1 -1
  82. package/lib/module/components/native/ImageBackground.js +2 -1
  83. package/lib/module/components/native/ImageBackground.js.map +1 -1
  84. package/lib/module/core/createUnistylesElement.js +18 -6
  85. package/lib/module/core/createUnistylesElement.js.map +1 -1
  86. package/lib/module/core/getClassname.js +8 -4
  87. package/lib/module/core/getClassname.js.map +1 -1
  88. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  89. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  90. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -1
  91. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  92. package/lib/module/core/withUnistyles/withUnistyles.js +2 -1
  93. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  94. package/lib/module/hooks/useMedia.js +1 -1
  95. package/lib/module/hooks/useMedia.js.map +1 -1
  96. package/lib/module/hooks/useMedia.native.js +1 -1
  97. package/lib/module/hooks/useMedia.native.js.map +1 -1
  98. package/lib/module/mocks.js +201 -0
  99. package/lib/module/mocks.js.map +1 -0
  100. package/lib/module/mq.js +0 -19
  101. package/lib/module/mq.js.map +1 -1
  102. package/lib/module/server/getServerUnistyles.js +3 -3
  103. package/lib/module/server/getServerUnistyles.js.map +1 -1
  104. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  105. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  106. package/lib/module/server/resetServerUnistyles.js +2 -2
  107. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  108. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  109. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  110. package/lib/module/utils.js +19 -0
  111. package/lib/module/utils.js.map +1 -1
  112. package/lib/module/web/convert/index.js +4 -7
  113. package/lib/module/web/convert/index.js.map +1 -1
  114. package/lib/module/web/convert/object/filter.js +3 -4
  115. package/lib/module/web/convert/object/filter.js.map +1 -1
  116. package/lib/module/web/create.js +4 -4
  117. package/lib/module/web/create.js.map +1 -1
  118. package/lib/module/web/css/core.js +2 -2
  119. package/lib/module/web/css/core.js.map +1 -1
  120. package/lib/module/web/css/state.js +1 -1
  121. package/lib/module/web/css/state.js.map +1 -1
  122. package/lib/module/web/index.js +4 -10
  123. package/lib/module/web/index.js.map +1 -1
  124. package/lib/module/web/services.js +7 -1
  125. package/lib/module/web/services.js.map +1 -1
  126. package/lib/module/web/shadowRegistry.js +10 -2
  127. package/lib/module/web/shadowRegistry.js.map +1 -1
  128. package/lib/module/web/utils/createUnistylesRef.js +5 -4
  129. package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
  130. package/lib/module/web/utils/index.js +0 -1
  131. package/lib/module/web/utils/index.js.map +1 -1
  132. package/lib/module/web/utils/unistyle.js +28 -9
  133. package/lib/module/web/utils/unistyle.js.map +1 -1
  134. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  135. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  136. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  137. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  138. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  139. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  140. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  141. package/lib/typescript/src/mocks.d.ts +2 -0
  142. package/lib/typescript/src/mocks.d.ts.map +1 -0
  143. package/lib/typescript/src/mq.d.ts +0 -8
  144. package/lib/typescript/src/mq.d.ts.map +1 -1
  145. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  146. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  147. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  148. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  149. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  150. package/lib/typescript/src/utils.d.ts +8 -0
  151. package/lib/typescript/src/utils.d.ts.map +1 -1
  152. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  153. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  154. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  155. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  156. package/lib/typescript/src/web/index.d.ts +0 -5
  157. package/lib/typescript/src/web/index.d.ts.map +1 -1
  158. package/lib/typescript/src/web/services.d.ts +6 -1
  159. package/lib/typescript/src/web/services.d.ts.map +1 -1
  160. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  161. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +8 -5
  162. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  163. package/lib/typescript/src/web/utils/index.d.ts +0 -1
  164. package/lib/typescript/src/web/utils/index.d.ts.map +1 -1
  165. package/lib/typescript/src/web/utils/unistyle.d.ts +3 -1
  166. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  167. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  168. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  169. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  170. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  171. package/package.json +23 -9
  172. package/plugin/index.js +137 -65
  173. package/server/package.json +6 -0
  174. package/src/components/native/Image.tsx +4 -3
  175. package/src/components/native/ImageBackground.tsx +2 -1
  176. package/src/core/createUnistylesElement.tsx +26 -9
  177. package/src/core/getClassname.ts +14 -4
  178. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  179. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +1 -0
  180. package/src/core/withUnistyles/withUnistyles.tsx +2 -1
  181. package/src/hooks/useMedia.native.ts +1 -1
  182. package/src/hooks/useMedia.ts +1 -1
  183. package/src/mocks.ts +217 -0
  184. package/src/mq.ts +0 -24
  185. package/src/server/getServerUnistyles.tsx +3 -3
  186. package/src/server/hydrateServerUnistyles.ts +3 -2
  187. package/src/server/resetServerUnistyles.ts +4 -3
  188. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  189. package/src/utils.ts +25 -0
  190. package/src/web/convert/index.ts +5 -7
  191. package/src/web/convert/object/filter.ts +4 -4
  192. package/src/web/create.ts +4 -4
  193. package/src/web/css/core.ts +2 -2
  194. package/src/web/css/state.ts +1 -1
  195. package/src/web/index.ts +4 -16
  196. package/src/web/services.ts +14 -1
  197. package/src/web/shadowRegistry.ts +10 -2
  198. package/src/web/utils/createUnistylesRef.ts +12 -8
  199. package/src/web/utils/index.ts +0 -1
  200. package/src/web/utils/unistyle.ts +50 -21
@@ -1,9 +1,10 @@
1
+ import { Animated } from 'react-native'
1
2
  import type { UnistylesBreakpoints } from '../../global'
2
- import { isUnistylesMq, parseMq } from '../../mq'
3
- import type { UnistyleDependency } from '../../specs/NativePlatform'
3
+ import type { UnistyleDependency } from '../../specs/NativePlatform/NativePlatform.nitro'
4
4
  import { ColorScheme, Orientation } from '../../specs/types'
5
5
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
6
- import { UnistylesWeb } from '../index'
6
+ import { isUnistylesMq, parseMq } from '../../utils'
7
+ import * as unistyles from '../services'
7
8
  import { keyInObject, reduceObject } from './common'
8
9
 
9
10
  export const schemeToTheme = (scheme: ColorScheme) => {
@@ -49,13 +50,7 @@ export const extractSecrets = (object: any) => {
49
50
  return undefined
50
51
  }
51
52
 
52
- const hiddenSecrets = Object.getOwnPropertyDescriptors(secrets)
53
-
54
- if (Object.keys(hiddenSecrets).length === 0) {
55
- return undefined
56
- }
57
-
58
- return reduceObject(hiddenSecrets, secret => secret.value)
53
+ return reduceObject(Object.getOwnPropertyDescriptors(secrets), secret => secret.value)
59
54
  }
60
55
 
61
56
  export const removeInlineStyles = (values: UnistylesValues) => {
@@ -87,18 +82,18 @@ export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
87
82
  return `@media ${queries}`
88
83
  }
89
84
 
90
- const breakpointValue = UnistylesWeb.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
85
+ const breakpointValue = unistyles.services.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
91
86
  const nextBreakpoint = allBreakpoints
92
- .filter((b): b is keyof UnistylesBreakpoints => b in UnistylesWeb.runtime.breakpoints)
93
- .map(b => UnistylesWeb.runtime.breakpoints[b] as number)
94
- .sort((a, b) => a - b)
95
- .find(b => b > breakpointValue)
96
- const queries = [
97
- `(min-width: ${breakpointValue}px)`,
98
- nextBreakpoint ? `(max-width: ${nextBreakpoint - 1}px)` : undefined,
99
- ].filter(Boolean).join(' and ')
100
-
101
- return `@media ${queries}`
87
+ .filter((b): b is keyof UnistylesBreakpoints => b in unistyles.services.runtime.breakpoints)
88
+ .map(b => unistyles.services.runtime.breakpoints[b] as number)
89
+ .sort((a, b) => a - b)
90
+ .find(b => b > breakpointValue)
91
+ const queries = [
92
+ `(min-width: ${breakpointValue}px)`,
93
+ nextBreakpoint ? `(max-width: ${nextBreakpoint - 1}px)` : undefined,
94
+ ].filter(Boolean).join(' and ')
95
+
96
+ return `@media ${queries}`
102
97
  }
103
98
 
104
99
  export const extractUnistyleDependencies = (value: any) => {
@@ -110,3 +105,37 @@ export const extractUnistyleDependencies = (value: any) => {
110
105
 
111
106
  return Array.isArray(dependencies) ? dependencies : []
112
107
  }
108
+
109
+ export const checkForProp = (value: any, prop: string): boolean => {
110
+ if (Array.isArray(value)) {
111
+ return value.some(nestedValue => checkForProp(nestedValue, prop))
112
+ }
113
+
114
+ if (typeof value === 'object' && value !== null) {
115
+ return keyInObject(value, prop)
116
+ ? true
117
+ : keyInObject(value, '_web')
118
+ ? checkForProp(value._web, prop)
119
+ : false
120
+ }
121
+
122
+ return false
123
+ }
124
+
125
+ export const checkForAnimated = (value: any): boolean => {
126
+ if (Array.isArray(value)) {
127
+ return value.some(checkForAnimated)
128
+ }
129
+
130
+ if (typeof value === 'object' && value !== null) {
131
+ const objectValues = Object.values(value)
132
+ const secrets = extractSecrets(value)
133
+
134
+ // @ts-expect-error React Native Web exports Animated.AnimatedNode as Animated.Node
135
+ return value instanceof Animated.Node ||
136
+ objectValues.length > 0 && objectValues.some(checkForAnimated) ||
137
+ secrets && Object.keys(secrets).length === 0
138
+ }
139
+
140
+ return false
141
+ }