react-native-unistyles 3.0.0-beta.7 → 3.0.0-experimental-2025051401

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 (390) hide show
  1. package/README.md +41 -19
  2. package/Unistyles.podspec +1 -0
  3. package/android/CMakeLists.txt +2 -1
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
  5. package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
  6. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
  7. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +11 -4
  8. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
  9. package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
  10. package/components/native/ActivityIndicator/package.json +1 -0
  11. package/components/native/Animated/package.json +1 -0
  12. package/components/native/FlatList/package.json +1 -0
  13. package/components/native/Image/package.json +2 -1
  14. package/components/native/ImageBackground/package.json +1 -0
  15. package/components/native/KeyboardAvoidingView/package.json +1 -0
  16. package/components/native/NativeText/package.json +1 -0
  17. package/components/native/NativeView/package.json +1 -0
  18. package/components/native/Pressable/package.json +1 -0
  19. package/components/native/RefreshControl/package.json +1 -0
  20. package/components/native/ScrollView/package.json +1 -0
  21. package/components/native/SectionList/package.json +1 -0
  22. package/components/native/Switch/package.json +1 -0
  23. package/components/native/Text/package.json +1 -0
  24. package/components/native/TextInput/package.json +1 -0
  25. package/components/native/TouchableHighlight/package.json +1 -0
  26. package/components/native/TouchableOpacity/package.json +1 -0
  27. package/components/native/View/package.json +1 -0
  28. package/components/native/VirtualizedList/package.json +1 -0
  29. package/cxx/common/Helpers.h +89 -0
  30. package/cxx/core/HostUnistyle.cpp +14 -5
  31. package/cxx/core/StyleSheet.h +1 -1
  32. package/cxx/core/UnistyleWrapper.h +1 -1
  33. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  34. package/cxx/core/UnistylesRegistry.cpp +74 -69
  35. package/cxx/core/UnistylesRegistry.h +1 -1
  36. package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
  37. package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
  38. package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
  39. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
  40. package/cxx/parser/Parser.cpp +200 -89
  41. package/cxx/parser/Parser.h +1 -1
  42. package/cxx/shadowTree/ShadowTrafficController.h +13 -9
  43. package/cxx/shadowTree/ShadowTreeManager.cpp +64 -59
  44. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  45. package/ios/NativePlatform+ios.swift +1 -1
  46. package/ios/NativePlatformListener+ios.swift +12 -7
  47. package/ios/UnistylesModuleOnLoad.h +1 -5
  48. package/ios/UnistylesModuleOnLoad.mm +5 -13
  49. package/lib/commonjs/components/native/Image.js +27 -1
  50. package/lib/commonjs/components/native/Image.js.map +1 -1
  51. package/lib/commonjs/components/native/Image.native.js +10 -0
  52. package/lib/commonjs/components/native/Image.native.js.map +1 -0
  53. package/lib/commonjs/components/native/ImageBackground.js +21 -36
  54. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  55. package/lib/commonjs/components/native/Pressable.native.js +16 -2
  56. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  57. package/lib/commonjs/core/createUnistylesElement.js +17 -21
  58. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  59. package/lib/commonjs/core/createUnistylesElement.native.js +7 -1
  60. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  61. package/lib/commonjs/core/createUnistylesImageBackground.js +10 -4
  62. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  63. package/lib/commonjs/core/getClassname.js +11 -5
  64. package/lib/commonjs/core/getClassname.js.map +1 -1
  65. package/lib/commonjs/core/passForwardRef.js +3 -5
  66. package/lib/commonjs/core/passForwardRef.js.map +1 -1
  67. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  68. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  69. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
  70. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  71. package/lib/commonjs/core/withUnistyles/withUnistyles.js +14 -5
  72. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  73. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +14 -7
  74. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  75. package/lib/commonjs/hooks/useMedia.js +4 -4
  76. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  77. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  78. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  79. package/lib/commonjs/mocks.js +203 -0
  80. package/lib/commonjs/mocks.js.map +1 -0
  81. package/lib/commonjs/mq.js +1 -23
  82. package/lib/commonjs/mq.js.map +1 -1
  83. package/lib/commonjs/reanimated/index.js +13 -0
  84. package/lib/commonjs/reanimated/index.js.map +1 -0
  85. package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
  86. package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
  87. package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
  88. package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
  89. package/lib/commonjs/server/getServerUnistyles.js +9 -4
  90. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  91. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  92. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  93. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  94. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  95. package/lib/commonjs/server/serialize.js +24 -0
  96. package/lib/commonjs/server/serialize.js.map +1 -0
  97. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  98. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  99. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  100. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  101. package/lib/commonjs/utils.js +23 -1
  102. package/lib/commonjs/utils.js.map +1 -1
  103. package/lib/commonjs/web/convert/index.js +4 -7
  104. package/lib/commonjs/web/convert/index.js.map +1 -1
  105. package/lib/commonjs/web/convert/object/filter.js +7 -8
  106. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  107. package/lib/commonjs/web/create.js +10 -2
  108. package/lib/commonjs/web/create.js.map +1 -1
  109. package/lib/commonjs/web/css/core.js +2 -2
  110. package/lib/commonjs/web/css/core.js.map +1 -1
  111. package/lib/commonjs/web/css/state.js +6 -3
  112. package/lib/commonjs/web/css/state.js.map +1 -1
  113. package/lib/commonjs/web/index.js +7 -12
  114. package/lib/commonjs/web/index.js.map +1 -1
  115. package/lib/commonjs/web/registry.js +11 -9
  116. package/lib/commonjs/web/registry.js.map +1 -1
  117. package/lib/commonjs/web/runtime.js +5 -1
  118. package/lib/commonjs/web/runtime.js.map +1 -1
  119. package/lib/commonjs/web/services.js +7 -2
  120. package/lib/commonjs/web/services.js.map +1 -1
  121. package/lib/commonjs/web/shadowRegistry.js +27 -10
  122. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  123. package/lib/commonjs/web/state.js +11 -2
  124. package/lib/commonjs/web/state.js.map +1 -1
  125. package/lib/commonjs/web/types.js +2 -0
  126. package/lib/commonjs/web/types.js.map +1 -1
  127. package/lib/commonjs/web/utils/createUnistylesRef.js +31 -0
  128. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
  129. package/lib/commonjs/web/utils/unistyle.js +40 -14
  130. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  131. package/lib/commonjs/web-only/getWebProps.js +19 -0
  132. package/lib/commonjs/web-only/getWebProps.js.map +1 -0
  133. package/lib/commonjs/web-only/index.js +13 -0
  134. package/lib/commonjs/web-only/index.js.map +1 -0
  135. package/lib/module/components/native/Image.js +26 -2
  136. package/lib/module/components/native/Image.js.map +1 -1
  137. package/lib/module/components/native/Image.native.js +6 -0
  138. package/lib/module/components/native/Image.native.js.map +1 -0
  139. package/lib/module/components/native/ImageBackground.js +22 -37
  140. package/lib/module/components/native/ImageBackground.js.map +1 -1
  141. package/lib/module/components/native/Pressable.native.js +16 -2
  142. package/lib/module/components/native/Pressable.native.js.map +1 -1
  143. package/lib/module/core/createUnistylesElement.js +17 -21
  144. package/lib/module/core/createUnistylesElement.js.map +1 -1
  145. package/lib/module/core/createUnistylesElement.native.js +7 -1
  146. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  147. package/lib/module/core/createUnistylesImageBackground.js +10 -4
  148. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  149. package/lib/module/core/getClassname.js +9 -5
  150. package/lib/module/core/getClassname.js.map +1 -1
  151. package/lib/module/core/passForwardRef.js +3 -5
  152. package/lib/module/core/passForwardRef.js.map +1 -1
  153. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  154. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  155. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
  156. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  157. package/lib/module/core/withUnistyles/withUnistyles.js +14 -5
  158. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  159. package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -7
  160. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  161. package/lib/module/hooks/useMedia.js +1 -1
  162. package/lib/module/hooks/useMedia.js.map +1 -1
  163. package/lib/module/hooks/useMedia.native.js +1 -1
  164. package/lib/module/hooks/useMedia.native.js.map +1 -1
  165. package/lib/module/mocks.js +201 -0
  166. package/lib/module/mocks.js.map +1 -0
  167. package/lib/module/mq.js +0 -19
  168. package/lib/module/mq.js.map +1 -1
  169. package/lib/module/reanimated/index.js +4 -0
  170. package/lib/module/reanimated/index.js.map +1 -0
  171. package/lib/module/reanimated/useAnimatedTheme.js +17 -0
  172. package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
  173. package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
  174. package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
  175. package/lib/module/server/getServerUnistyles.js +7 -4
  176. package/lib/module/server/getServerUnistyles.js.map +1 -1
  177. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  178. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  179. package/lib/module/server/resetServerUnistyles.js +2 -2
  180. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  181. package/lib/module/server/serialize.js +19 -0
  182. package/lib/module/server/serialize.js.map +1 -0
  183. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  184. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  185. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  186. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  187. package/lib/module/utils.js +19 -0
  188. package/lib/module/utils.js.map +1 -1
  189. package/lib/module/web/convert/index.js +4 -7
  190. package/lib/module/web/convert/index.js.map +1 -1
  191. package/lib/module/web/convert/object/filter.js +3 -4
  192. package/lib/module/web/convert/object/filter.js.map +1 -1
  193. package/lib/module/web/create.js +9 -3
  194. package/lib/module/web/create.js.map +1 -1
  195. package/lib/module/web/css/core.js +2 -2
  196. package/lib/module/web/css/core.js.map +1 -1
  197. package/lib/module/web/css/state.js +6 -3
  198. package/lib/module/web/css/state.js.map +1 -1
  199. package/lib/module/web/index.js +4 -10
  200. package/lib/module/web/index.js.map +1 -1
  201. package/lib/module/web/registry.js +11 -9
  202. package/lib/module/web/registry.js.map +1 -1
  203. package/lib/module/web/runtime.js +5 -1
  204. package/lib/module/web/runtime.js.map +1 -1
  205. package/lib/module/web/services.js +7 -1
  206. package/lib/module/web/services.js.map +1 -1
  207. package/lib/module/web/shadowRegistry.js +27 -10
  208. package/lib/module/web/shadowRegistry.js.map +1 -1
  209. package/lib/module/web/state.js +11 -2
  210. package/lib/module/web/state.js.map +1 -1
  211. package/lib/module/web/types.js +1 -1
  212. package/lib/module/web/types.js.map +1 -1
  213. package/lib/module/web/utils/createUnistylesRef.js +24 -0
  214. package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
  215. package/lib/module/web/utils/unistyle.js +32 -10
  216. package/lib/module/web/utils/unistyle.js.map +1 -1
  217. package/lib/module/web-only/getWebProps.js +14 -0
  218. package/lib/module/web-only/getWebProps.js.map +1 -0
  219. package/lib/module/web-only/index.js +4 -0
  220. package/lib/module/web-only/index.js.map +1 -0
  221. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  222. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  223. package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
  224. package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
  225. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  226. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  227. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  228. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  229. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  230. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  231. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  232. package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
  233. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  234. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  235. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  236. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  237. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  238. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
  239. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  240. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
  241. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  242. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  243. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  244. package/lib/typescript/src/mocks.d.ts +2 -0
  245. package/lib/typescript/src/mocks.d.ts.map +1 -0
  246. package/lib/typescript/src/mq.d.ts +0 -8
  247. package/lib/typescript/src/mq.d.ts.map +1 -1
  248. package/lib/typescript/src/reanimated/index.d.ts +2 -0
  249. package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
  250. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
  251. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
  252. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
  253. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
  254. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  255. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  256. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  257. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  258. package/lib/typescript/src/server/serialize.d.ts +2 -0
  259. package/lib/typescript/src/server/serialize.d.ts.map +1 -0
  260. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  261. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  262. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  263. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  264. package/lib/typescript/src/types/common.d.ts +0 -1
  265. package/lib/typescript/src/types/common.d.ts.map +1 -1
  266. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  267. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  268. package/lib/typescript/src/utils.d.ts +8 -0
  269. package/lib/typescript/src/utils.d.ts.map +1 -1
  270. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  271. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  272. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  273. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  274. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  275. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  276. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  277. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  278. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  279. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  280. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  281. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  282. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  283. package/lib/typescript/src/web/create.d.ts.map +1 -1
  284. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  285. package/lib/typescript/src/web/css/state.d.ts +4 -1
  286. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  287. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  288. package/lib/typescript/src/web/index.d.ts +0 -5
  289. package/lib/typescript/src/web/index.d.ts.map +1 -1
  290. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  291. package/lib/typescript/src/web/registry.d.ts +2 -2
  292. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  293. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  294. package/lib/typescript/src/web/services.d.ts +6 -1
  295. package/lib/typescript/src/web/services.d.ts.map +1 -1
  296. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
  297. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  298. package/lib/typescript/src/web/state.d.ts +2 -0
  299. package/lib/typescript/src/web/state.d.ts.map +1 -1
  300. package/lib/typescript/src/web/types.d.ts +3 -0
  301. package/lib/typescript/src/web/types.d.ts.map +1 -1
  302. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  303. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +11 -0
  304. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
  305. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -2
  306. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  307. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  308. package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
  309. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
  310. package/lib/typescript/src/web-only/index.d.ts +2 -0
  311. package/lib/typescript/src/web-only/index.d.ts.map +1 -0
  312. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
  313. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
  314. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
  315. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  316. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
  317. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
  318. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +22 -22
  319. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  320. package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
  321. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
  322. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  323. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -0
  324. package/nitrogen/generated/shared/c++/Insets.hpp +1 -0
  325. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  326. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -0
  327. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -0
  328. package/package.json +77 -33
  329. package/plugin/index.d.ts +51 -18
  330. package/plugin/index.js +878 -177
  331. package/reanimated/package.json +6 -0
  332. package/server/package.json +6 -0
  333. package/src/components/native/Image.native.tsx +4 -0
  334. package/src/components/native/Image.tsx +36 -3
  335. package/src/components/native/ImageBackground.tsx +20 -36
  336. package/src/components/native/Pressable.native.tsx +25 -2
  337. package/src/core/createUnistylesElement.native.tsx +13 -2
  338. package/src/core/createUnistylesElement.tsx +26 -27
  339. package/src/core/createUnistylesImageBackground.tsx +16 -5
  340. package/src/core/getClassname.ts +16 -5
  341. package/src/core/passForwardRef.ts +5 -5
  342. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  343. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +18 -1
  344. package/src/core/withUnistyles/withUnistyles.native.tsx +42 -17
  345. package/src/core/withUnistyles/withUnistyles.tsx +23 -6
  346. package/src/hooks/useMedia.native.ts +1 -1
  347. package/src/hooks/useMedia.ts +1 -1
  348. package/src/mocks.ts +217 -0
  349. package/src/mq.ts +0 -24
  350. package/src/reanimated/index.ts +1 -0
  351. package/src/reanimated/useAnimatedTheme.native.ts +21 -0
  352. package/src/reanimated/useAnimatedTheme.ts +19 -0
  353. package/src/server/getServerUnistyles.tsx +15 -10
  354. package/src/server/hydrateServerUnistyles.ts +3 -2
  355. package/src/server/resetServerUnistyles.ts +4 -3
  356. package/src/server/serialize.ts +20 -0
  357. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  358. package/src/specs/ShadowRegistry/index.ts +2 -2
  359. package/src/types/common.ts +0 -1
  360. package/src/types/stylesheet.ts +1 -1
  361. package/src/utils.ts +25 -0
  362. package/src/web/convert/index.ts +5 -7
  363. package/src/web/convert/object/filter.ts +4 -4
  364. package/src/web/create.ts +10 -3
  365. package/src/web/css/core.ts +2 -2
  366. package/src/web/css/state.ts +5 -3
  367. package/src/web/index.ts +4 -16
  368. package/src/web/registry.ts +20 -11
  369. package/src/web/runtime.ts +6 -2
  370. package/src/web/services.ts +14 -1
  371. package/src/web/shadowRegistry.ts +35 -13
  372. package/src/web/state.ts +14 -2
  373. package/src/web/types.ts +9 -4
  374. package/src/web/utils/createUnistylesRef.ts +33 -0
  375. package/src/web/utils/unistyle.ts +55 -23
  376. package/src/web-only/getWebProps.ts +18 -0
  377. package/src/web-only/index.ts +2 -0
  378. package/web/package.json +6 -0
  379. package/cxx/core/UnistylesCommitHook.cpp +0 -49
  380. package/cxx/core/UnistylesCommitHook.h +0 -27
  381. package/cxx/core/UnistylesMountHook.cpp +0 -28
  382. package/cxx/core/UnistylesMountHook.h +0 -27
  383. package/lib/module/package.json +0 -1
  384. package/plugin/consts.js +0 -63
  385. package/plugin/exotic.js +0 -54
  386. package/plugin/import.js +0 -51
  387. package/plugin/ref.js +0 -11
  388. package/plugin/stylesheet.js +0 -565
  389. package/plugin/variants.js +0 -66
  390. /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
@@ -11,9 +11,11 @@ export class UnistylesRegistry {
11
11
  private readonly stylesCounter = new Map<string, Set<HTMLElement>>()
12
12
  private readonly disposeListenersMap = new Map<object, VoidFunction>()
13
13
  private readonly dependenciesMap = new Map<StyleSheetWithSuperPowers<StyleSheet>, Set<UnistyleDependency>>()
14
- readonly css = new CSSState()
14
+ readonly css: CSSState
15
15
 
16
- constructor(private services: UnistylesServices) {}
16
+ constructor(private services: UnistylesServices) {
17
+ this.css = new CSSState(services)
18
+ }
17
19
 
18
20
  getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, scopedThemeName?: UnistylesTheme) => {
19
21
  if (typeof stylesheet !== 'function') {
@@ -21,7 +23,7 @@ export class UnistylesRegistry {
21
23
  }
22
24
 
23
25
  if (scopedThemeName) {
24
- const scopedTheme = this.services.runtime.getTheme(scopedThemeName, this.services.state.CSSVars)
26
+ const scopedTheme = this.services.runtime.getTheme(scopedThemeName)
25
27
 
26
28
  if (!scopedTheme) {
27
29
  throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
@@ -54,7 +56,10 @@ export class UnistylesRegistry {
54
56
  dependencies.forEach(dependency => dependenciesMap.add(dependency))
55
57
 
56
58
  const dispose = this.services.listener.addStylesheetListeners(Array.from(dependenciesMap), () => {
57
- const newComputedStylesheet = stylesheet(this.services.runtime.theme, this.services.runtime.miniRuntime)
59
+ const newComputedStylesheet = stylesheet(
60
+ this.services.runtime.getTheme(this.services.runtime.themeName, this.services.state.CSSVars),
61
+ this.services.runtime.miniRuntime
62
+ )
58
63
 
59
64
  this.stylesheets.set(stylesheet, newComputedStylesheet)
60
65
  })
@@ -77,23 +82,27 @@ export class UnistylesRegistry {
77
82
 
78
83
  if (stylesCounter.size === 0) {
79
84
  // Move this to the end of the event loop so the element is removed from the DOM
80
- Promise.resolve().then(() => {
85
+ return Promise.resolve().then(() => {
86
+ // Check if element is still in the DOM
81
87
  if (document.querySelector(`.${hash}`)) {
82
- return
88
+ return false
83
89
  }
84
90
 
85
91
  this.css.remove(hash)
86
92
  this.stylesCache.delete(hash)
87
- })
88
93
 
89
- return true
94
+ return true
95
+ })
90
96
  }
91
97
 
92
- return false
98
+ return Promise.resolve(false)
93
99
  }
94
100
 
95
- add = (value: UnistylesValues) => {
96
- const hash = generateHash(value)
101
+ add = (value: UnistylesValues, forChild?: boolean) => {
102
+ const generatedHash = generateHash(value)
103
+ const hash = forChild
104
+ ? `${generatedHash} > *`
105
+ : generatedHash
97
106
 
98
107
  if (!this.stylesCache.has(hash)) {
99
108
  this.applyStyles(hash, value)
@@ -1,7 +1,7 @@
1
1
  import { UnistyleDependency } from '../specs/NativePlatform'
2
2
  import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
3
3
  import { type AppTheme, type AppThemeName, ColorScheme, Orientation } from '../specs/types'
4
- import { WebContentSizeCategory } from '../types'
4
+ import { type UnistylesTheme, WebContentSizeCategory } from '../types'
5
5
  import { NavigationBar, StatusBar } from './mock'
6
6
  import type { UnistylesServices } from './types'
7
7
  import { error, isServer, schemeToTheme } from './utils'
@@ -213,7 +213,11 @@ export class UnistylesRuntime {
213
213
  : this.services.state.themes.get(themeName ?? '')
214
214
 
215
215
  if (!themeName || !theme) {
216
- throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
216
+ return new Proxy({} as UnistylesTheme, {
217
+ get: () => {
218
+ throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
219
+ }
220
+ })
217
221
  }
218
222
 
219
223
  return theme
@@ -3,8 +3,9 @@ import { UnistylesRegistry } from './registry'
3
3
  import { UnistylesRuntime } from './runtime'
4
4
  import { UnistylesShadowRegistry } from './shadowRegistry'
5
5
  import { UnistylesState } from './state'
6
+ import { isServer } from './utils'
6
7
 
7
- export class UnistylesServices {
8
+ class UnistylesServices {
8
9
  runtime: UnistylesRuntime
9
10
  registry: UnistylesRegistry
10
11
  shadowRegistry: UnistylesShadowRegistry
@@ -26,3 +27,15 @@ export class UnistylesServices {
26
27
  this.services.listener = this.listener
27
28
  }
28
29
  }
30
+
31
+ declare global {
32
+ // @ts-ignore
33
+ var __unistyles__: UnistylesServices
34
+ }
35
+
36
+ if (isServer() && !globalThis.__unistyles__) {
37
+ // @ts-ignore
38
+ globalThis.__unistyles__ = new UnistylesServices()
39
+ }
40
+
41
+ export const services = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
@@ -1,8 +1,8 @@
1
- import { UnistyleDependency } from '../specs'
1
+ import { UnistyleDependency } from '../specs/NativePlatform/NativePlatform.nitro'
2
2
  import type { UnistylesTheme, UnistylesValues } from '../types'
3
3
  import { deepMergeObjects } from '../utils'
4
- import type { UnistylesServices } from './types'
5
- import { extractSecrets, extractUnistyleDependencies } from './utils'
4
+ import type { UniGeneratedStyle, UnistylesServices } from './types'
5
+ import { extractSecrets, extractUnistyleDependencies, isGeneratedUnistyle, isServer } from './utils'
6
6
  import { getVariants } from './variants'
7
7
 
8
8
  export class UnistylesShadowRegistry {
@@ -27,7 +27,14 @@ export class UnistylesShadowRegistry {
27
27
  this.services.registry.connect(ref, hash)
28
28
  }
29
29
 
30
- addStyles = (unistyles: Array<UnistylesValues>) => {
30
+ addStyles = (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
31
+ const [firstStyle] = unistyles
32
+
33
+ // If it is already a generated style, return it
34
+ if (firstStyle && isGeneratedUnistyle(firstStyle)) {
35
+ return firstStyle as UniGeneratedStyle
36
+ }
37
+
31
38
  const getParsedStyles = () => {
32
39
  const allStyles = unistyles.map(unistyle => {
33
40
  const secrets = extractSecrets(unistyle)
@@ -37,6 +44,11 @@ export class UnistylesShadowRegistry {
37
44
  return unistyle
38
45
  }
39
46
 
47
+ // Animated styles - shouldn't be processed
48
+ if (Object.keys(secrets).length === 0) {
49
+ return {}
50
+ }
51
+
40
52
  const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
41
53
  const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
42
54
  const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
@@ -52,7 +64,10 @@ export class UnistylesShadowRegistry {
52
64
  this.services.registry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
53
65
  }
54
66
 
55
- return resultWithVariants as UnistylesValues
67
+ return {
68
+ ...resultWithVariants,
69
+ ...resultWithVariants._web
70
+ } as UnistylesValues
56
71
  })
57
72
 
58
73
  return deepMergeObjects(...allStyles)
@@ -61,7 +76,7 @@ export class UnistylesShadowRegistry {
61
76
  // Copy scoped theme to not use referenced value
62
77
  const scopedTheme = this.scopedTheme
63
78
  const parsedStyles = getParsedStyles()
64
- const { hash, existingHash } = this.services.registry.add(parsedStyles)
79
+ const { hash, existingHash } = this.services.registry.add(parsedStyles, forChild)
65
80
  const injectedClassNames = parsedStyles?._web?._classNames ?? []
66
81
  const injectedClassName = Array.isArray(injectedClassNames) ? injectedClassNames.join(' ') : injectedClassNames
67
82
  const dependencies = extractUnistyleDependencies(parsedStyles)
@@ -75,7 +90,11 @@ export class UnistylesShadowRegistry {
75
90
  }))
76
91
  }
77
92
 
78
- return { injectedClassName, hash }
93
+ const hashClassname = forChild
94
+ ? hash.replace(' > *', '')
95
+ : hash
96
+
97
+ return { injectedClassName, hash: hashClassname }
79
98
  }
80
99
 
81
100
  setScopedTheme = (theme?: UnistylesTheme) => {
@@ -85,15 +104,18 @@ export class UnistylesShadowRegistry {
85
104
  getScopedTheme = () => this.scopedTheme
86
105
 
87
106
  remove = (ref: any, hash?: string) => {
88
- if (!(ref instanceof HTMLElement) || !hash) {
107
+ if (isServer() || !(ref instanceof HTMLElement) || !hash) {
89
108
  return
90
109
  }
91
110
 
92
- const removed = this.services.registry.remove(ref, hash)
111
+ this.services.registry.remove(ref, hash)
112
+ .then(removed => {
113
+ if (!removed) {
114
+ return
115
+ }
93
116
 
94
- if (removed) {
95
- this.disposeMap.get(hash)?.()
96
- this.disposeMap.delete(hash)
97
- }
117
+ this.disposeMap.get(hash)?.()
118
+ this.disposeMap.delete(hash)
119
+ })
98
120
  }
99
121
  }
package/src/web/state.ts CHANGED
@@ -17,6 +17,7 @@ export class UnistylesState {
17
17
  CSSVars = true
18
18
 
19
19
  private matchingBreakpoints = new Map<string, boolean>()
20
+ private _config: UnistylesConfig = {}
20
21
 
21
22
  get breakpoint() {
22
23
  const [currentBreakpoint] = Array.from(this.matchingBreakpoints)
@@ -37,6 +38,7 @@ export class UnistylesState {
37
38
  return
38
39
  }
39
40
 
41
+ this._config = config
40
42
  this.isInitialized = true
41
43
  this.initThemes(config.themes, config.settings?.CSSVars)
42
44
  this.initBreakpoints(config.breakpoints)
@@ -58,7 +60,11 @@ export class UnistylesState {
58
60
  this.services.listener.initListeners()
59
61
  }
60
62
 
61
- private initThemes = (themes = {} as UnistylesThemes, CSSVars = true) => {
63
+ private initThemes = (themes?: UnistylesThemes, CSSVars = true) => {
64
+ if (!themes) {
65
+ return
66
+ }
67
+
62
68
  this.CSSVars = CSSVars
63
69
 
64
70
  Object.entries(themes).forEach(([themeName, theme]) => {
@@ -117,7 +123,11 @@ export class UnistylesState {
117
123
  }
118
124
  }
119
125
 
120
- private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
126
+ private initBreakpoints = (breakpoints?: UnistylesBreakpoints) => {
127
+ if (!breakpoints) {
128
+ return
129
+ }
130
+
121
131
  this.breakpoints = breakpoints
122
132
  const breakpointsEntries = Object.entries(breakpoints)
123
133
 
@@ -145,4 +155,6 @@ export class UnistylesState {
145
155
  })
146
156
  })
147
157
  }
158
+
159
+ getConfig = () => this._config
148
160
  }
package/src/web/types.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { UnistylesListener } from './listener'
2
- import type{ UnistylesRegistry } from './registry'
3
- import type{ UnistylesRuntime } from './runtime'
4
- import type{ UnistylesShadowRegistry } from './shadowRegistry'
5
- import type{ UnistylesState } from './state'
2
+ import type { UnistylesRegistry } from './registry'
3
+ import type { UnistylesRuntime } from './runtime'
4
+ import type { UnistylesShadowRegistry } from './shadowRegistry'
5
+ import type { UnistylesState } from './state'
6
6
 
7
7
  export type UnistylesServices = {
8
8
  runtime: UnistylesRuntime,
@@ -11,3 +11,8 @@ export type UnistylesServices = {
11
11
  state: UnistylesState,
12
12
  listener: UnistylesListener
13
13
  }
14
+
15
+ export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
16
+ export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
17
+
18
+ export type UniGeneratedStyle = Record<UniGeneratedKey, string>
@@ -0,0 +1,33 @@
1
+ import type React from 'react'
2
+ import type { Nullable, UnistylesValues } from '../../types'
3
+ import * as unistyles from '../services'
4
+ import { isServer } from './common'
5
+
6
+ type Styles = readonly [
7
+ {
8
+ hash: string
9
+ },
10
+ Array<UnistylesValues>
11
+ ]
12
+
13
+ export const createUnistylesRef = <T>(styles?: Styles, forwardedRef?: React.ForwardedRef<T>) => {
14
+ const storedRef = { current: null as Nullable<T> }
15
+ const [classNames] = styles ?? []
16
+
17
+ return isServer() ? undefined : (ref: Nullable<T>) => {
18
+ if (!ref) {
19
+ unistyles.services.shadowRegistry.remove(storedRef, classNames?.hash)
20
+ }
21
+
22
+ storedRef.current = ref
23
+ unistyles.services.shadowRegistry.add(ref, classNames?.hash)
24
+
25
+ if (typeof forwardedRef === 'function') {
26
+ return forwardedRef(ref)
27
+ }
28
+
29
+ if (forwardedRef) {
30
+ forwardedRef.current = ref
31
+ }
32
+ }
33
+ }
@@ -1,9 +1,11 @@
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'
8
+ import { UNI_GENERATED_KEYS, type UniGeneratedKey, type UniGeneratedStyle } from '../types'
7
9
  import { keyInObject, reduceObject } from './common'
8
10
 
9
11
  export const schemeToTheme = (scheme: ColorScheme) => {
@@ -49,13 +51,7 @@ export const extractSecrets = (object: any) => {
49
51
  return undefined
50
52
  }
51
53
 
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)
54
+ return reduceObject(Object.getOwnPropertyDescriptors(secrets), secret => secret.value)
59
55
  }
60
56
 
61
57
  export const removeInlineStyles = (values: UnistylesValues) => {
@@ -70,8 +66,6 @@ export const removeInlineStyles = (values: UnistylesValues) => {
70
66
  return returnValue
71
67
  }
72
68
 
73
- export const isInDocument = (element: HTMLElement) => document.body.contains(element)
74
-
75
69
  export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
76
70
  if (Object.values(Orientation).includes(query as Orientation)) {
77
71
  return `@media (orientation: ${query})`
@@ -89,18 +83,18 @@ export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
89
83
  return `@media ${queries}`
90
84
  }
91
85
 
92
- const breakpointValue = UnistylesWeb.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
86
+ const breakpointValue = unistyles.services.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
93
87
  const nextBreakpoint = allBreakpoints
94
- .filter((b): b is keyof UnistylesBreakpoints => b in UnistylesWeb.runtime.breakpoints)
95
- .map(b => UnistylesWeb.runtime.breakpoints[b] as number)
96
- .sort((a, b) => a - b)
97
- .find(b => b > breakpointValue)
98
- const queries = [
99
- `(min-width: ${breakpointValue}px)`,
100
- nextBreakpoint ? `(max-width: ${nextBreakpoint - 1}px)` : undefined,
101
- ].filter(Boolean).join(' and ')
102
-
103
- return `@media ${queries}`
88
+ .filter((b): b is keyof UnistylesBreakpoints => b in unistyles.services.runtime.breakpoints)
89
+ .map(b => unistyles.services.runtime.breakpoints[b] as number)
90
+ .sort((a, b) => a - b)
91
+ .find(b => b > breakpointValue)
92
+ const queries = [
93
+ `(min-width: ${breakpointValue}px)`,
94
+ nextBreakpoint ? `(max-width: ${nextBreakpoint - 1}px)` : undefined,
95
+ ].filter(Boolean).join(' and ')
96
+
97
+ return `@media ${queries}`
104
98
  }
105
99
 
106
100
  export const extractUnistyleDependencies = (value: any) => {
@@ -112,3 +106,41 @@ export const extractUnistyleDependencies = (value: any) => {
112
106
 
113
107
  return Array.isArray(dependencies) ? dependencies : []
114
108
  }
109
+
110
+ export const checkForProp = (value: any, prop: string): boolean => {
111
+ if (Array.isArray(value)) {
112
+ return value.some(nestedValue => checkForProp(nestedValue, prop))
113
+ }
114
+
115
+ if (typeof value === 'object' && value !== null) {
116
+ return keyInObject(value, prop)
117
+ ? true
118
+ : keyInObject(value, '_web')
119
+ ? checkForProp(value._web, prop)
120
+ : false
121
+ }
122
+
123
+ return false
124
+ }
125
+
126
+ export const checkForAnimated = (value: any): boolean => {
127
+ if (Array.isArray(value)) {
128
+ return value.some(checkForAnimated)
129
+ }
130
+
131
+ if (typeof value === 'object' && value !== null) {
132
+ const objectValues = Object.values(value)
133
+ const secrets = extractSecrets(value)
134
+
135
+ // @ts-expect-error React Native Web exports Animated.AnimatedNode as Animated.Node
136
+ return value instanceof Animated.Node ||
137
+ objectValues.length > 0 && objectValues.some(checkForAnimated) ||
138
+ secrets && Object.keys(secrets).length === 0
139
+ }
140
+
141
+ return false
142
+ }
143
+
144
+ export const isGeneratedUnistyle = (value: Record<string, any>): value is UniGeneratedStyle => {
145
+ return Object.keys(value).every(key => UNI_GENERATED_KEYS.includes(key as UniGeneratedKey))
146
+ }
@@ -0,0 +1,18 @@
1
+ import type { StyleProp } from 'react-native'
2
+ import { getClassName } from '../core'
3
+ import type { RNStyle, UnistylesValues } from '../types'
4
+ import { createUnistylesRef } from '../web/utils/createUnistylesRef'
5
+
6
+ export const getWebProps = <T>(style: StyleProp<RNStyle>) => {
7
+ const styles = getClassName(style as UnistylesValues)
8
+ const ref = createUnistylesRef<T>(styles)
9
+ const [generatedStyles] = styles ?? []
10
+
11
+ return {
12
+ className: [
13
+ generatedStyles?.hash,
14
+ generatedStyles?.injectedClassName,
15
+ ].filter(Boolean).join(' '),
16
+ ref
17
+ }
18
+ }
@@ -0,0 +1,2 @@
1
+
2
+ export { getWebProps } from './getWebProps'
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../lib/commonjs/web-only/index",
3
+ "module": "../lib/module/web-only/index",
4
+ "react-native": "../src/web-only/index",
5
+ "types": "../lib/typescript/src/web-only/index"
6
+ }
@@ -1,49 +0,0 @@
1
- #include "UnistylesCommitHook.h"
2
-
3
- using namespace margelo::nitro::unistyles;
4
- using namespace facebook::react;
5
-
6
- core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {
7
- _uiManager->unregisterCommitHook(*this);
8
- }
9
-
10
- void core::UnistylesCommitHook::commitHookWasRegistered(const UIManager &uiManager) noexcept {}
11
- void core::UnistylesCommitHook::commitHookWasUnregistered(const UIManager &uiManager) noexcept {}
12
-
13
- RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
14
- const ShadowTree &shadowTree,
15
- const RootShadowNode::Shared &oldRootShadowNode,
16
- const RootShadowNode::Unshared &newRootShadowNode
17
- ) noexcept {
18
- RootShadowNode::Unshared rootNode = newRootShadowNode;
19
- auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootShadowNode);
20
-
21
- // this is Unistyles commit, we don't need to override it
22
- if (unistylesRootNode->hasUnistylesCommitTrait()) {
23
- unistylesRootNode->removeUnistylesCommitTrait();
24
- unistylesRootNode->addUnistylesMountTrait();
25
-
26
- return newRootShadowNode;
27
- }
28
-
29
- // this is React Native / Reanimated commit
30
- // merge Unistyles updates before it completes
31
- auto& registry = core::UnistylesRegistry::get();
32
- auto& shadowLeafUpdates = registry.trafficController.getUpdates();
33
-
34
- // oops, no updates from Unistyles yet, skip it!
35
- if (shadowLeafUpdates.size() == 0) {
36
- return newRootShadowNode;
37
- }
38
-
39
- auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
40
-
41
- registry.trafficController.stopUnistylesTraffic();
42
-
43
- // we have few updates, so merge it
44
- return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
45
- *rootNode,
46
- shadowLeafUpdates,
47
- affectedNodes
48
- ));
49
- }
@@ -1,27 +0,0 @@
1
- #pragma once
2
-
3
- #include <react/renderer/uimanager/UIManager.h>
4
- #include <react/renderer/uimanager/UIManagerCommitHook.h>
5
- #include "ShadowTreeManager.h"
6
- #include "ShadowTrafficController.h"
7
-
8
- namespace margelo::nitro::unistyles::core {
9
-
10
- using namespace facebook::react;
11
-
12
- struct UnistylesCommitHook : public UIManagerCommitHook {
13
- UnistylesCommitHook(std::shared_ptr<UIManager> uiManager) : _uiManager{uiManager} {
14
- _uiManager->registerCommitHook(*this);
15
- }
16
-
17
- ~UnistylesCommitHook() noexcept override;
18
-
19
- void commitHookWasRegistered(const UIManager &uiManager) noexcept override;
20
- void commitHookWasUnregistered(const UIManager &uiManager) noexcept override;
21
- RootShadowNode::Unshared shadowTreeWillCommit(const ShadowTree &shadowTree, const RootShadowNode::Shared &oldRootShadowNode, const RootShadowNode::Unshared &newRootShadowNode) noexcept override;
22
-
23
- private:
24
- std::shared_ptr<UIManager> _uiManager;
25
- };
26
-
27
- }
@@ -1,28 +0,0 @@
1
- #include "UnistylesMountHook.h"
2
-
3
- using namespace margelo::nitro::unistyles;
4
- using namespace facebook::react;
5
-
6
- core::UnistylesMountHook::~UnistylesMountHook() noexcept {
7
- _uiManager->unregisterMountHook(*this);
8
- }
9
-
10
- void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept {
11
- auto rootNode = std::const_pointer_cast<RootShadowNode>(rootShadowNode);
12
- auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(rootNode);
13
-
14
- // if this is Unistyles commit, do nothing
15
- if (unistylesRootNode->hasUnistylesMountTrait()) {
16
- unistylesRootNode->removeUnistylesMountTrait();
17
-
18
- return;
19
- }
20
-
21
- // this is React Native or Reanimated commit
22
- // one more time merge Unistyles changes
23
- auto& registry = core::UnistylesRegistry::get();
24
-
25
- if (!registry.trafficController.shouldStop()) {
26
- shadow::ShadowTreeManager::updateShadowTree(this->_uiManager->getShadowTreeRegistry());
27
- }
28
- }
@@ -1,27 +0,0 @@
1
- #pragma once
2
-
3
- #include <react/renderer/uimanager/UIManager.h>
4
- #include <react/renderer/uimanager/UIManagerMountHook.h>
5
- #include "ShadowTreeManager.h"
6
- #include "HybridUnistylesRuntime.h"
7
-
8
- namespace margelo::nitro::unistyles::core {
9
-
10
- using namespace facebook::react;
11
-
12
- struct UnistylesMountHook : public UIManagerMountHook {
13
- UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
14
- : _uiManager{uiManager}, _unistylesRuntime{unistylesRuntime} {
15
- _uiManager->registerMountHook(*this);
16
- }
17
-
18
- ~UnistylesMountHook() noexcept override;
19
-
20
- void shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept override;
21
-
22
- private:
23
- std::shared_ptr<UIManager> _uiManager;
24
- std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
25
- };
26
-
27
- }
@@ -1 +0,0 @@
1
- {"type":"module"}
package/plugin/consts.js DELETED
@@ -1,63 +0,0 @@
1
- const REACT_NATIVE_COMPONENT_NAMES = [
2
- 'ActivityIndicator',
3
- 'View',
4
- 'Text',
5
- 'Image',
6
- 'ImageBackground',
7
- 'KeyboardAvoidingView',
8
- 'Pressable',
9
- 'ScrollView',
10
- 'FlatList',
11
- 'SectionList',
12
- 'Switch',
13
- 'TextInput',
14
- 'RefreshControl',
15
- 'TouchableHighlight',
16
- 'TouchableOpacity',
17
- 'VirtualizedList',
18
- 'Animated'
19
- // Modal - there is no exposed native handle
20
- // TouchableWithoutFeedback - can't accept a ref
21
- ]
22
-
23
- // auto replace RN imports to Unistyles imports under these paths
24
- // our implementation simply borrows 'ref' to register it in ShadowRegistry
25
- // so we won't affect anyone's implementation
26
- const REPLACE_WITH_UNISTYLES_PATHS = [
27
- 'react-native-reanimated/src/component',
28
- 'react-native-gesture-handler/src/components'
29
- ]
30
-
31
- // this is more powerful API as it allows to convert unmatched imports to Unistyles
32
- // { path: string, imports: Array<{ name: string, isDefault: boolean, path: string, mapTo: string }> }
33
- // path => node_modules path
34
- // imports:
35
- // name? <- target import name if isDefault is false
36
- // isDefault <- is the import default?
37
- // path <- path to the target import
38
- // mapTo <- name of the Unistyles component
39
- const REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = []
40
-
41
- // this list will additionally detect React Native direct imports
42
- const NATIVE_COMPONENTS_PATHS = {
43
- imports: [
44
- {
45
- name: 'NativeText',
46
- isDefault: false,
47
- path: 'react-native/Libraries/Text/TextNativeComponent',
48
- mapTo: 'NativeText'
49
- },
50
- {
51
- isDefault: true,
52
- path: 'react-native/Libraries/Components/View/ViewNativeComponent',
53
- mapTo: 'NativeView'
54
- }
55
- ]
56
- }
57
-
58
- module.exports = {
59
- NATIVE_COMPONENTS_PATHS,
60
- REACT_NATIVE_COMPONENT_NAMES,
61
- REPLACE_WITH_UNISTYLES_PATHS,
62
- REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
63
- }