react-native-unistyles 3.0.0-beta.8 → 3.0.0-experimental-2025051402

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 (367) hide show
  1. package/README.md +32 -26
  2. package/Unistyles.podspec +1 -0
  3. package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
  4. package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
  5. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
  6. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +2 -3
  7. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
  9. package/components/native/ActivityIndicator/package.json +1 -0
  10. package/components/native/Animated/package.json +1 -0
  11. package/components/native/FlatList/package.json +1 -0
  12. package/components/native/Image/package.json +2 -1
  13. package/components/native/ImageBackground/package.json +1 -0
  14. package/components/native/KeyboardAvoidingView/package.json +1 -0
  15. package/components/native/NativeText/package.json +1 -0
  16. package/components/native/NativeView/package.json +1 -0
  17. package/components/native/Pressable/package.json +1 -0
  18. package/components/native/RefreshControl/package.json +1 -0
  19. package/components/native/ScrollView/package.json +1 -0
  20. package/components/native/SectionList/package.json +1 -0
  21. package/components/native/Switch/package.json +1 -0
  22. package/components/native/Text/package.json +1 -0
  23. package/components/native/TextInput/package.json +1 -0
  24. package/components/native/TouchableHighlight/package.json +1 -0
  25. package/components/native/TouchableOpacity/package.json +1 -0
  26. package/components/native/View/package.json +1 -0
  27. package/components/native/VirtualizedList/package.json +1 -0
  28. package/cxx/common/Helpers.h +4 -0
  29. package/cxx/core/HostUnistyle.cpp +14 -5
  30. package/cxx/core/StyleSheet.h +1 -1
  31. package/cxx/core/UnistyleWrapper.h +1 -1
  32. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  33. package/cxx/core/UnistylesRegistry.cpp +67 -64
  34. package/cxx/core/UnistylesRegistry.h +1 -1
  35. package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
  36. package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
  37. package/cxx/parser/Parser.cpp +161 -115
  38. package/cxx/parser/Parser.h +1 -1
  39. package/cxx/shadowTree/ShadowTrafficController.h +7 -9
  40. package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
  41. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  42. package/ios/NativePlatform+ios.swift +1 -1
  43. package/ios/NativePlatformListener+ios.swift +12 -7
  44. package/ios/UnistylesModuleOnLoad.h +1 -5
  45. package/ios/UnistylesModuleOnLoad.mm +5 -13
  46. package/lib/commonjs/components/native/Image.js +27 -1
  47. package/lib/commonjs/components/native/Image.js.map +1 -1
  48. package/lib/commonjs/components/native/Image.native.js +10 -0
  49. package/lib/commonjs/components/native/Image.native.js.map +1 -0
  50. package/lib/commonjs/components/native/ImageBackground.js +17 -28
  51. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  52. package/lib/commonjs/components/native/Pressable.native.js +7 -4
  53. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  54. package/lib/commonjs/core/createUnistylesElement.js +17 -21
  55. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  56. package/lib/commonjs/core/createUnistylesElement.native.js +6 -4
  57. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  58. package/lib/commonjs/core/createUnistylesImageBackground.js +7 -5
  59. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  60. package/lib/commonjs/core/getClassname.js +11 -5
  61. package/lib/commonjs/core/getClassname.js.map +1 -1
  62. package/lib/commonjs/core/passForwardRef.js +3 -5
  63. package/lib/commonjs/core/passForwardRef.js.map +1 -1
  64. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  65. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  66. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -1
  67. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  68. package/lib/commonjs/core/withUnistyles/withUnistyles.js +14 -5
  69. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  70. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +1 -1
  71. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  72. package/lib/commonjs/hooks/useMedia.js +4 -4
  73. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  74. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  75. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  76. package/lib/commonjs/mocks.js +203 -0
  77. package/lib/commonjs/mocks.js.map +1 -0
  78. package/lib/commonjs/mq.js +1 -23
  79. package/lib/commonjs/mq.js.map +1 -1
  80. package/lib/commonjs/reanimated/index.js +13 -0
  81. package/lib/commonjs/reanimated/index.js.map +1 -0
  82. package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
  83. package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
  84. package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
  85. package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
  86. package/lib/commonjs/server/getServerUnistyles.js +9 -4
  87. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  88. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  89. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  90. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  91. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  92. package/lib/commonjs/server/serialize.js +24 -0
  93. package/lib/commonjs/server/serialize.js.map +1 -0
  94. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  95. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  96. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  97. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  98. package/lib/commonjs/utils.js +23 -1
  99. package/lib/commonjs/utils.js.map +1 -1
  100. package/lib/commonjs/web/convert/index.js +4 -7
  101. package/lib/commonjs/web/convert/index.js.map +1 -1
  102. package/lib/commonjs/web/convert/object/filter.js +7 -8
  103. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  104. package/lib/commonjs/web/create.js +10 -2
  105. package/lib/commonjs/web/create.js.map +1 -1
  106. package/lib/commonjs/web/css/core.js +2 -2
  107. package/lib/commonjs/web/css/core.js.map +1 -1
  108. package/lib/commonjs/web/css/state.js +6 -3
  109. package/lib/commonjs/web/css/state.js.map +1 -1
  110. package/lib/commonjs/web/index.js +7 -12
  111. package/lib/commonjs/web/index.js.map +1 -1
  112. package/lib/commonjs/web/registry.js +11 -9
  113. package/lib/commonjs/web/registry.js.map +1 -1
  114. package/lib/commonjs/web/runtime.js +5 -1
  115. package/lib/commonjs/web/runtime.js.map +1 -1
  116. package/lib/commonjs/web/services.js +7 -2
  117. package/lib/commonjs/web/services.js.map +1 -1
  118. package/lib/commonjs/web/shadowRegistry.js +27 -10
  119. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  120. package/lib/commonjs/web/state.js +11 -2
  121. package/lib/commonjs/web/state.js.map +1 -1
  122. package/lib/commonjs/web/types.js +2 -0
  123. package/lib/commonjs/web/types.js.map +1 -1
  124. package/lib/commonjs/web/utils/createUnistylesRef.js +31 -0
  125. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
  126. package/lib/commonjs/web/utils/unistyle.js +40 -14
  127. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  128. package/lib/commonjs/web-only/getWebProps.js +19 -0
  129. package/lib/commonjs/web-only/getWebProps.js.map +1 -0
  130. package/lib/commonjs/web-only/index.js +13 -0
  131. package/lib/commonjs/web-only/index.js.map +1 -0
  132. package/lib/module/components/native/Image.js +26 -2
  133. package/lib/module/components/native/Image.js.map +1 -1
  134. package/lib/module/components/native/Image.native.js +6 -0
  135. package/lib/module/components/native/Image.native.js.map +1 -0
  136. package/lib/module/components/native/ImageBackground.js +18 -29
  137. package/lib/module/components/native/ImageBackground.js.map +1 -1
  138. package/lib/module/components/native/Pressable.native.js +7 -4
  139. package/lib/module/components/native/Pressable.native.js.map +1 -1
  140. package/lib/module/core/createUnistylesElement.js +17 -21
  141. package/lib/module/core/createUnistylesElement.js.map +1 -1
  142. package/lib/module/core/createUnistylesElement.native.js +6 -4
  143. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  144. package/lib/module/core/createUnistylesImageBackground.js +7 -5
  145. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  146. package/lib/module/core/getClassname.js +9 -5
  147. package/lib/module/core/getClassname.js.map +1 -1
  148. package/lib/module/core/passForwardRef.js +3 -5
  149. package/lib/module/core/passForwardRef.js.map +1 -1
  150. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  151. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  152. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -1
  153. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  154. package/lib/module/core/withUnistyles/withUnistyles.js +14 -5
  155. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  156. package/lib/module/core/withUnistyles/withUnistyles.native.js +1 -1
  157. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  158. package/lib/module/hooks/useMedia.js +1 -1
  159. package/lib/module/hooks/useMedia.js.map +1 -1
  160. package/lib/module/hooks/useMedia.native.js +1 -1
  161. package/lib/module/hooks/useMedia.native.js.map +1 -1
  162. package/lib/module/mocks.js +201 -0
  163. package/lib/module/mocks.js.map +1 -0
  164. package/lib/module/mq.js +0 -19
  165. package/lib/module/mq.js.map +1 -1
  166. package/lib/module/reanimated/index.js +4 -0
  167. package/lib/module/reanimated/index.js.map +1 -0
  168. package/lib/module/reanimated/useAnimatedTheme.js +17 -0
  169. package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
  170. package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
  171. package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
  172. package/lib/module/server/getServerUnistyles.js +7 -4
  173. package/lib/module/server/getServerUnistyles.js.map +1 -1
  174. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  175. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  176. package/lib/module/server/resetServerUnistyles.js +2 -2
  177. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  178. package/lib/module/server/serialize.js +19 -0
  179. package/lib/module/server/serialize.js.map +1 -0
  180. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  181. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  182. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  183. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  184. package/lib/module/utils.js +19 -0
  185. package/lib/module/utils.js.map +1 -1
  186. package/lib/module/web/convert/index.js +4 -7
  187. package/lib/module/web/convert/index.js.map +1 -1
  188. package/lib/module/web/convert/object/filter.js +3 -4
  189. package/lib/module/web/convert/object/filter.js.map +1 -1
  190. package/lib/module/web/create.js +9 -3
  191. package/lib/module/web/create.js.map +1 -1
  192. package/lib/module/web/css/core.js +2 -2
  193. package/lib/module/web/css/core.js.map +1 -1
  194. package/lib/module/web/css/state.js +6 -3
  195. package/lib/module/web/css/state.js.map +1 -1
  196. package/lib/module/web/index.js +4 -10
  197. package/lib/module/web/index.js.map +1 -1
  198. package/lib/module/web/registry.js +11 -9
  199. package/lib/module/web/registry.js.map +1 -1
  200. package/lib/module/web/runtime.js +5 -1
  201. package/lib/module/web/runtime.js.map +1 -1
  202. package/lib/module/web/services.js +7 -1
  203. package/lib/module/web/services.js.map +1 -1
  204. package/lib/module/web/shadowRegistry.js +27 -10
  205. package/lib/module/web/shadowRegistry.js.map +1 -1
  206. package/lib/module/web/state.js +11 -2
  207. package/lib/module/web/state.js.map +1 -1
  208. package/lib/module/web/types.js +1 -1
  209. package/lib/module/web/types.js.map +1 -1
  210. package/lib/module/web/utils/createUnistylesRef.js +24 -0
  211. package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
  212. package/lib/module/web/utils/unistyle.js +32 -10
  213. package/lib/module/web/utils/unistyle.js.map +1 -1
  214. package/lib/module/web-only/getWebProps.js +14 -0
  215. package/lib/module/web-only/getWebProps.js.map +1 -0
  216. package/lib/module/web-only/index.js +4 -0
  217. package/lib/module/web-only/index.js.map +1 -0
  218. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  219. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  220. package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
  221. package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
  222. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  223. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  224. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  225. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  226. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  227. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  228. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  229. package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
  230. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  231. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  232. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  233. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  234. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  235. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
  236. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  237. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
  238. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  239. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  240. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  241. package/lib/typescript/src/mocks.d.ts +2 -0
  242. package/lib/typescript/src/mocks.d.ts.map +1 -0
  243. package/lib/typescript/src/mq.d.ts +0 -8
  244. package/lib/typescript/src/mq.d.ts.map +1 -1
  245. package/lib/typescript/src/reanimated/index.d.ts +2 -0
  246. package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
  247. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
  248. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
  249. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
  250. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
  251. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  252. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  253. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  254. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  255. package/lib/typescript/src/server/serialize.d.ts +2 -0
  256. package/lib/typescript/src/server/serialize.d.ts.map +1 -0
  257. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  258. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  259. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  260. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  261. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  262. package/lib/typescript/src/types/common.d.ts +0 -1
  263. package/lib/typescript/src/types/common.d.ts.map +1 -1
  264. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  265. package/lib/typescript/src/utils.d.ts +8 -0
  266. package/lib/typescript/src/utils.d.ts.map +1 -1
  267. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  268. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  269. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  270. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  271. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  272. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  273. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  274. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  275. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  276. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  277. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  278. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  279. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  280. package/lib/typescript/src/web/create.d.ts.map +1 -1
  281. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  282. package/lib/typescript/src/web/css/state.d.ts +4 -1
  283. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  284. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  285. package/lib/typescript/src/web/index.d.ts +0 -5
  286. package/lib/typescript/src/web/index.d.ts.map +1 -1
  287. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  288. package/lib/typescript/src/web/registry.d.ts +2 -2
  289. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  290. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  291. package/lib/typescript/src/web/services.d.ts +6 -1
  292. package/lib/typescript/src/web/services.d.ts.map +1 -1
  293. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
  294. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  295. package/lib/typescript/src/web/state.d.ts +2 -0
  296. package/lib/typescript/src/web/state.d.ts.map +1 -1
  297. package/lib/typescript/src/web/types.d.ts +3 -0
  298. package/lib/typescript/src/web/types.d.ts.map +1 -1
  299. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  300. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +11 -0
  301. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
  302. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -2
  303. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  304. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  305. package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
  306. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
  307. package/lib/typescript/src/web-only/index.d.ts +2 -0
  308. package/lib/typescript/src/web-only/index.d.ts.map +1 -0
  309. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  310. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  311. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  312. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  313. package/package.json +66 -32
  314. package/plugin/index.js +155 -67
  315. package/reanimated/package.json +6 -0
  316. package/server/package.json +6 -0
  317. package/src/components/native/Image.native.tsx +4 -0
  318. package/src/components/native/Image.tsx +36 -3
  319. package/src/components/native/ImageBackground.tsx +18 -33
  320. package/src/components/native/Pressable.native.tsx +12 -4
  321. package/src/core/createUnistylesElement.native.tsx +12 -6
  322. package/src/core/createUnistylesElement.tsx +26 -27
  323. package/src/core/createUnistylesImageBackground.tsx +16 -10
  324. package/src/core/getClassname.ts +16 -5
  325. package/src/core/passForwardRef.ts +5 -5
  326. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  327. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +17 -0
  328. package/src/core/withUnistyles/withUnistyles.native.tsx +3 -4
  329. package/src/core/withUnistyles/withUnistyles.tsx +23 -6
  330. package/src/hooks/useMedia.native.ts +1 -1
  331. package/src/hooks/useMedia.ts +1 -1
  332. package/src/mocks.ts +217 -0
  333. package/src/mq.ts +0 -24
  334. package/src/reanimated/index.ts +1 -0
  335. package/src/reanimated/useAnimatedTheme.native.ts +21 -0
  336. package/src/reanimated/useAnimatedTheme.ts +19 -0
  337. package/src/server/getServerUnistyles.tsx +15 -10
  338. package/src/server/hydrateServerUnistyles.ts +3 -2
  339. package/src/server/resetServerUnistyles.ts +4 -3
  340. package/src/server/serialize.ts +20 -0
  341. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  342. package/src/specs/ShadowRegistry/index.ts +1 -2
  343. package/src/types/common.ts +0 -1
  344. package/src/utils.ts +25 -0
  345. package/src/web/convert/index.ts +5 -7
  346. package/src/web/convert/object/filter.ts +4 -4
  347. package/src/web/create.ts +10 -3
  348. package/src/web/css/core.ts +2 -2
  349. package/src/web/css/state.ts +5 -3
  350. package/src/web/index.ts +4 -16
  351. package/src/web/registry.ts +20 -11
  352. package/src/web/runtime.ts +6 -2
  353. package/src/web/services.ts +14 -1
  354. package/src/web/shadowRegistry.ts +35 -13
  355. package/src/web/state.ts +14 -2
  356. package/src/web/types.ts +9 -4
  357. package/src/web/utils/createUnistylesRef.ts +33 -0
  358. package/src/web/utils/unistyle.ts +55 -23
  359. package/src/web-only/getWebProps.ts +18 -0
  360. package/src/web-only/index.ts +2 -0
  361. package/web/package.json +6 -0
  362. package/cxx/core/UnistylesCommitHook.cpp +0 -52
  363. package/cxx/core/UnistylesCommitHook.h +0 -27
  364. package/cxx/core/UnistylesMountHook.cpp +0 -28
  365. package/cxx/core/UnistylesMountHook.h +0 -24
  366. package/lib/module/package.json +0 -1
  367. /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
@@ -213,113 +213,115 @@ void parser::Parser::rebuildUnistyleWithVariants(jsi::Runtime& rt, std::shared_p
213
213
  }
214
214
 
215
215
  // rebuild all unistyles that are affected by platform event
216
- void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, DependencyMap& dependencyMap, std::vector<std::shared_ptr<core::StyleSheet>>& styleSheets, std::optional<UnistylesNativeMiniRuntime> maybeMiniRuntime) {
217
- std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value> parsedStyleSheetsWithDefaultTheme{};
218
- std::unordered_map<std::string, std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value>> parsedStyleSheetsWithScopedTheme{};
219
- std::unordered_map<std::shared_ptr<core::Unistyle>, bool> parsedUnistyles{};
220
-
221
- // parse all stylesheets that depends on changes
222
- for (auto styleSheet : styleSheets) {
223
- parsedStyleSheetsWithDefaultTheme.emplace(styleSheet, this->unwrapStyleSheet(rt, styleSheet, maybeMiniRuntime));
216
+ void parser::Parser::rebuildUnistylesInDependencyMap(
217
+ jsi::Runtime& rt,
218
+ DependencyMap& dependencyMap,
219
+ std::vector<std::shared_ptr<core::StyleSheet>>& styleSheets,
220
+ std::optional<UnistylesNativeMiniRuntime> maybeMiniRuntime
221
+ ) {
222
+ std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value> parsedStyleSheetsWithDefaultTheme;
223
+ std::unordered_map<std::string, std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value>> parsedStyleSheetsWithScopedTheme;
224
+ std::unordered_set<std::shared_ptr<core::Unistyle>> parsedUnistyles;
225
+
226
+ // Parse all stylesheets that depend on changes
227
+ for (const auto& styleSheet : styleSheets) {
228
+ parsedStyleSheetsWithDefaultTheme.emplace(
229
+ styleSheet,
230
+ this->unwrapStyleSheet(rt, styleSheet, maybeMiniRuntime)
231
+ );
224
232
  }
225
233
 
226
- // then parse all visible Unistyles managed by Unistyle
234
+ // Parse all visible Unistyles managed by Unistyle
227
235
  for (auto& [shadowNode, unistyles] : dependencyMap) {
228
- auto styleSheet = unistyles.begin()->get()->unistyle->parent;
236
+ auto styleSheet = unistyles.front()->unistyle->parent;
229
237
 
230
- // stylesheet may be optional for exotic unistyles
231
- if (styleSheet != nullptr && !parsedStyleSheetsWithDefaultTheme.contains(styleSheet)) {
232
- parsedStyleSheetsWithDefaultTheme.emplace(styleSheet, this->unwrapStyleSheet(rt, styleSheet, maybeMiniRuntime));
238
+ // Stylesheet may be optional for exotic unistyles
239
+ if (styleSheet && !parsedStyleSheetsWithDefaultTheme.contains(styleSheet)) {
240
+ parsedStyleSheetsWithDefaultTheme.emplace(
241
+ styleSheet,
242
+ this->unwrapStyleSheet(rt, styleSheet, maybeMiniRuntime)
243
+ );
233
244
  }
234
245
 
235
246
  for (auto& unistyleData : unistyles) {
236
247
  auto& unistyle = unistyleData->unistyle;
237
248
 
238
- // for RN styles or inline styles, compute styles only once
249
+ // For RN styles or inline styles, compute styles only once
239
250
  if (unistyle->styleKey == helpers::EXOTIC_STYLE_KEY) {
240
251
  if (!unistyleData->parsedStyle.has_value()) {
241
252
  unistyleData->parsedStyle = jsi::Value(rt, unistyle->rawValue).asObject(rt);
242
-
243
- if (!parsedUnistyles.contains(unistyle)) {
244
- parsedUnistyles.emplace(unistyle, true);
245
- }
253
+ parsedUnistyles.insert(unistyle);
246
254
  }
247
-
255
+
248
256
  continue;
249
257
  }
250
258
 
251
- // reference Unistyles StyleSheet as we may mix them for one style
259
+ // Reference Unistyles StyleSheet as we may mix them for one style
252
260
  auto unistyleStyleSheet = unistyle->parent;
253
261
 
254
- // we may hit now other StyleSheets that are referenced from affected nodes
255
- if (unistyleStyleSheet != nullptr && !parsedStyleSheetsWithDefaultTheme.contains(unistyleStyleSheet)) {
256
- parsedStyleSheetsWithDefaultTheme.emplace(unistyleStyleSheet, this->unwrapStyleSheet(rt, unistyleStyleSheet, maybeMiniRuntime));
262
+ // We may hit now other StyleSheets that are referenced from affected nodes
263
+ if (unistyleStyleSheet && !parsedStyleSheetsWithDefaultTheme.contains(unistyleStyleSheet)) {
264
+ parsedStyleSheetsWithDefaultTheme.emplace(
265
+ unistyleStyleSheet,
266
+ this->unwrapStyleSheet(rt, unistyleStyleSheet, maybeMiniRuntime)
267
+ );
257
268
  }
258
269
 
259
270
  // StyleSheet might have styles that are not affected
260
- if (!parsedStyleSheetsWithDefaultTheme[unistyleStyleSheet].asObject(rt).hasProperty(rt, unistyle->styleKey.c_str())) {
271
+ auto& parsedSheetValue = parsedStyleSheetsWithDefaultTheme[unistyleStyleSheet];
272
+ auto parsedSheetObj = parsedSheetValue.asObject(rt);
273
+
274
+ if (!parsedSheetObj.hasProperty(rt, unistyle->styleKey.c_str())) {
261
275
  continue;
262
276
  }
263
277
 
264
- // for scoped themes we need to parse unistyle exclusively
278
+ // For scoped themes we need to parse unistyle exclusively
265
279
  if (unistyleData->scopedTheme.has_value()) {
266
- std::vector<folly::dynamic> arguments = {};
267
-
268
- if (unistyleData->dynamicFunctionMetadata.has_value()) {
269
- arguments = unistyleData->dynamicFunctionMetadata.value();
280
+ auto& scopedThemeName = unistyleData->scopedTheme.value();
281
+ auto& scopedThemeMap = parsedStyleSheetsWithScopedTheme[scopedThemeName];
282
+
283
+ jsi::Value parsedStyleSheet = jsi::Value::undefined();
284
+ auto it = scopedThemeMap.find(unistyle->parent);
285
+
286
+ if (it != scopedThemeMap.end()) {
287
+ parsedStyleSheet = jsi::Value(rt, it->second);
270
288
  }
271
289
 
272
- auto parsedStyleSheet = jsi::Value::undefined();
273
- auto scopedThemeName = unistyleData->scopedTheme.value();
274
-
275
- // check if we have theme in cache
276
- if (parsedStyleSheetsWithScopedTheme.contains(scopedThemeName)) {
277
- if (parsedStyleSheetsWithScopedTheme[scopedThemeName].contains(unistyle->parent)) {
278
- parsedStyleSheet = jsi::Value(rt, parsedStyleSheetsWithScopedTheme[scopedThemeName][unistyle->parent]);
279
- }
280
- }
281
-
282
- // if not, let's build it
283
290
  if (parsedStyleSheet.isUndefined()) {
284
- parsedStyleSheet = this->getParsedStyleSheetForScopedTheme(rt, unistyle, unistyleData->scopedTheme.value());
285
-
286
- if (!parsedStyleSheetsWithScopedTheme.contains(scopedThemeName)) {
287
- parsedStyleSheetsWithScopedTheme.emplace(
288
- scopedThemeName,
289
- std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value>{}
290
- );
291
- }
292
-
293
- parsedStyleSheetsWithScopedTheme[scopedThemeName].emplace(
291
+ parsedStyleSheet = this->getParsedStyleSheetForScopedTheme(rt, unistyle, scopedThemeName);
292
+ scopedThemeMap.emplace(
294
293
  unistyle->parent,
295
294
  jsi::Value(rt, parsedStyleSheet)
296
295
  );
297
296
  }
298
297
 
299
- this->rebuildUnistyleWithScopedTheme(
300
- rt,
301
- parsedStyleSheet,
302
- unistyleData
303
- );
298
+ this->rebuildUnistyleWithScopedTheme(rt, parsedStyleSheet, unistyleData);
304
299
  } else {
305
- unistyle->rawValue = parsedStyleSheetsWithDefaultTheme[unistyleStyleSheet].asObject(rt).getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
306
- this->rebuildUnistyle(rt, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
300
+ unistyle->rawValue = parsedSheetObj
301
+ .getProperty(rt, unistyle->styleKey.c_str())
302
+ .asObject(rt);
303
+ this->rebuildUnistyle(
304
+ rt, unistyle, unistyleData->variants,
305
+ unistyleData->dynamicFunctionMetadata
306
+ );
307
307
  unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
308
308
  unistyle->isDirty = true;
309
309
  }
310
310
 
311
- if (!parsedUnistyles.contains(unistyle)) {
312
- parsedUnistyles.emplace(unistyle, true);
313
- }
311
+ parsedUnistyles.insert(unistyle);
314
312
  }
315
313
  }
316
314
 
317
- // parse whatever left in StyleSheets to be later accessible
318
- // for createUnistylesComponent
319
- for (auto styleSheet : styleSheets) {
315
+ // Parse whatever left in StyleSheets to be later accessible
316
+ for (const auto& styleSheet : styleSheets) {
317
+ auto& parsedSheetValue = parsedStyleSheetsWithDefaultTheme[styleSheet];
318
+ auto parsedSheetObj = parsedSheetValue.asObject(rt);
319
+
320
320
  for (auto& [_, unistyle] : styleSheet->unistyles) {
321
321
  if (!parsedUnistyles.contains(unistyle)) {
322
- unistyle->rawValue = parsedStyleSheetsWithDefaultTheme[styleSheet].asObject(rt).getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
322
+ unistyle->rawValue = parsedSheetObj
323
+ .getProperty(rt, unistyle->styleKey.c_str())
324
+ .asObject(rt);
323
325
  unistyle->isDirty = true;
324
326
  }
325
327
  }
@@ -370,20 +372,25 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle
370
372
 
371
373
  // convert dependency map to shadow tree updates
372
374
  void parser::Parser::rebuildShadowLeafUpdates(jsi::Runtime& rt, core::DependencyMap& dependencyMap) {
373
- shadow::ShadowLeafUpdates updates;
374
375
  auto& registry = core::UnistylesRegistry::get();
375
376
 
376
- for (const auto& [shadowNode, unistyles] : dependencyMap) {
377
- // this step is required to parse string colors eg. #000000 to int representation
378
- auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
377
+ registry.trafficController.withLock([this, &rt, &dependencyMap, &registry]() {
378
+ shadow::ShadowLeafUpdates updates;
379
+ updates.reserve(dependencyMap.size());
379
380
 
380
- updates.emplace(shadowNode, std::move(rawProps));
381
- }
381
+ for (const auto& [shadowNode, unistyles] : dependencyMap) {
382
+ // Parse string colors (e.g., "#000000") to int representation
383
+ auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
384
+
385
+ updates.emplace(shadowNode, std::move(rawProps));
386
+ }
382
387
 
383
- registry.trafficController.setUpdates(updates);
384
- registry.trafficController.resumeUnistylesTraffic();
388
+ registry.trafficController.setUpdates(updates);
389
+ registry.trafficController.resumeUnistylesTraffic();
390
+ });
385
391
  }
386
392
 
393
+
387
394
  // first level of StyleSheet, we can expect here different properties than on second level
388
395
  // eg. variants, compoundVariants, mq, breakpoints etc.
389
396
  jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants) {
@@ -925,69 +932,108 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
925
932
 
926
933
  // convert unistyles to folly with int colors
927
934
  folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles) {
928
- jsi::Object convertedStyles = jsi::Object(rt);
935
+ jsi::Object convertedStyles(rt);
929
936
  auto& state = core::UnistylesRegistry::get().getState(rt);
930
937
 
931
938
  for (const auto& unistyleData : unistyles) {
932
- // this can happen for exotic stylesheets
933
939
  if (!unistyleData->parsedStyle.has_value()) {
934
940
  continue;
935
941
  }
936
942
 
937
- helpers::enumerateJSIObject(rt, unistyleData->parsedStyle.value(), [&](const std::string& propertyName, jsi::Value& propertyValue){
938
- if (this->isColor(propertyName)) {
939
- return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
940
- }
941
-
942
- if (!propertyValue.isObject()) {
943
- return convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
944
- }
945
-
946
- auto objValue = propertyValue.asObject(rt);
947
-
948
- if (!objValue.isArray(rt)) {
949
- return convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
950
- }
951
-
952
- // parse nested arrays like boxShadow
953
- auto arrValue = objValue.asArray(rt);
954
- auto parsedArray = jsi::Array(rt, arrValue.length(rt));
955
-
956
- helpers::iterateJSIArray(rt, arrValue, [&](size_t i, jsi::Value& nestedValue){
957
- if (nestedValue.isObject()) {
958
- jsi::Object obj = jsi::Object(rt);
959
-
960
- helpers::enumerateJSIObject(rt, nestedValue.asObject(rt), [&](const std::string& propertyName, jsi::Value& propertyValue){
961
- if (this->isColor(propertyName)) {
962
- obj.setProperty(rt, propertyName.c_str(), state.parseColor(propertyValue));
963
-
964
- return;
965
- }
966
-
967
- obj.setProperty(rt, propertyName.c_str(), propertyValue);
968
- });
969
-
970
- parsedArray.setValueAtIndex(rt, i, std::move(obj));
943
+ helpers::enumerateJSIObject(
944
+ rt,
945
+ unistyleData->parsedStyle.value(),
946
+ [this, &rt, &state, &convertedStyles](const std::string& propertyName, jsi::Value& propertyValue) {
947
+ if (this->isColor(propertyName)) {
948
+ convertedStyles.setProperty(
949
+ rt,
950
+ propertyName.c_str(),
951
+ jsi::Value(state.parseColor(propertyValue))
952
+ );
953
+
954
+ return;
955
+ }
971
956
 
957
+ if (!propertyValue.isObject()) {
958
+ convertedStyles.setProperty(
959
+ rt,
960
+ propertyName.c_str(),
961
+ propertyValue
962
+ );
963
+
972
964
  return;
973
965
  }
974
966
 
975
- if (this->isColor(propertyName)) {
976
- parsedArray.setValueAtIndex(rt, i, jsi::Value(state.parseColor(nestedValue)));
967
+ jsi::Object objValue = propertyValue.asObject(rt);
977
968
 
969
+ if (!objValue.isArray(rt)) {
970
+ convertedStyles.setProperty(
971
+ rt,
972
+ propertyName.c_str(),
973
+ propertyValue
974
+ );
975
+
978
976
  return;
979
977
  }
980
978
 
981
- parsedArray.setValueAtIndex(rt, i, nestedValue);
982
- });
979
+ // parse nested arrays like boxShadow
980
+ jsi::Array arrValue = objValue.asArray(rt);
981
+ size_t arrLen = arrValue.length(rt);
982
+ jsi::Array parsedArray(rt, arrLen);
983
983
 
984
- return convertedStyles.setProperty(rt, propertyName.c_str(), parsedArray);
985
- });
984
+ helpers::iterateJSIArray(
985
+ rt,
986
+ arrValue,
987
+ [this, &rt, &state, &propertyName, &parsedArray](size_t i, jsi::Value& nestedValue) {
988
+ if (nestedValue.isObject()) {
989
+ jsi::Object obj(rt);
990
+
991
+ helpers::enumerateJSIObject(
992
+ rt,
993
+ nestedValue.asObject(rt),
994
+ [this, &rt, &state, &obj](const std::string& nestedPropName, jsi::Value& nestedPropValue) {
995
+ if (this->isColor(nestedPropName)) {
996
+ obj.setProperty(
997
+ rt,
998
+ nestedPropName.c_str(),
999
+ state.parseColor(nestedPropValue)
1000
+ );
1001
+ } else {
1002
+ obj.setProperty(
1003
+ rt,
1004
+ nestedPropName.c_str(),
1005
+ nestedPropValue
1006
+ );
1007
+ }
1008
+ }
1009
+ );
1010
+
1011
+ parsedArray.setValueAtIndex(rt, i, obj);
1012
+
1013
+ return;
1014
+ }
1015
+
1016
+ if (this->isColor(propertyName)) {
1017
+ parsedArray.setValueAtIndex(
1018
+ rt,
1019
+ i,
1020
+ jsi::Value(state.parseColor(nestedValue))
1021
+ );
1022
+ } else {
1023
+ parsedArray.setValueAtIndex(rt, i, nestedValue);
1024
+ }
1025
+ }
1026
+ );
1027
+
1028
+ convertedStyles.setProperty(rt, propertyName.c_str(), parsedArray);
1029
+ }
1030
+ );
986
1031
  }
987
1032
 
988
- return jsi::dynamicFromValue(rt, std::move(convertedStyles));
1033
+ return jsi::dynamicFromValue(rt, jsi::Value(rt, convertedStyles));
989
1034
  }
990
1035
 
1036
+
991
1037
  // check is styleKey contains color
992
1038
  bool parser::Parser::isColor(const std::string& propertyName) {
993
1039
  std::string str = propertyName;
@@ -4,7 +4,7 @@
4
4
  #include <folly/dynamic.h>
5
5
  #include "Unistyle.h"
6
6
  #include "Dimensions.hpp"
7
- #include "Constants.h"
7
+ #include "UnistylesConstants.h"
8
8
  #include "Helpers.h"
9
9
  #include "MediaQueries.h"
10
10
  #include "HybridUnistylesRuntime.h"
@@ -22,13 +22,11 @@ struct ShadowTrafficController {
22
22
 
23
23
  inline shadow::ShadowLeafUpdates& getUpdates() {
24
24
  // call it only within withLock!
25
-
26
25
  return _unistylesUpdates;
27
26
  }
28
27
 
29
28
  inline void setUpdates(shadow::ShadowLeafUpdates& newUpdates) {
30
- std::lock_guard<std::mutex> lock(_mutex);
31
-
29
+ // call it only within withLock!
32
30
  auto& targetUpdates = _unistylesUpdates;
33
31
 
34
32
  // this is important as overriding updates may skip some interim changes
@@ -43,7 +41,7 @@ struct ShadowTrafficController {
43
41
  targetUpdates.emplace(pair.first, std::move(pair.second));
44
42
  });
45
43
  }
46
-
44
+
47
45
  inline void removeShadowNode(const ShadowNodeFamily* shadowNodeFamily) {
48
46
  // call it only within withLock!
49
47
  if (_unistylesUpdates.contains(shadowNodeFamily)) {
@@ -52,19 +50,19 @@ struct ShadowTrafficController {
52
50
  }
53
51
 
54
52
  inline void restore() {
55
- std::lock_guard<std::mutex> lock(_mutex);
56
-
53
+ // call it only within withLock!
54
+
57
55
  _unistylesUpdates = {};
58
56
  _canCommit = false;
59
57
  }
60
-
58
+
61
59
  template <typename F>
62
60
  inline auto withLock(F&& func) {
63
61
  std::lock_guard<std::mutex> lock(_mutex);
64
-
62
+
65
63
  return std::forward<F>(func)();
66
64
  }
67
-
65
+
68
66
  private:
69
67
  std::atomic<bool> _canCommit = false;
70
68
  shadow::ShadowLeafUpdates _unistylesUpdates{};
@@ -8,7 +8,7 @@ using AffectedNodes = std::unordered_map<const ShadowNodeFamily*, std::unordered
8
8
 
9
9
  void shadow::ShadowTreeManager::updateShadowTree(const ShadowTreeRegistry& shadowTreeRegistry) {
10
10
  auto& registry = core::UnistylesRegistry::get();
11
-
11
+
12
12
  registry.trafficController.withLock([&](){
13
13
  auto updates = registry.trafficController.getUpdates();
14
14
 
@@ -20,20 +20,14 @@ void shadow::ShadowTreeManager::updateShadowTree(const ShadowTreeRegistry& shado
20
20
  // we could iterate via updates and create multiple commits
21
21
  // but it can cause performance issues for hundreds of nodes
22
22
  // so let's mutate Shadow Tree in single transaction
23
- auto transaction = [&](const RootShadowNode& oldRootShadowNode) {
23
+ auto transaction = [&updates](const RootShadowNode& oldRootShadowNode) {
24
24
  auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(oldRootShadowNode, updates);
25
- auto newRootNode = std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
25
+
26
+ return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
26
27
  oldRootShadowNode,
27
28
  updates,
28
29
  affectedNodes
29
30
  ));
30
-
31
- // set unistyles trait
32
- auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootNode);
33
-
34
- unistylesRootNode->addUnistylesCommitTrait();
35
-
36
- return newRootNode;
37
31
  };
38
32
 
39
33
  // commit once!
@@ -71,18 +65,17 @@ void shadow::ShadowTreeManager::updateShadowTree(const ShadowTreeRegistry& shado
71
65
  AffectedNodes shadow::ShadowTreeManager::findAffectedNodes(const RootShadowNode& rootNode, ShadowLeafUpdates& updates) {
72
66
  AffectedNodes affectedNodes;
73
67
 
74
- // compute affected nodes (sub tree)
75
- std::for_each(updates.begin(), updates.end(), [&](const auto& pair) {
76
- const auto& [family, _] = pair;
77
- const auto familyAncestors = family->getAncestors(rootNode);
68
+ for (const auto& [family, _] : updates) {
69
+ auto familyAncestors = family->getAncestors(rootNode);
78
70
 
79
- for (const auto& [parentNode, index] : std::ranges::reverse_view(familyAncestors)) {
71
+ for (auto it = familyAncestors.rbegin(); it != familyAncestors.rend(); ++it) {
72
+ const auto& [parentNode, index] = *it;
80
73
  const auto parentFamily = &parentNode.get().getFamily();
81
- std::unordered_set<int>& affectedNode = affectedNodes[parentFamily];
74
+ auto [setIt, inserted] = affectedNodes.try_emplace(parentFamily, std::unordered_set<int>{});
82
75
 
83
- affectedNode.insert(index);
76
+ setIt->second.insert(index);
84
77
  }
85
- });
78
+ }
86
79
 
87
80
  return affectedNodes;
88
81
  }
@@ -93,44 +86,54 @@ ShadowNode::Unshared shadow::ShadowTreeManager::cloneShadowTree(const ShadowNode
93
86
  const auto family = &shadowNode.getFamily();
94
87
  const auto rawPropsIt = updates.find(family);
95
88
  const auto childrenIt = affectedNodes.find(family);
96
- auto children = shadowNode.getChildren();
97
89
 
98
- // for each affected node
90
+ // Only copy children if we need to update them
91
+ std::shared_ptr<ShadowNode::ListOfShared> childrenPtr;
92
+ const auto& originalChildren = shadowNode.getChildren();
93
+
99
94
  if (childrenIt != affectedNodes.end()) {
100
- // get all indexes of children and clone it recursively
95
+ auto children = originalChildren;
96
+
101
97
  for (const auto index : childrenIt->second) {
102
98
  children[index] = cloneShadowTree(*children[index], updates, affectedNodes);
103
99
  }
100
+
101
+ childrenPtr = std::make_shared<ShadowNode::ListOfShared>(std::move(children));
102
+ } else {
103
+ childrenPtr = std::make_shared<ShadowNode::ListOfShared>(originalChildren);
104
104
  }
105
105
 
106
106
  Props::Shared updatedProps = nullptr;
107
107
 
108
- // clone props for our target shadow node and place fresh RawProps
109
108
  if (rawPropsIt != updates.end()) {
109
+ const auto& componentDescriptor = shadowNode.getComponentDescriptor();
110
+ const auto& props = shadowNode.getProps();
111
+
110
112
  PropsParserContext propsParserContext{
111
113
  shadowNode.getSurfaceId(),
112
114
  *shadowNode.getContextContainer()
113
115
  };
114
116
 
115
- // this is important and critical
116
- // first of all Android doesn't like nullish props (they work perfectly fine on iOS)
117
- // second of all Android props MUST be constructed from previous props, otherwise RawProps::~RawProps error occurs
118
- // Meta wants to remove shadowNode.getProps()->rawProps, but for now it's the only viable solution
117
+ folly::dynamic newProps;
119
118
  #ifdef ANDROID
120
- auto safeProps = rawPropsIt->second == nullptr ? folly::dynamic::object() : rawPropsIt->second;
121
- auto newProps = folly::dynamic::merge(shadowNode.getProps()->rawProps, safeProps);
119
+ auto safeProps = rawPropsIt->second == nullptr
120
+ ? folly::dynamic::object()
121
+ : rawPropsIt->second;
122
+ newProps = folly::dynamic::merge(props->rawProps, safeProps);
122
123
  #else
123
- auto newProps = rawPropsIt->second;
124
+ newProps = rawPropsIt->second;
124
125
  #endif
125
126
 
126
- updatedProps = shadowNode
127
- .getComponentDescriptor()
128
- .cloneProps(propsParserContext, shadowNode.getProps(), RawProps(newProps));
127
+ updatedProps = componentDescriptor.cloneProps(
128
+ propsParserContext,
129
+ props,
130
+ RawProps(newProps)
131
+ );
129
132
  }
130
133
 
131
134
  return shadowNode.clone({
132
135
  updatedProps ? updatedProps : ShadowNodeFragment::propsPlaceholder(),
133
- std::make_shared<ShadowNode::ListOfShared>(children),
136
+ childrenPtr,
134
137
  shadowNode.getState()
135
138
  });
136
139
  }
@@ -5,7 +5,6 @@
5
5
  #include <react/renderer/uimanager/UIManager.h>
6
6
  #include <ranges>
7
7
  #include "ShadowLeafUpdate.h"
8
- #include "UnistylesCommitShadowNode.h"
9
8
  #include "UnistylesRegistry.h"
10
9
 
11
10
  namespace margelo::nitro::unistyles::shadow {
@@ -313,7 +313,7 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
313
313
  }
314
314
 
315
315
  func setStatusBarHidden(isHidden: Bool) throws {
316
- self.onWindowChange(Notification(name: NSNotification.Name("RCTWindowFrameDidChangeNotification")))
316
+ self.onNativePlatformChange()
317
317
  }
318
318
 
319
319
  // not implemented for iOS as there are no such APIs
@@ -1,12 +1,17 @@
1
1
  import Foundation
2
+ import Combine
2
3
 
3
4
  extension NativeIOSPlatform {
4
5
  func setupPlatformListeners() {
5
- NotificationCenter.default.publisher(for: NSNotification.Name("RCTWindowFrameDidChangeNotification"))
6
- // add small delay (10ms) to make sure all values are up ot date
7
- .delay(for: .milliseconds(10), scheduler: RunLoop.current)
8
- .sink { [weak self] notification in
9
- self?.onWindowChange(notification)
6
+ let windowPublisher = NotificationCenter.default.publisher(for: NSNotification.Name("RCTWindowFrameDidChangeNotification"))
7
+ let orientationPublisher = NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)
8
+ let colorSchemePublisher = NotificationCenter.default.publisher(for: NSNotification.Name("RCTUserInterfaceStyleDidChangeNotification"))
9
+
10
+ Publishers
11
+ .MergeMany([windowPublisher, orientationPublisher, colorSchemePublisher])
12
+ .throttle(for: .milliseconds(25), scheduler: RunLoop.main, latest: true)
13
+ .sink { [weak self] _ in
14
+ self?.onNativePlatformChange()
10
15
  }
11
16
  .store(in: &cancellables)
12
17
  }
@@ -30,14 +35,14 @@ extension NativeIOSPlatform {
30
35
  func emitImeEvent(updatedMiniRuntime: UnistylesNativeMiniRuntime) {
31
36
  self.imeListeners.forEach { $0(updatedMiniRuntime) }
32
37
  }
33
-
38
+
34
39
  func unregisterPlatformListeners() {
35
40
  cancellables.removeAll()
36
41
  dependencyListeners.removeAll()
37
42
  imeListeners.removeAll()
38
43
  }
39
44
 
40
- @objc func onWindowChange(_ notification: Notification) {
45
+ @objc func onNativePlatformChange() {
41
46
  guard let currentMiniRuntime = self.miniRuntime else {
42
47
  return
43
48
  }
@@ -6,13 +6,9 @@
6
6
 
7
7
  #import <React/RCTEventEmitter.h>
8
8
  #import "TurboUnistyles/TurboUnistyles.h"
9
- #import <React/RCTSurfacePresenter.h>
10
- #import <React/RCTScheduler.h>
11
- #import <React/RCTCallInvoker.h>
12
- #import <React/RCTCallInvokerModule.h>
13
9
  #import <ReactCommon/RCTTurboModuleWithJSIBindings.h>
14
10
 
15
- @interface UnistylesModule: RCTEventEmitter<NativeTurboUnistylesSpec, RCTCallInvokerModule>
11
+ @interface UnistylesModule: RCTEventEmitter<NativeTurboUnistylesSpec>
16
12
  @end
17
13
 
18
14
  @interface UnistylesModule()<RCTTurboModuleWithJSIBindings>