react-native-unistyles 3.0.0-beta.4 → 3.0.0-beta.6

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 (543) hide show
  1. package/README.md +18 -3
  2. package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -2
  3. package/android/src/main/cxx/NativeUnistylesModule.h +1 -1
  4. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -2
  5. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +4 -0
  6. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +2 -1
  7. package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -4
  8. package/android/src/main/java/com/unistyles/UnistylesPackage.kt +6 -6
  9. package/components/native/ActivityIndicator/package.json +2 -1
  10. package/components/native/Animated/package.json +5 -0
  11. package/components/native/FlatList/package.json +2 -1
  12. package/components/native/Image/package.json +2 -1
  13. package/components/native/ImageBackground/package.json +2 -1
  14. package/components/native/KeyboardAvoidingView/package.json +2 -1
  15. package/components/native/NativeText/package.json +5 -0
  16. package/components/native/NativeView/package.json +5 -0
  17. package/components/native/Pressable/package.json +1 -1
  18. package/components/native/RefreshControl/package.json +2 -1
  19. package/components/native/ScrollView/package.json +2 -1
  20. package/components/native/SectionList/package.json +2 -1
  21. package/components/native/Switch/package.json +2 -1
  22. package/components/native/Text/package.json +2 -1
  23. package/components/native/TextInput/package.json +2 -1
  24. package/components/native/TouchableHighlight/package.json +2 -1
  25. package/components/native/TouchableOpacity/package.json +2 -1
  26. package/components/native/View/package.json +2 -1
  27. package/components/native/VirtualizedList/package.json +2 -1
  28. package/cxx/common/Constants.h +4 -4
  29. package/cxx/common/Helpers.h +1 -1
  30. package/cxx/core/HashGenerator.cpp +23 -0
  31. package/cxx/core/HashGenerator.h +13 -0
  32. package/cxx/core/HostUnistyle.cpp +83 -0
  33. package/cxx/core/HostUnistyle.h +27 -0
  34. package/cxx/core/RNStyle.h +18 -0
  35. package/cxx/core/Unistyle.h +13 -4
  36. package/cxx/core/UnistyleWrapper.h +92 -47
  37. package/cxx/core/UnistylesRegistry.cpp +40 -11
  38. package/cxx/core/UnistylesRegistry.h +5 -4
  39. package/cxx/hybridObjects/HybridNavigationBar.cpp +3 -3
  40. package/cxx/hybridObjects/HybridNavigationBar.h +2 -2
  41. package/cxx/hybridObjects/HybridShadowRegistry.cpp +39 -45
  42. package/cxx/hybridObjects/HybridShadowRegistry.h +0 -10
  43. package/cxx/hybridObjects/HybridStatusBar.cpp +3 -3
  44. package/cxx/hybridObjects/HybridStatusBar.h +2 -2
  45. package/cxx/hybridObjects/HybridStyleSheet.cpp +52 -10
  46. package/cxx/hybridObjects/HybridStyleSheet.h +2 -1
  47. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -15
  48. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -2
  49. package/cxx/parser/Parser.cpp +26 -27
  50. package/cxx/parser/Parser.h +2 -1
  51. package/ios/NativePlatform+ios.swift +21 -11
  52. package/ios/NativePlatform.swift +2 -2
  53. package/ios/UnistylesModuleOnLoad.h +4 -4
  54. package/ios/UnistylesModuleOnLoad.mm +5 -8
  55. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  56. package/lib/commonjs/components/index.js +0 -7
  57. package/lib/commonjs/components/index.js.map +1 -1
  58. package/lib/commonjs/components/native/Animated.js +23 -0
  59. package/lib/commonjs/components/native/Animated.js.map +1 -0
  60. package/lib/commonjs/components/native/ImageBackground.js +47 -1
  61. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  62. package/lib/commonjs/components/native/ImageBackground.native.js +10 -0
  63. package/lib/commonjs/components/native/ImageBackground.native.js.map +1 -0
  64. package/lib/commonjs/components/native/NativeText.js +13 -0
  65. package/lib/commonjs/components/native/NativeText.js.map +1 -0
  66. package/lib/commonjs/components/native/NativeText.native.js +18 -0
  67. package/lib/commonjs/components/native/NativeText.native.js.map +1 -0
  68. package/lib/commonjs/components/native/NativeView.js +9 -0
  69. package/lib/commonjs/components/native/NativeView.js.map +1 -0
  70. package/lib/commonjs/components/native/NativeView.native.js +20 -0
  71. package/lib/commonjs/components/native/NativeView.native.js.map +1 -0
  72. package/lib/commonjs/components/native/Pressable.js +26 -51
  73. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  74. package/lib/commonjs/components/native/Pressable.native.js +25 -9
  75. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  76. package/lib/commonjs/core/createUnistylesElement.js +33 -5
  77. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  78. package/lib/commonjs/core/createUnistylesElement.native.js +54 -0
  79. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -0
  80. package/lib/commonjs/core/createUnistylesImageBackground.js +41 -15
  81. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  82. package/lib/commonjs/core/getClassname.js +23 -0
  83. package/lib/commonjs/core/getClassname.js.map +1 -0
  84. package/lib/commonjs/core/getClassname.native.js +9 -0
  85. package/lib/commonjs/core/getClassname.native.js.map +1 -0
  86. package/lib/commonjs/core/index.js +14 -7
  87. package/lib/commonjs/core/index.js.map +1 -1
  88. package/lib/commonjs/core/passForwardRef.js +2 -2
  89. package/lib/commonjs/core/passForwardRef.js.map +1 -1
  90. package/lib/commonjs/core/useProxifiedUnistyles/index.js +13 -0
  91. package/lib/commonjs/core/useProxifiedUnistyles/index.js.map +1 -0
  92. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +22 -0
  93. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -0
  94. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +26 -0
  95. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -0
  96. package/lib/commonjs/core/useProxifiedUnistyles/types.js +6 -0
  97. package/lib/commonjs/core/useProxifiedUnistyles/types.js.map +1 -0
  98. package/lib/commonjs/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +22 -22
  99. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
  100. package/lib/commonjs/core/useUnistyles.js +19 -0
  101. package/lib/commonjs/core/useUnistyles.js.map +1 -0
  102. package/lib/commonjs/core/warn.js +16 -0
  103. package/lib/commonjs/core/warn.js.map +1 -0
  104. package/lib/commonjs/core/withUnistyles/withUnistyles.js +19 -55
  105. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  106. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +32 -65
  107. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  108. package/lib/commonjs/index.js +23 -4
  109. package/lib/commonjs/index.js.map +1 -1
  110. package/lib/commonjs/server/getServerUnistyles.js +40 -0
  111. package/lib/commonjs/server/getServerUnistyles.js.map +1 -0
  112. package/lib/commonjs/server/hydrateServerUnistyles.js +17 -0
  113. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -0
  114. package/lib/commonjs/server/index.js +34 -0
  115. package/lib/commonjs/server/index.js.map +1 -0
  116. package/lib/commonjs/server/resetServerUnistyles.js +16 -0
  117. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -0
  118. package/lib/commonjs/server/types.js +8 -0
  119. package/lib/commonjs/server/types.js.map +1 -0
  120. package/lib/commonjs/server/useServerUnistyles.js +27 -0
  121. package/lib/commonjs/server/useServerUnistyles.js.map +1 -0
  122. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -3
  123. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  124. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  125. package/lib/commonjs/utils.js +19 -2
  126. package/lib/commonjs/utils.js.map +1 -1
  127. package/lib/commonjs/web/convert/object/filter.js +2 -2
  128. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  129. package/lib/commonjs/web/convert/style.js +4 -4
  130. package/lib/commonjs/web/convert/style.js.map +1 -1
  131. package/lib/commonjs/web/create.js +20 -15
  132. package/lib/commonjs/web/create.js.map +1 -1
  133. package/lib/commonjs/web/css/core.js +55 -0
  134. package/lib/commonjs/web/css/core.js.map +1 -0
  135. package/lib/commonjs/web/css/index.js +17 -0
  136. package/lib/commonjs/web/css/index.js.map +1 -0
  137. package/lib/commonjs/web/css/state.js +155 -0
  138. package/lib/commonjs/web/css/state.js.map +1 -0
  139. package/lib/commonjs/web/css/utils.js +47 -0
  140. package/lib/commonjs/web/css/utils.js.map +1 -0
  141. package/lib/commonjs/web/index.js +14 -18
  142. package/lib/commonjs/web/index.js.map +1 -1
  143. package/lib/commonjs/web/listener.js +9 -7
  144. package/lib/commonjs/web/listener.js.map +1 -1
  145. package/lib/commonjs/web/registry.js +44 -123
  146. package/lib/commonjs/web/registry.js.map +1 -1
  147. package/lib/commonjs/web/runtime.js +28 -21
  148. package/lib/commonjs/web/runtime.js.map +1 -1
  149. package/lib/commonjs/web/services.js +28 -0
  150. package/lib/commonjs/web/services.js.map +1 -0
  151. package/lib/commonjs/web/shadowRegistry.js +46 -93
  152. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  153. package/lib/commonjs/web/state.js +39 -9
  154. package/lib/commonjs/web/state.js.map +1 -1
  155. package/lib/commonjs/web/types.js +6 -0
  156. package/lib/commonjs/web/types.js.map +1 -0
  157. package/lib/commonjs/web/utils/common.js +29 -9
  158. package/lib/commonjs/web/utils/common.js.map +1 -1
  159. package/lib/commonjs/web/utils/unistyle.js +32 -19
  160. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  161. package/lib/commonjs/web/variants.js +25 -27
  162. package/lib/commonjs/web/variants.js.map +1 -1
  163. package/lib/module/components/ScopedTheme.js.map +1 -1
  164. package/lib/module/components/index.js +0 -1
  165. package/lib/module/components/index.js.map +1 -1
  166. package/lib/module/components/native/Animated.js +19 -0
  167. package/lib/module/components/native/Animated.js.map +1 -0
  168. package/lib/module/components/native/ImageBackground.js +47 -2
  169. package/lib/module/components/native/ImageBackground.js.map +1 -1
  170. package/lib/module/components/native/ImageBackground.native.js +6 -0
  171. package/lib/module/components/native/ImageBackground.native.js.map +1 -0
  172. package/lib/module/components/native/NativeText.js +4 -0
  173. package/lib/module/components/native/NativeText.js.map +1 -0
  174. package/lib/module/components/native/NativeText.native.js +15 -0
  175. package/lib/module/components/native/NativeText.native.js.map +1 -0
  176. package/lib/module/components/native/NativeView.js +5 -0
  177. package/lib/module/components/native/NativeView.js.map +1 -0
  178. package/lib/module/components/native/NativeView.native.js +17 -0
  179. package/lib/module/components/native/NativeView.native.js.map +1 -0
  180. package/lib/module/components/native/Pressable.js +27 -52
  181. package/lib/module/components/native/Pressable.js.map +1 -1
  182. package/lib/module/components/native/Pressable.native.js +26 -10
  183. package/lib/module/components/native/Pressable.native.js.map +1 -1
  184. package/lib/module/core/createUnistylesElement.js +33 -5
  185. package/lib/module/core/createUnistylesElement.js.map +1 -1
  186. package/lib/module/core/createUnistylesElement.native.js +47 -0
  187. package/lib/module/core/createUnistylesElement.native.js.map +1 -0
  188. package/lib/module/core/createUnistylesImageBackground.js +39 -14
  189. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  190. package/lib/module/core/getClassname.js +18 -0
  191. package/lib/module/core/getClassname.js.map +1 -0
  192. package/lib/module/core/getClassname.native.js +4 -0
  193. package/lib/module/core/getClassname.native.js.map +1 -0
  194. package/lib/module/core/index.js +2 -1
  195. package/lib/module/core/index.js.map +1 -1
  196. package/lib/module/core/passForwardRef.js +2 -2
  197. package/lib/module/core/passForwardRef.js.map +1 -1
  198. package/lib/module/core/useProxifiedUnistyles/index.js +4 -0
  199. package/lib/module/core/useProxifiedUnistyles/index.js.map +1 -0
  200. package/lib/module/core/useProxifiedUnistyles/listener.js +17 -0
  201. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -0
  202. package/lib/module/core/useProxifiedUnistyles/listener.native.js +21 -0
  203. package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -0
  204. package/lib/module/core/useProxifiedUnistyles/types.js +4 -0
  205. package/lib/module/core/useProxifiedUnistyles/types.js.map +1 -0
  206. package/lib/module/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +19 -19
  207. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
  208. package/lib/module/core/useUnistyles.js +14 -0
  209. package/lib/module/core/useUnistyles.js.map +1 -0
  210. package/lib/module/core/warn.js +11 -0
  211. package/lib/module/core/warn.js.map +1 -0
  212. package/lib/module/core/withUnistyles/withUnistyles.js +19 -55
  213. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  214. package/lib/module/core/withUnistyles/withUnistyles.native.js +33 -66
  215. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  216. package/lib/module/index.js +3 -2
  217. package/lib/module/index.js.map +1 -1
  218. package/lib/module/server/getServerUnistyles.js +34 -0
  219. package/lib/module/server/getServerUnistyles.js.map +1 -0
  220. package/lib/module/server/hydrateServerUnistyles.js +12 -0
  221. package/lib/module/server/hydrateServerUnistyles.js.map +1 -0
  222. package/lib/module/server/index.js +7 -0
  223. package/lib/module/server/index.js.map +1 -0
  224. package/lib/module/server/resetServerUnistyles.js +11 -0
  225. package/lib/module/server/resetServerUnistyles.js.map +1 -0
  226. package/lib/module/server/types.js +4 -0
  227. package/lib/module/server/types.js.map +1 -0
  228. package/lib/module/server/useServerUnistyles.js +22 -0
  229. package/lib/module/server/useServerUnistyles.js.map +1 -0
  230. package/lib/module/specs/ShadowRegistry/index.js +6 -3
  231. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  232. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  233. package/lib/module/utils.js +16 -1
  234. package/lib/module/utils.js.map +1 -1
  235. package/lib/module/web/convert/object/filter.js +2 -2
  236. package/lib/module/web/convert/object/filter.js.map +1 -1
  237. package/lib/module/web/convert/style.js +4 -4
  238. package/lib/module/web/convert/style.js.map +1 -1
  239. package/lib/module/web/create.js +20 -15
  240. package/lib/module/web/create.js.map +1 -1
  241. package/lib/module/web/css/core.js +50 -0
  242. package/lib/module/web/css/core.js.map +1 -0
  243. package/lib/module/web/css/index.js +4 -0
  244. package/lib/module/web/css/index.js.map +1 -0
  245. package/lib/module/web/css/state.js +150 -0
  246. package/lib/module/web/css/state.js.map +1 -0
  247. package/lib/module/web/css/utils.js +41 -0
  248. package/lib/module/web/css/utils.js.map +1 -0
  249. package/lib/module/web/index.js +10 -5
  250. package/lib/module/web/index.js.map +1 -1
  251. package/lib/module/web/listener.js +8 -7
  252. package/lib/module/web/listener.js.map +1 -1
  253. package/lib/module/web/registry.js +44 -124
  254. package/lib/module/web/registry.js.map +1 -1
  255. package/lib/module/web/runtime.js +27 -21
  256. package/lib/module/web/runtime.js.map +1 -1
  257. package/lib/module/web/services.js +23 -0
  258. package/lib/module/web/services.js.map +1 -0
  259. package/lib/module/web/shadowRegistry.js +46 -94
  260. package/lib/module/web/shadowRegistry.js.map +1 -1
  261. package/lib/module/web/state.js +39 -10
  262. package/lib/module/web/state.js.map +1 -1
  263. package/lib/module/web/types.js +4 -0
  264. package/lib/module/web/types.js.map +1 -0
  265. package/lib/module/web/utils/common.js +26 -7
  266. package/lib/module/web/utils/common.js.map +1 -1
  267. package/lib/module/web/utils/unistyle.js +31 -17
  268. package/lib/module/web/utils/unistyle.js.map +1 -1
  269. package/lib/module/web/variants.js +25 -27
  270. package/lib/module/web/variants.js.map +1 -1
  271. package/lib/typescript/src/components/index.d.ts +0 -1
  272. package/lib/typescript/src/components/index.d.ts.map +1 -1
  273. package/lib/typescript/src/components/native/ActivityIndicator.d.ts +1 -1
  274. package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
  275. package/lib/typescript/src/components/native/Animated.d.ts +39 -0
  276. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -0
  277. package/lib/typescript/src/components/native/FlatList.d.ts +1 -1
  278. package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
  279. package/lib/typescript/src/components/native/Image.d.ts +1 -1
  280. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  281. package/lib/typescript/src/components/native/ImageBackground.d.ts +1 -2
  282. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  283. package/lib/typescript/src/components/native/ImageBackground.native.d.ts +2 -0
  284. package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -0
  285. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +1 -1
  286. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
  287. package/lib/typescript/src/components/native/NativeText.d.ts +2 -0
  288. package/lib/typescript/src/components/native/NativeText.d.ts.map +1 -0
  289. package/lib/typescript/src/components/native/NativeText.native.d.ts +2 -0
  290. package/lib/typescript/src/components/native/NativeText.native.d.ts.map +1 -0
  291. package/lib/typescript/src/components/native/NativeView.d.ts +3 -0
  292. package/lib/typescript/src/components/native/NativeView.d.ts.map +1 -0
  293. package/lib/typescript/src/components/native/NativeView.native.d.ts +3 -0
  294. package/lib/typescript/src/components/native/NativeView.native.d.ts.map +1 -0
  295. package/lib/typescript/src/components/native/Pressable.d.ts +3 -2
  296. package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
  297. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  298. package/lib/typescript/src/components/native/RefreshControl.d.ts +1 -1
  299. package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
  300. package/lib/typescript/src/components/native/ScrollView.d.ts +1 -1
  301. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
  302. package/lib/typescript/src/components/native/SectionList.d.ts +1 -1
  303. package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
  304. package/lib/typescript/src/components/native/Switch.d.ts +1 -1
  305. package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
  306. package/lib/typescript/src/components/native/Text.d.ts +1 -1
  307. package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
  308. package/lib/typescript/src/components/native/TextInput.d.ts +1 -1
  309. package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
  310. package/lib/typescript/src/components/native/TouchableHighlight.d.ts +1 -1
  311. package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
  312. package/lib/typescript/src/components/native/TouchableOpacity.d.ts +1 -1
  313. package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
  314. package/lib/typescript/src/components/native/View.d.ts +1 -1
  315. package/lib/typescript/src/components/native/View.d.ts.map +1 -1
  316. package/lib/typescript/src/components/native/VirtualizedList.d.ts +1 -1
  317. package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
  318. package/lib/typescript/src/core/createUnistylesElement.d.ts +1 -2
  319. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  320. package/lib/typescript/src/core/createUnistylesElement.native.d.ts +2 -0
  321. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -0
  322. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +2 -3
  323. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  324. package/lib/typescript/src/core/getClassname.d.ts +7 -0
  325. package/lib/typescript/src/core/getClassname.d.ts.map +1 -0
  326. package/lib/typescript/src/core/getClassname.native.d.ts +2 -0
  327. package/lib/typescript/src/core/getClassname.native.d.ts.map +1 -0
  328. package/lib/typescript/src/core/index.d.ts +2 -1
  329. package/lib/typescript/src/core/index.d.ts.map +1 -1
  330. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  331. package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts +2 -0
  332. package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts.map +1 -0
  333. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts +3 -0
  334. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -0
  335. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts +3 -0
  336. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -0
  337. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +7 -0
  338. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -0
  339. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +8 -0
  340. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -0
  341. package/lib/typescript/src/core/useUnistyles.d.ts +6 -0
  342. package/lib/typescript/src/core/useUnistyles.d.ts.map +1 -0
  343. package/lib/typescript/src/core/warn.d.ts +3 -0
  344. package/lib/typescript/src/core/warn.d.ts.map +1 -0
  345. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +0 -3
  346. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  347. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  348. package/lib/typescript/src/index.d.ts +3 -2
  349. package/lib/typescript/src/index.d.ts.map +1 -1
  350. package/lib/typescript/src/server/getServerUnistyles.d.ts +4 -0
  351. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -0
  352. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +8 -0
  353. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -0
  354. package/lib/typescript/src/server/index.d.ts +5 -0
  355. package/lib/typescript/src/server/index.d.ts.map +1 -0
  356. package/lib/typescript/src/server/resetServerUnistyles.d.ts +2 -0
  357. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -0
  358. package/lib/typescript/src/server/types.d.ts +5 -0
  359. package/lib/typescript/src/server/types.d.ts.map +1 -0
  360. package/lib/typescript/src/server/useServerUnistyles.d.ts +4 -0
  361. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -0
  362. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +0 -3
  363. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  364. package/lib/typescript/src/specs/StyleSheet/index.d.ts +5 -1
  365. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  366. package/lib/typescript/src/utils.d.ts +2 -0
  367. package/lib/typescript/src/utils.d.ts.map +1 -1
  368. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  369. package/lib/typescript/src/web/create.d.ts.map +1 -1
  370. package/lib/typescript/src/web/css/core.d.ts +3 -0
  371. package/lib/typescript/src/web/css/core.d.ts.map +1 -0
  372. package/lib/typescript/src/web/css/index.d.ts +2 -0
  373. package/lib/typescript/src/web/css/index.d.ts.map +1 -0
  374. package/lib/typescript/src/web/css/state.d.ts +30 -0
  375. package/lib/typescript/src/web/css/state.d.ts.map +1 -0
  376. package/lib/typescript/src/web/css/utils.d.ts +4 -0
  377. package/lib/typescript/src/web/css/utils.d.ts.map +1 -0
  378. package/lib/typescript/src/web/index.d.ts +7 -1
  379. package/lib/typescript/src/web/index.d.ts.map +1 -1
  380. package/lib/typescript/src/web/listener.d.ts +4 -3
  381. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  382. package/lib/typescript/src/web/registry.d.ts +11 -8
  383. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  384. package/lib/typescript/src/web/runtime.d.ts +6 -4
  385. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  386. package/lib/typescript/src/web/services.d.ts +15 -0
  387. package/lib/typescript/src/web/services.d.ts.map +1 -0
  388. package/lib/typescript/src/web/shadowRegistry.d.ts +10 -13
  389. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  390. package/lib/typescript/src/web/state.d.ts +7 -3
  391. package/lib/typescript/src/web/state.d.ts.map +1 -1
  392. package/lib/typescript/src/web/types.d.ts +13 -0
  393. package/lib/typescript/src/web/types.d.ts.map +1 -0
  394. package/lib/typescript/src/web/utils/common.d.ts +2 -1
  395. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  396. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -4
  397. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  398. package/lib/typescript/src/web/variants.d.ts +2 -2
  399. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  400. package/nitrogen/generated/android/c++/JColorScheme.hpp +2 -1
  401. package/nitrogen/generated/android/c++/JDimensions.hpp +2 -1
  402. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +36 -10
  403. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +53 -19
  404. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +5 -5
  405. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
  406. package/nitrogen/generated/android/c++/JInsets.hpp +2 -1
  407. package/nitrogen/generated/android/c++/JOrientation.hpp +2 -1
  408. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +2 -1
  409. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +2 -1
  410. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +1 -1
  411. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +10 -5
  412. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +43 -14
  413. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +43 -14
  414. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +10 -10
  415. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +13 -8
  416. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +1 -1
  417. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +1 -1
  418. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +19 -14
  419. package/nitrogen/generated/android/unistyles+autolinking.cmake +4 -1
  420. package/nitrogen/generated/android/unistyles+autolinking.gradle +1 -1
  421. package/nitrogen/generated/android/unistylesOnLoad.cpp +7 -3
  422. package/nitrogen/generated/android/unistylesOnLoad.hpp +1 -1
  423. package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
  424. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +21 -6
  425. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +105 -27
  426. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +5 -3
  427. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.cpp +1 -1
  428. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +92 -33
  429. package/nitrogen/generated/ios/swift/ColorScheme.swift +1 -1
  430. package/nitrogen/generated/ios/swift/Dimensions.swift +1 -1
  431. package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +46 -0
  432. package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +46 -0
  433. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +36 -23
  434. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +327 -0
  435. package/nitrogen/generated/ios/swift/Insets.swift +1 -1
  436. package/nitrogen/generated/ios/swift/Orientation.swift +1 -1
  437. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +1 -1
  438. package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +1 -1
  439. package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
  440. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -1
  441. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +1 -1
  442. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
  443. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +1 -1
  444. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
  445. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -1
  446. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
  447. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.cpp +1 -1
  448. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
  449. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +1 -1
  450. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
  451. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  452. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
  453. package/nitrogen/generated/shared/c++/Insets.hpp +1 -1
  454. package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
  455. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -2
  456. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -1
  457. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -1
  458. package/package.json +23 -14
  459. package/plugin/consts.js +63 -0
  460. package/plugin/exotic.js +54 -0
  461. package/plugin/import.js +1 -21
  462. package/plugin/index.d.ts +89 -0
  463. package/plugin/index.js +58 -96
  464. package/plugin/stylesheet.js +28 -1
  465. package/plugin/variants.js +49 -75
  466. package/src/components/ScopedTheme.tsx +1 -1
  467. package/src/components/index.ts +0 -1
  468. package/src/components/native/Animated.tsx +17 -0
  469. package/src/components/native/ImageBackground.native.tsx +4 -0
  470. package/src/components/native/ImageBackground.tsx +57 -2
  471. package/src/components/native/NativeText.native.tsx +12 -0
  472. package/src/components/native/NativeText.tsx +1 -0
  473. package/src/components/native/NativeView.native.tsx +13 -0
  474. package/src/components/native/NativeView.tsx +3 -0
  475. package/src/components/native/Pressable.native.tsx +32 -15
  476. package/src/components/native/Pressable.tsx +35 -69
  477. package/src/core/createUnistylesElement.native.tsx +51 -0
  478. package/src/core/createUnistylesElement.tsx +47 -8
  479. package/src/core/createUnistylesImageBackground.tsx +44 -18
  480. package/src/core/getClassname.native.ts +1 -0
  481. package/src/core/getClassname.ts +14 -0
  482. package/src/core/index.ts +2 -1
  483. package/src/core/passForwardRef.ts +1 -2
  484. package/src/core/useProxifiedUnistyles/index.ts +1 -0
  485. package/src/core/useProxifiedUnistyles/listener.native.ts +18 -0
  486. package/src/core/useProxifiedUnistyles/listener.ts +13 -0
  487. package/src/core/useProxifiedUnistyles/types.ts +7 -0
  488. package/src/core/{withUnistyles/useDependencies.ts → useProxifiedUnistyles/useProxifiedUnistyles.ts} +19 -26
  489. package/src/core/useUnistyles.ts +11 -0
  490. package/src/core/warn.ts +13 -0
  491. package/src/core/withUnistyles/withUnistyles.native.tsx +39 -68
  492. package/src/core/withUnistyles/withUnistyles.tsx +19 -56
  493. package/src/index.ts +3 -2
  494. package/src/server/getServerUnistyles.tsx +21 -0
  495. package/src/server/hydrateServerUnistyles.ts +17 -0
  496. package/src/server/index.ts +5 -0
  497. package/src/server/resetServerUnistyles.ts +9 -0
  498. package/src/server/types.ts +4 -0
  499. package/src/server/useServerUnistyles.tsx +22 -0
  500. package/src/specs/ShadowRegistry/index.ts +12 -9
  501. package/src/specs/StyleSheet/index.ts +6 -1
  502. package/src/utils.ts +32 -11
  503. package/src/web/convert/object/filter.ts +2 -2
  504. package/src/web/convert/style.ts +8 -7
  505. package/src/web/create.ts +23 -18
  506. package/src/web/css/core.ts +58 -0
  507. package/src/web/css/index.ts +1 -0
  508. package/src/web/css/state.ts +191 -0
  509. package/src/web/css/utils.ts +54 -0
  510. package/src/web/index.ts +18 -5
  511. package/src/web/listener.ts +8 -8
  512. package/src/web/registry.ts +47 -152
  513. package/src/web/runtime.ts +32 -22
  514. package/src/web/services.ts +28 -0
  515. package/src/web/shadowRegistry.ts +46 -104
  516. package/src/web/state.ts +46 -11
  517. package/src/web/types.ts +13 -0
  518. package/src/web/utils/common.ts +32 -8
  519. package/src/web/utils/unistyle.ts +46 -25
  520. package/src/web/variants.ts +27 -27
  521. package/cxx/core/HostStyle.cpp +0 -73
  522. package/cxx/core/HostStyle.h +0 -34
  523. package/lib/commonjs/components/Variants.js +0 -36
  524. package/lib/commonjs/components/Variants.js.map +0 -1
  525. package/lib/commonjs/core/createUnistylesComponent.js +0 -16
  526. package/lib/commonjs/core/createUnistylesComponent.js.map +0 -1
  527. package/lib/commonjs/core/withUnistyles/useDependencies.js.map +0 -1
  528. package/lib/module/components/Variants.js +0 -29
  529. package/lib/module/components/Variants.js.map +0 -1
  530. package/lib/module/core/createUnistylesComponent.js +0 -11
  531. package/lib/module/core/createUnistylesComponent.js.map +0 -1
  532. package/lib/module/core/withUnistyles/useDependencies.js.map +0 -1
  533. package/lib/typescript/src/components/Variants.d.ts +0 -7
  534. package/lib/typescript/src/components/Variants.d.ts.map +0 -1
  535. package/lib/typescript/src/core/createUnistylesComponent.d.ts +0 -14
  536. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +0 -1
  537. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +0 -13
  538. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +0 -1
  539. package/nitrogen/generated/android/unistylesOnLoad.kt +0 -1
  540. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +0 -314
  541. package/plugin/style.js +0 -168
  542. package/src/components/Variants.tsx +0 -30
  543. package/src/core/createUnistylesComponent.tsx +0 -14
@@ -42,6 +42,20 @@ function isUnistylesStyleSheet(t, path, state) {
42
42
  )
43
43
  }
44
44
 
45
+ function isKindOfStyleSheet(t, path, state) {
46
+ if (!state.file.forceProcessing) {
47
+ return false
48
+ }
49
+
50
+ const callee = path.get('callee')
51
+
52
+ return (
53
+ t.isMemberExpression(callee.node) &&
54
+ callee.node.property.name === 'create' &&
55
+ t.isIdentifier(callee.node.object)
56
+ )
57
+ }
58
+
45
59
  function addStyleSheetTag(t, path, state) {
46
60
  const callee = path.get('callee')
47
61
  const uniqueId = stringToUniqueId(state.filename.replace(state.cwd, '')) + ++state.file.tagNumber
@@ -49,6 +63,7 @@ function addStyleSheetTag(t, path, state) {
49
63
  callee.container.arguments.push(t.numericLiteral(uniqueId))
50
64
  }
51
65
 
66
+ /** @param {import('./index').UnistylesPluginPass} state */
52
67
  function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
53
68
  const debugMessage = deps => {
54
69
  if (state.opts.debug) {
@@ -204,9 +219,21 @@ function getUnistyles(t, property) {
204
219
  return []
205
220
  }
206
221
 
222
+ function addThemeDependencyToMemberExpression(t, path) {
223
+ path.value = t.objectExpression([
224
+ t.spreadElement(path.value),
225
+ t.objectProperty(
226
+ t.identifier('uni__dependencies'),
227
+ t.arrayExpression([t.numericLiteral(UnistyleDependency.Theme)])
228
+ )
229
+ ])
230
+ }
231
+
207
232
  module.exports = {
208
233
  isUnistylesStyleSheet,
209
234
  analyzeDependencies,
210
235
  addStyleSheetTag,
211
- getUnistyles
236
+ getUnistyles,
237
+ isKindOfStyleSheet,
238
+ addThemeDependencyToMemberExpression
212
239
  }
@@ -1,92 +1,66 @@
1
- function isUsingVariants(t, path) {
2
- const callee = path.get('callee')
3
-
4
- return (
5
- t.isMemberExpression(callee) &&
6
- t.isIdentifier(callee.node.object, { name: 'styles' }) &&
7
- t.isIdentifier(callee.node.property, { name: 'useVariants' }) &&
8
- t.isObjectExpression(path.node.arguments[0])
9
- )
10
- }
11
-
12
1
  function extractVariants(t, path, state) {
13
- const arg = path.node.arguments[0]
14
-
15
- const variantDeclaration = t.variableDeclaration('const', [
16
- t.variableDeclarator(
17
- t.identifier('__uni__variants'),
18
- arg
19
- )
20
- ])
21
-
22
- // Replace useVariants argument with __uni__variants
23
- path.node.arguments[0] = t.identifier('__uni__variants')
24
-
25
- path.insertBefore(variantDeclaration)
26
-
27
- state.file.hasVariants = true
28
- }
29
-
30
- function wrapVariants(t, path) {
31
- const wrapperElement = t.jsxElement(
32
- t.jsxOpeningElement(
33
- t.jsxIdentifier('Variants'),
34
- [
35
- t.jsxAttribute(
36
- t.jsxIdentifier('variants'),
37
- t.jsxExpressionContainer(t.identifier('__uni__variants'))
38
- ),
39
- ],
40
- false
41
- ),
42
- t.jsxClosingElement(t.jsxIdentifier('Variants')),
43
- []
44
- )
45
-
46
- const element = path.openingElement && path.openingElement.name
47
- const isWrappedInRegularFragment = t.isJSXFragment(path)
48
- const isWrappedInFragment = (t.isJSXMemberExpression(element) && element.object.name === 'React' && element.property.name === 'Fragment') || (t.isJSXIdentifier(element) && element.name === 'Fragment')
49
-
50
- wrapperElement.children = (isWrappedInRegularFragment || isWrappedInFragment)
51
- ? path.children
52
- : [path]
2
+ const maybeVariants = path.node.body.filter(node => (
3
+ t.isExpressionStatement(node) &&
4
+ t.isCallExpression(node.expression) &&
5
+ t.isMemberExpression(node.expression.callee)
6
+ ))
53
7
 
54
- // copy Fragment props like key
55
- if (isWrappedInFragment) {
56
- wrapperElement.openingElement.attributes.push(...path.openingElement.attributes)
8
+ if (maybeVariants.length === 0) {
9
+ return
57
10
  }
58
11
 
59
- return wrapperElement
60
- }
12
+ const targetVariant = maybeVariants.find(variant => {
13
+ const calleeName = variant.expression.callee.object.name
14
+
15
+ return (
16
+ t.isIdentifier(variant.expression.callee.object, { name: calleeName }) &&
17
+ t.isIdentifier(variant.expression.callee.property, { name: 'useVariants' }) &&
18
+ variant.expression.arguments.length === 1
19
+ )
20
+ })
61
21
 
62
- function addJSXVariants(t, path) {
63
- if (!t.isReturnStatement(path.node)) {
22
+ if (!targetVariant) {
64
23
  return
65
24
  }
66
25
 
67
- const jsxElement = path.node.argument
26
+ const calleeName = targetVariant.expression.callee.object.name
27
+ const node = targetVariant.expression
28
+ const newUniqueName = path.scope.generateUidIdentifier(calleeName)
68
29
 
69
- if (t.isConditionalExpression(jsxElement)) {
70
- const ifStatement = t.ifStatement(
71
- jsxElement.test,
72
- t.blockStatement([t.returnStatement(jsxElement.consequent)]),
73
- t.blockStatement([t.returnStatement(jsxElement.alternate)])
74
- )
30
+ // Create shadow declaration eg. const _styles = styles
31
+ const shadowDeclaration = t.variableDeclaration('const', [
32
+ t.variableDeclarator(newUniqueName, t.identifier(calleeName))
33
+ ])
75
34
 
76
- path.replaceWith(ifStatement)
35
+ // Create the new call expression eg. const styles = _styles.useVariants(...)
36
+ const newCallExpression = t.callExpression(
37
+ t.memberExpression(t.identifier(newUniqueName.name), t.identifier('useVariants')),
38
+ node.arguments
39
+ )
40
+ const finalDeclaration = t.variableDeclaration('const', [
41
+ t.variableDeclarator(t.identifier(calleeName), newCallExpression)
42
+ ])
77
43
 
78
- return
79
- }
44
+ // Find the current node's index, we will move everything after to new block
45
+ const pathIndex = path.node.body
46
+ .findIndex(bodyPath => bodyPath === targetVariant)
47
+ const rest = path.node.body.slice(pathIndex + 1)
80
48
 
81
- if (!t.isJSXElement(jsxElement) && !t.isJSXFragment(jsxElement)) {
82
- return
83
- }
49
+ // move rest to new block (scope)
50
+ const blockStatement = t.blockStatement([
51
+ finalDeclaration,
52
+ ...rest
53
+ ])
54
+
55
+ path.node.body = [
56
+ ...path.node.body.slice(0, pathIndex),
57
+ shadowDeclaration,
58
+ blockStatement
59
+ ]
84
60
 
85
- path.get('argument').replaceWith(wrapVariants(t, jsxElement));
61
+ state.file.hasVariants = true
86
62
  }
87
63
 
88
64
  module.exports = {
89
- isUsingVariants,
90
- extractVariants,
91
- addJSXVariants
65
+ extractVariants
92
66
  }
@@ -21,7 +21,7 @@ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeP
21
21
  const mappedChildren = [
22
22
  <Apply key={name} name={name} />,
23
23
  children,
24
- <Apply key='dispose' name={previousScopedTheme} />
24
+ <Apply key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
25
25
  ]
26
26
 
27
27
  return (
@@ -1,4 +1,3 @@
1
1
  export { Hide } from './Hide'
2
2
  export { Display } from './Display'
3
- export { Variants } from './Variants'
4
3
  export { ScopedTheme } from './ScopedTheme'
@@ -0,0 +1,17 @@
1
+ import { Animated as RNAnimated } from 'react-native'
2
+ import { View } from './View'
3
+ import { Text } from './Text'
4
+ import { FlatList } from './FlatList'
5
+ import { Image } from './Image'
6
+ import { ScrollView } from './ScrollView'
7
+ import { SectionList } from './SectionList'
8
+
9
+ export const Animated = {
10
+ ...RNAnimated,
11
+ View: RNAnimated.createAnimatedComponent(View),
12
+ Text: RNAnimated.createAnimatedComponent(Text),
13
+ FlatList: RNAnimated.createAnimatedComponent(FlatList),
14
+ Image: RNAnimated.createAnimatedComponent(Image),
15
+ ScrollView: RNAnimated.createAnimatedComponent(ScrollView),
16
+ SectionList: RNAnimated.createAnimatedComponent(SectionList)
17
+ }
@@ -0,0 +1,4 @@
1
+ import { ImageBackground as NativeImageBackground } from 'react-native'
2
+ import { createUnistylesImageBackground } from '../../core'
3
+
4
+ export const ImageBackground = createUnistylesImageBackground(NativeImageBackground)
@@ -1,4 +1,59 @@
1
+ import React from 'react'
1
2
  import { ImageBackground as NativeImageBackground } from 'react-native'
2
- import { createUnistylesImageBackground } from '../../core'
3
+ import { forwardRef } from 'react'
4
+ import type { UnistylesValues } from '../../types'
5
+ import { getClassName } from '../../core'
6
+ import { isServer } from '../../web/utils'
7
+ import { UnistylesShadowRegistry } from '../../web'
8
+ import { copyComponentProperties } from '../../utils'
3
9
 
4
- export const ImageBackground = createUnistylesImageBackground(NativeImageBackground)
10
+ type Props = {
11
+ style?: UnistylesValues
12
+ imageStyle?: UnistylesValues
13
+ }
14
+
15
+ const UnistylesImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
16
+ let storedRef: NativeImageBackground | null = null
17
+ let storedImageRef: NativeImageBackground | null = null
18
+ const styleClassNames = getClassName(props.style)
19
+ const imageClassNames = getClassName(props.imageStyle)
20
+
21
+ return (
22
+ // @ts-expect-error - RN types are not compatible with RNW styles
23
+ <NativeImageBackground
24
+ {...props}
25
+ style={styleClassNames}
26
+ imageStyle={imageClassNames}
27
+ ref={isServer() ? undefined : ref => {
28
+ if (!ref) {
29
+ // @ts-expect-error hidden from TS
30
+ UnistylesShadowRegistry.remove(storedRef, styleClassNames?.hash)
31
+ }
32
+
33
+ storedRef = ref
34
+ // @ts-expect-error hidden from TS
35
+ UnistylesShadowRegistry.add(ref, styleClassNames?.hash)
36
+
37
+ if (typeof forwardedRef === 'function') {
38
+ return forwardedRef(ref)
39
+ }
40
+
41
+ if (forwardedRef) {
42
+ forwardedRef.current = ref
43
+ }
44
+ }}
45
+ imageRef={isServer() ? undefined : ref => {
46
+ if (!ref) {
47
+ // @ts-expect-error hidden from TS
48
+ UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
49
+ }
50
+
51
+ storedImageRef = ref
52
+ // @ts-expect-error hidden from TS
53
+ UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
54
+ }}
55
+ />
56
+ )
57
+ })
58
+
59
+ export const ImageBackground = copyComponentProperties(NativeImageBackground, UnistylesImageBackground)
@@ -0,0 +1,12 @@
1
+ import type { TextProps } from 'react-native'
2
+ import { type ComponentType, createElement, forwardRef } from 'react'
3
+ import { createUnistylesElement } from '../../core'
4
+
5
+ // credits to @hirbod
6
+ const LeanText = forwardRef((props, ref) => {
7
+ return createElement('RCTText', { ...props, ref })
8
+ }) as ComponentType<TextProps>
9
+
10
+ LeanText.displayName = 'RCTText'
11
+
12
+ export const NativeText = createUnistylesElement(LeanText)
@@ -0,0 +1 @@
1
+ export { Text } from './Text'
@@ -0,0 +1,13 @@
1
+ import type { ViewProps } from 'react-native'
2
+ import { type ComponentType, createElement, forwardRef } from 'react'
3
+ import { createUnistylesElement } from '../../core'
4
+
5
+ // credits to @hirbod
6
+ const LeanView = forwardRef((props, ref) => {
7
+ return createElement('RCTView', { ...props, ref })
8
+ }) as ComponentType<ViewProps>
9
+
10
+ LeanView.displayName = 'RCTView'
11
+
12
+ // this will match default export from react-native
13
+ export default createUnistylesElement(LeanView)
@@ -0,0 +1,3 @@
1
+ import { View } from './View'
2
+
3
+ export default View
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useRef } from 'react'
1
+ import React, { forwardRef, useLayoutEffect, useRef } from 'react'
2
2
  import { Pressable as NativePressableReactNative } from 'react-native'
3
3
  import type { PressableProps as Props, View } from 'react-native'
4
4
  import { UnistylesShadowRegistry } from '../../specs'
@@ -8,9 +8,34 @@ type PressableProps = Props & {
8
8
  variants?: Record<string, string | boolean>
9
9
  }
10
10
 
11
+ const getStyles = (styleProps: Record<string, any> = {}) => {
12
+ const unistyleKey = Object
13
+ .keys(styleProps)
14
+ .find(key => key.startsWith('unistyles-'))
15
+
16
+ if (!unistyleKey) {
17
+ return styleProps
18
+ }
19
+
20
+ return {
21
+ // styles without C++ state
22
+ ...styleProps[unistyleKey].uni__getStyles(),
23
+ [unistyleKey]: styleProps[unistyleKey].uni__getStyles()
24
+ }
25
+ }
26
+
11
27
  export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, forwardedRef) => {
12
28
  const storedRef = useRef<View | null>()
13
29
 
30
+ useLayoutEffect(() => {
31
+ return () => {
32
+ if (storedRef.current) {
33
+ // @ts-expect-error - this is hidden from TS
34
+ UnistylesShadowRegistry.remove(storedRef.current)
35
+ }
36
+ }
37
+ }, [])
38
+
14
39
  return (
15
40
  <NativePressableReactNative
16
41
  {...props}
@@ -18,37 +43,29 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
18
43
  const unistyles = typeof style === 'function'
19
44
  ? style({ pressed: false })
20
45
  : style
21
- const styles = Array.isArray(unistyles)
22
- ? unistyles
23
- : [unistyles]
24
46
 
25
47
  // @ts-expect-error - this is hidden from TS
26
- UnistylesShadowRegistry.add(ref, styles)
48
+ UnistylesShadowRegistry.add(ref, unistyles)
27
49
 
28
- storedRef.current = ref
50
+ if (ref) {
51
+ storedRef.current = ref
52
+ }
29
53
 
30
54
  return passForwardedRef(props, ref, forwardedRef)
31
55
  }}
32
56
  style={state => {
33
57
  const unistyles = typeof style === 'function'
34
58
  ? style(state)
35
- : style
36
- const styles = Array.isArray(unistyles)
37
- ? unistyles
38
- : [unistyles]
59
+ : getStyles(style as unknown as Record<string, any>)
39
60
 
40
61
  if (!storedRef.current) {
41
62
  return unistyles
42
63
  }
43
64
 
44
- if (state.pressed) {
45
- UnistylesShadowRegistry.selectVariants(variants)
46
- }
47
-
48
65
  // @ts-expect-error - this is hidden from TS
49
66
  UnistylesShadowRegistry.remove(storedRef.current)
50
67
  // @ts-expect-error - this is hidden from TS
51
- UnistylesShadowRegistry.add(storedRef.current, styles)
68
+ UnistylesShadowRegistry.add(storedRef.current, unistyles)
52
69
 
53
70
  return unistyles
54
71
  }}
@@ -1,7 +1,10 @@
1
- import React, { forwardRef, useRef } from 'react'
1
+ import React, { forwardRef } from 'react'
2
2
  import { Pressable as NativePressableReactNative } from 'react-native'
3
- import type { PressableProps as Props, View, ViewStyle } from 'react-native'
3
+ import type { PressableProps as Props, View } from 'react-native'
4
4
  import { UnistylesShadowRegistry } from '../../specs'
5
+ import type { UnistylesValues } from '../../types'
6
+ import { getClassName } from '../../core'
7
+ import { isServer } from '../../web/utils'
5
8
 
6
9
  type Variants = Record<string, string | boolean | undefined>
7
10
  type WebPressableState = {
@@ -10,88 +13,51 @@ type WebPressableState = {
10
13
  focused: boolean
11
14
  }
12
15
 
13
- type WebPressableStyle = ((state: WebPressableState) => ViewStyle) | ViewStyle
16
+ type WebPressableStyle = ((state: WebPressableState) => UnistylesValues) | UnistylesValues
14
17
 
15
18
  type PressableProps = Props & {
16
19
  variants?: Variants
17
20
  style?: WebPressableStyle,
18
21
  }
19
22
 
20
- const initialState: WebPressableState = {
21
- pressed: false,
22
- hovered: false,
23
- focused: false
24
- }
25
-
26
- type UpdateStylesProps = {
27
- ref: View | null,
28
- style: WebPressableStyle,
29
- variants?: Variants,
30
- state: WebPressableState
31
- scopedTheme?: string
32
- }
33
-
34
- const extractStyleResult = (style: any) => {
35
- return typeof style === 'function'
36
- ? [style()]
37
- : Array.isArray(style)
38
- ? style.map(style => typeof style === 'function' ? style() : style)
39
- : [style]
40
- }
41
-
42
- const updateStyles = ({ ref, style, state, scopedTheme, variants }: UpdateStylesProps) => {
43
- const styleResult = typeof style === 'function'
44
- ? style(state)
45
- : style
46
- const extractedResult = extractStyleResult(styleResult)
47
- const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
48
- const previousVariants = UnistylesShadowRegistry.getVariants()
49
-
50
- UnistylesShadowRegistry.selectVariants(variants as unknown as Variants)
51
- UnistylesShadowRegistry.setScopedTheme(scopedTheme as any)
52
-
53
- UnistylesShadowRegistry.add(ref, extractedResult)
54
-
55
- UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
56
- UnistylesShadowRegistry.selectVariants(previousVariants as unknown as Variants)
57
- }
58
-
59
- export const Pressable = forwardRef<View, PressableProps>(({ style, ...props }, passedRef) => {
60
- const storedRef = useRef<View | null>(null)
23
+ export const Pressable = forwardRef<View, PressableProps>(({ style, ...props }, forwardedRef) => {
61
24
  const scopedTheme = UnistylesShadowRegistry.getScopedTheme()
62
- const variants = UnistylesShadowRegistry.getVariants()
25
+ let storedRef: HTMLElement | null = null
26
+ let classNames: ReturnType<typeof getClassName> | undefined = undefined
63
27
 
64
28
  return (
65
29
  <NativePressableReactNative
66
30
  {...props}
67
- style={state => {
68
- if (!storedRef.current) {
69
- return {}
70
- }
31
+ ref={isServer() ? undefined : ref => {
32
+ storedRef = ref as unknown as HTMLElement
33
+ // @ts-expect-error hidden from TS
34
+ UnistylesShadowRegistry.add(storedRef, classNames?.hash)
71
35
 
72
- updateStyles({
73
- ref: storedRef.current,
74
- style: style as WebPressableStyle,
75
- variants,
76
- scopedTheme,
77
- state: state as WebPressableState
78
- })
36
+ if (typeof forwardedRef === 'function') {
37
+ return forwardedRef(ref)
38
+ }
79
39
 
80
- return {}
40
+ if (forwardedRef) {
41
+ forwardedRef.current = ref
42
+ }
81
43
  }}
82
- ref={ref => {
83
- storedRef.current = ref
84
- updateStyles({
85
- ref,
86
- style: style as WebPressableStyle,
87
- variants,
88
- scopedTheme,
89
- state: initialState
90
- })
44
+ style={state => {
45
+ const styleResult = typeof style === 'function'
46
+ ? style(state as WebPressableState)
47
+ : style
48
+ const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
91
49
 
92
- if (typeof passedRef === 'object' && passedRef !== null) {
93
- passedRef.current = ref
94
- }
50
+ UnistylesShadowRegistry.setScopedTheme(scopedTheme)
51
+
52
+ // @ts-expect-error hidden from TS
53
+ UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
54
+ classNames = getClassName(styleResult as UnistylesValues)
55
+ // @ts-expect-error hidden from TS
56
+ UnistylesShadowRegistry.add(storedRef, classNames?.hash)
57
+
58
+ UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
59
+
60
+ return classNames as any
95
61
  }}
96
62
  />
97
63
  )
@@ -0,0 +1,51 @@
1
+ import React, { useLayoutEffect, useRef } from 'react'
2
+ import { UnistylesShadowRegistry } from '../specs'
3
+ import { passForwardedRef } from './passForwardRef'
4
+ import { maybeWarnAboutMultipleUnistyles } from './warn'
5
+ import { copyComponentProperties } from '../utils'
6
+
7
+ const getNativeRef = (Component: any, ref: any) => {
8
+ switch (Component.name) {
9
+ case 'KeyboardAvoidingView':
10
+ return ref.viewRef?.current
11
+ case 'FlatList':
12
+ return ref.getNativeScrollRef?.()
13
+ case 'VirtualizedList':
14
+ return ref.getScrollRef?.()
15
+ default:
16
+ return ref
17
+ }
18
+ }
19
+
20
+ export const createUnistylesElement = (Component: any) => {
21
+ const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
22
+ const storedRef = useRef<unknown>(null)
23
+
24
+ useLayoutEffect(() => {
25
+ return () => {
26
+ if (storedRef.current) {
27
+ // @ts-ignore
28
+ UnistylesShadowRegistry.remove(storedRef.current)
29
+ }
30
+ }
31
+ }, [])
32
+
33
+ return (
34
+ <Component
35
+ {...props}
36
+ ref={(ref: unknown) => {
37
+ if (ref) {
38
+ storedRef.current = getNativeRef(Component, ref)
39
+ }
40
+
41
+ passForwardedRef(props, ref, forwardedRef)
42
+
43
+ // @ts-ignore we don't know the type of the component
44
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
45
+ }}
46
+ />
47
+ )
48
+ })
49
+
50
+ return copyComponentProperties(Component, UnistylesComponent)
51
+ }
@@ -1,9 +1,48 @@
1
1
  import React from 'react'
2
- import { passForwardedRef } from './passForwardRef'
3
-
4
- export const createUnistylesElement = (Component: any) => React.forwardRef((props, forwardedRef) => (
5
- <Component
6
- {...props}
7
- ref={(ref: unknown) => passForwardedRef(props, ref, forwardedRef)}
8
- />
9
- ))
2
+ import type { UnistylesValues } from '../types'
3
+ import { getClassName } from './getClassname'
4
+ import { isServer } from '../web/utils'
5
+ import { UnistylesShadowRegistry } from '../web'
6
+ import { maybeWarnAboutMultipleUnistyles } from './warn'
7
+ import { copyComponentProperties } from '../utils'
8
+
9
+ type ComponentProps = {
10
+ style?: UnistylesValues | Array<UnistylesValues>
11
+ }
12
+
13
+ export const createUnistylesElement = (Component: any) => {
14
+ const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
15
+ let storedRef: HTMLElement | null = null
16
+ const classNames = getClassName(props.style)
17
+
18
+ return (
19
+ <Component
20
+ {...props}
21
+ style={classNames}
22
+ ref={isServer() ? undefined : (ref: HTMLElement | null) => {
23
+ // @ts-ignore we don't know the type of the component
24
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
25
+
26
+ if (!ref) {
27
+ // @ts-expect-error hidden from TS
28
+ UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
29
+ }
30
+
31
+ storedRef = ref
32
+ // @ts-expect-error hidden from TS
33
+ UnistylesShadowRegistry.add(ref, classNames?.hash)
34
+
35
+ if (typeof forwardedRef === 'function') {
36
+ return forwardedRef(ref)
37
+ }
38
+
39
+ if (forwardedRef) {
40
+ forwardedRef.current = ref
41
+ }
42
+ }}
43
+ />
44
+ )
45
+ })
46
+
47
+ return copyComponentProperties(Component, UnistylesComponent)
48
+ }