react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (316) hide show
  1. package/Unistyles.podspec +3 -2
  2. package/cxx/common/Constants.h +2 -0
  3. package/cxx/common/Helpers.h +97 -5
  4. package/cxx/core/HostStyle.cpp +19 -13
  5. package/cxx/core/HostStyle.h +4 -0
  6. package/cxx/core/StyleSheet.h +0 -2
  7. package/cxx/core/StyleSheetRegistry.cpp +10 -13
  8. package/cxx/core/StyleSheetRegistry.h +4 -4
  9. package/cxx/core/Unistyle.h +7 -10
  10. package/cxx/core/UnistyleData.h +23 -0
  11. package/cxx/core/UnistyleWrapper.h +78 -10
  12. package/cxx/core/UnistylesCommitHook.cpp +22 -13
  13. package/cxx/core/UnistylesCommitHook.h +8 -1
  14. package/cxx/core/UnistylesCommitShadowNode.h +13 -0
  15. package/cxx/core/UnistylesMountHook.cpp +37 -0
  16. package/cxx/core/UnistylesMountHook.h +31 -0
  17. package/cxx/core/UnistylesRegistry.cpp +56 -81
  18. package/cxx/core/UnistylesRegistry.h +15 -13
  19. package/cxx/core/UnistylesState.cpp +14 -8
  20. package/cxx/core/UnistylesState.h +1 -0
  21. package/cxx/hybridObjects/HybridShadowRegistry.cpp +15 -9
  22. package/cxx/hybridObjects/HybridStyleSheet.cpp +43 -38
  23. package/cxx/hybridObjects/HybridStyleSheet.h +10 -7
  24. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +35 -16
  25. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  26. package/cxx/parser/Parser.cpp +105 -164
  27. package/cxx/parser/Parser.h +8 -14
  28. package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
  29. package/cxx/shadowTree/ShadowTrafficController.h +33 -0
  30. package/cxx/shadowTree/ShadowTreeManager.cpp +13 -11
  31. package/cxx/shadowTree/ShadowTreeManager.h +1 -0
  32. package/ios/Unistyles.h +1 -0
  33. package/ios/UnistylesModuleOnLoad.h +2 -0
  34. package/ios/UnistylesModuleOnLoad.mm +8 -1
  35. package/lib/commonjs/index.js +4 -0
  36. package/lib/commonjs/index.js.map +1 -1
  37. package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
  38. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  39. package/lib/commonjs/specs/ShadowRegistry/index.js +7 -6
  40. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  41. package/lib/commonjs/specs/StatusBar/index.js +1 -1
  42. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  43. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  44. package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
  45. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  46. package/lib/commonjs/specs/index.web.js +1 -1
  47. package/lib/commonjs/web/convert/boxShadow.js +77 -0
  48. package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
  49. package/lib/commonjs/web/convert/breakpoint.js +25 -0
  50. package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
  51. package/lib/commonjs/web/convert/index.js +76 -0
  52. package/lib/commonjs/web/convert/index.js.map +1 -0
  53. package/lib/commonjs/web/convert/module.d.js +2 -0
  54. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  55. package/lib/commonjs/web/convert/shadow.js +68 -0
  56. package/lib/commonjs/web/convert/shadow.js.map +1 -0
  57. package/lib/commonjs/web/convert/style.js +89 -0
  58. package/lib/commonjs/web/convert/style.js.map +1 -0
  59. package/lib/commonjs/web/convert/textShadow.js +73 -0
  60. package/lib/commonjs/web/convert/textShadow.js.map +1 -0
  61. package/lib/commonjs/web/convert/transform.js +72 -0
  62. package/lib/commonjs/web/convert/transform.js.map +1 -0
  63. package/lib/commonjs/web/convert/types.js +9 -0
  64. package/lib/commonjs/web/convert/types.js.map +1 -0
  65. package/lib/commonjs/web/convert/utils.js +55 -0
  66. package/lib/commonjs/web/convert/utils.js.map +1 -0
  67. package/lib/commonjs/web/create.js +51 -0
  68. package/lib/commonjs/web/create.js.map +1 -0
  69. package/lib/commonjs/web/createUnistylesComponent.js +61 -0
  70. package/lib/commonjs/web/createUnistylesComponent.js.map +1 -0
  71. package/lib/commonjs/web/index.js +60 -0
  72. package/lib/commonjs/web/index.js.map +1 -0
  73. package/lib/commonjs/web/listener/index.js +20 -0
  74. package/lib/commonjs/web/listener/index.js.map +1 -0
  75. package/lib/commonjs/web/listener/listenToDependencies.js +38 -0
  76. package/lib/commonjs/web/listener/listenToDependencies.js.map +1 -0
  77. package/lib/commonjs/web/listener/listener.js +35 -0
  78. package/lib/commonjs/web/listener/listener.js.map +1 -0
  79. package/lib/commonjs/web/mock.js +28 -0
  80. package/lib/commonjs/web/mock.js.map +1 -0
  81. package/lib/commonjs/web/mq.js +23 -0
  82. package/lib/commonjs/web/mq.js.map +1 -0
  83. package/lib/commonjs/web/pseudo.js +10 -0
  84. package/lib/commonjs/web/pseudo.js.map +1 -0
  85. package/lib/commonjs/web/registry.js +50 -0
  86. package/lib/commonjs/web/registry.js.map +1 -0
  87. package/lib/commonjs/web/runtime.js +163 -0
  88. package/lib/commonjs/web/runtime.js.map +1 -0
  89. package/lib/commonjs/web/shadowRegistry.js +123 -0
  90. package/lib/commonjs/web/shadowRegistry.js.map +1 -0
  91. package/lib/commonjs/web/state.js +81 -0
  92. package/lib/commonjs/web/state.js.map +1 -0
  93. package/lib/commonjs/web/utils.js +130 -0
  94. package/lib/commonjs/web/utils.js.map +1 -0
  95. package/lib/commonjs/web/variants/getVariants.js +39 -0
  96. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  97. package/lib/commonjs/web/variants/index.js +28 -0
  98. package/lib/commonjs/web/variants/index.js.map +1 -0
  99. package/lib/commonjs/web/variants/useVariants.js +59 -0
  100. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  101. package/lib/module/index.js +4 -0
  102. package/lib/module/index.js.map +1 -1
  103. package/lib/module/specs/NavigtionBar/index.js +1 -1
  104. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  105. package/lib/module/specs/ShadowRegistry/index.js +7 -6
  106. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  107. package/lib/module/specs/StatusBar/index.js +1 -1
  108. package/lib/module/specs/StatusBar/index.js.map +1 -1
  109. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  110. package/lib/module/specs/UnistylesRuntime/index.js +1 -1
  111. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  112. package/lib/module/specs/index.web.js +1 -1
  113. package/lib/module/specs/index.web.js.map +1 -1
  114. package/lib/module/web/convert/boxShadow.js +72 -0
  115. package/lib/module/web/convert/boxShadow.js.map +1 -0
  116. package/lib/module/web/convert/breakpoint.js +20 -0
  117. package/lib/module/web/convert/breakpoint.js.map +1 -0
  118. package/lib/module/web/convert/index.js +71 -0
  119. package/lib/module/web/convert/index.js.map +1 -0
  120. package/lib/module/web/convert/module.d.js +2 -0
  121. package/lib/module/web/convert/module.d.js.map +1 -0
  122. package/lib/module/web/convert/shadow.js +63 -0
  123. package/lib/module/web/convert/shadow.js.map +1 -0
  124. package/lib/module/web/convert/style.js +84 -0
  125. package/lib/module/web/convert/style.js.map +1 -0
  126. package/lib/module/web/convert/textShadow.js +68 -0
  127. package/lib/module/web/convert/textShadow.js.map +1 -0
  128. package/lib/module/web/convert/transform.js +67 -0
  129. package/lib/module/web/convert/transform.js.map +1 -0
  130. package/lib/module/web/convert/types.js +5 -0
  131. package/lib/module/web/convert/types.js.map +1 -0
  132. package/lib/module/web/convert/utils.js +43 -0
  133. package/lib/module/web/convert/utils.js.map +1 -0
  134. package/lib/module/web/create.js +46 -0
  135. package/lib/module/web/create.js.map +1 -0
  136. package/lib/module/web/createUnistylesComponent.js +54 -0
  137. package/lib/module/web/createUnistylesComponent.js.map +1 -0
  138. package/lib/module/web/index.js +26 -0
  139. package/lib/module/web/index.js.map +1 -0
  140. package/lib/module/web/listener/index.js +5 -0
  141. package/lib/module/web/listener/index.js.map +1 -0
  142. package/lib/module/web/listener/listenToDependencies.js +33 -0
  143. package/lib/module/web/listener/listenToDependencies.js.map +1 -0
  144. package/lib/module/web/listener/listener.js +31 -0
  145. package/lib/module/web/listener/listener.js.map +1 -0
  146. package/lib/module/web/mock.js +24 -0
  147. package/lib/module/web/mock.js.map +1 -0
  148. package/lib/module/web/mq.js +17 -0
  149. package/lib/module/web/mq.js.map +1 -0
  150. package/lib/module/web/pseudo.js +5 -0
  151. package/lib/module/web/pseudo.js.map +1 -0
  152. package/lib/module/web/registry.js +46 -0
  153. package/lib/module/web/registry.js.map +1 -0
  154. package/lib/module/web/runtime.js +159 -0
  155. package/lib/module/web/runtime.js.map +1 -0
  156. package/lib/module/web/shadowRegistry.js +119 -0
  157. package/lib/module/web/shadowRegistry.js.map +1 -0
  158. package/lib/module/web/state.js +77 -0
  159. package/lib/module/web/state.js.map +1 -0
  160. package/lib/module/web/utils.js +112 -0
  161. package/lib/module/web/utils.js.map +1 -0
  162. package/lib/module/web/variants/getVariants.js +34 -0
  163. package/lib/module/web/variants/getVariants.js.map +1 -0
  164. package/lib/module/web/variants/index.js +5 -0
  165. package/lib/module/web/variants/index.js.map +1 -0
  166. package/lib/module/web/variants/useVariants.js +54 -0
  167. package/lib/module/web/variants/useVariants.js.map +1 -0
  168. package/lib/typescript/example/App.d.ts.map +1 -1
  169. package/lib/typescript/example/Typography.d.ts +12 -0
  170. package/lib/typescript/example/Typography.d.ts.map +1 -0
  171. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
  172. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  173. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  174. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  175. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  176. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  177. package/lib/typescript/src/types/stylesheet.d.ts +2 -2
  178. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  179. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  180. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  181. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  182. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  183. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  184. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  185. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  186. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  187. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  188. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  189. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  190. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  191. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  192. package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
  193. package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
  194. package/lib/typescript/{web → src/web}/index.d.ts +14 -13
  195. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  196. package/lib/typescript/src/web/listener/index.d.ts +3 -0
  197. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  198. package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
  199. package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
  200. package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
  201. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  202. package/lib/typescript/src/web/mock.d.ts +5 -0
  203. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  204. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  205. package/lib/typescript/src/web/pseudo.d.ts +6 -0
  206. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  207. package/lib/typescript/src/web/registry.d.ts +15 -0
  208. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  209. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
  210. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  211. package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
  212. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
  213. package/lib/typescript/{web → src/web}/state.d.ts +4 -9
  214. package/lib/typescript/src/web/state.d.ts.map +1 -0
  215. package/lib/typescript/src/web/utils.d.ts +35 -0
  216. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  217. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  218. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  219. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  220. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  221. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  222. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  223. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -3
  224. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
  225. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
  226. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
  227. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
  228. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -0
  229. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
  230. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
  231. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
  232. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
  233. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  234. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
  235. package/package.json +3 -3
  236. package/plugin/__tests__/dependencies.spec.js +199 -111
  237. package/plugin/__tests__/ref.spec.js +638 -202
  238. package/plugin/__tests__/stylesheet.spec.js +182 -71
  239. package/plugin/index.js +110 -23
  240. package/plugin/ref.js +64 -13
  241. package/plugin/style.js +82 -22
  242. package/plugin/stylesheet.js +44 -1
  243. package/plugin/variants.js +33 -0
  244. package/src/index.ts +3 -0
  245. package/src/specs/NavigtionBar/index.ts +1 -1
  246. package/src/specs/ShadowRegistry/index.ts +10 -9
  247. package/src/specs/StatusBar/index.ts +1 -1
  248. package/src/specs/StyleSheet/index.ts +3 -1
  249. package/src/specs/UnistylesRuntime/index.ts +1 -1
  250. package/src/specs/index.web.ts +1 -1
  251. package/src/types/stylesheet.ts +2 -2
  252. package/{web → src/web}/convert/breakpoint.ts +1 -1
  253. package/{web → src/web}/convert/index.ts +2 -2
  254. package/{web → src/web}/convert/types.ts +1 -1
  255. package/src/web/create.ts +50 -0
  256. package/src/web/createUnistylesComponent.tsx +54 -0
  257. package/{web → src/web}/index.ts +3 -2
  258. package/src/web/listener/index.ts +2 -0
  259. package/src/web/listener/listenToDependencies.ts +45 -0
  260. package/{web → src/web}/listener/listener.ts +2 -2
  261. package/{web → src/web}/mock.ts +2 -12
  262. package/src/web/pseudo.ts +137 -0
  263. package/src/web/registry.ts +60 -0
  264. package/{web → src/web}/runtime.ts +4 -6
  265. package/src/web/shadowRegistry.ts +124 -0
  266. package/{web → src/web}/state.ts +5 -49
  267. package/{web → src/web}/utils.ts +91 -17
  268. package/src/web/variants/getVariants.ts +42 -0
  269. package/src/web/variants/index.ts +2 -0
  270. package/src/web/variants/useVariants.ts +65 -0
  271. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  272. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  273. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  274. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  275. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  276. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  277. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  278. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  279. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  280. package/lib/typescript/web/listener/index.d.ts +0 -2
  281. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  282. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  283. package/lib/typescript/web/mock.d.ts +0 -14
  284. package/lib/typescript/web/mock.d.ts.map +0 -1
  285. package/lib/typescript/web/mq.d.ts.map +0 -1
  286. package/lib/typescript/web/pseudo.d.ts +0 -4
  287. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  288. package/lib/typescript/web/registry.d.ts +0 -12
  289. package/lib/typescript/web/registry.d.ts.map +0 -1
  290. package/lib/typescript/web/runtime.d.ts.map +0 -1
  291. package/lib/typescript/web/state.d.ts.map +0 -1
  292. package/lib/typescript/web/useVariants.d.ts +0 -3
  293. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  294. package/lib/typescript/web/utils.d.ts +0 -18
  295. package/lib/typescript/web/utils.d.ts.map +0 -1
  296. package/web/create.ts +0 -102
  297. package/web/listener/index.ts +0 -1
  298. package/web/pseudo.ts +0 -11
  299. package/web/registry.ts +0 -41
  300. package/web/useVariants.ts +0 -99
  301. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  302. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  303. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  304. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  305. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  306. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  307. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  308. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  309. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  310. /package/{web → src/web}/convert/module.d.ts +0 -0
  311. /package/{web → src/web}/convert/shadow.ts +0 -0
  312. /package/{web → src/web}/convert/style.ts +0 -0
  313. /package/{web → src/web}/convert/textShadow.ts +0 -0
  314. /package/{web → src/web}/convert/transform.ts +0 -0
  315. /package/{web → src/web}/convert/utils.ts +0 -0
  316. /package/{web → src/web}/mq.ts +0 -0
@@ -0,0 +1,37 @@
1
+ #include "UnistylesMountHook.h"
2
+ #include "ShadowTreeManager.h"
3
+
4
+ using namespace margelo::nitro::unistyles;
5
+ using namespace facebook::react;
6
+
7
+ core::UnistylesMountHook::~UnistylesMountHook() noexcept {
8
+ _uiManager->unregisterMountHook(*this);
9
+ }
10
+
11
+ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept {
12
+ auto rootNode = std::const_pointer_cast<RootShadowNode>(rootShadowNode);
13
+ auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(rootNode);
14
+
15
+ // if this is Unistyles commit, do nothing
16
+ if (unistylesRootNode->hasUnistylesMountTrait()) {
17
+ unistylesRootNode->removeUnistylesMountTrait();
18
+
19
+ return;
20
+ }
21
+
22
+ // React Native commit did mount
23
+ auto& registry = core::UnistylesRegistry::get();
24
+
25
+ // so, resume Unistyles commits
26
+ registry.trafficController.resumeUnistylesTraffic();
27
+ }
28
+
29
+ shadow::ShadowLeafUpdates core::UnistylesMountHook::getUnistylesUpdates() {
30
+ auto& registry = core::UnistylesRegistry::get();
31
+ auto parser = parser::Parser(this->_unistylesRuntime);
32
+ auto dependencyMap = registry.buildDependencyMap(*this->_rt);
33
+
34
+ // don't rebuild dependency map, at this point it's already done
35
+
36
+ return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
37
+ }
@@ -0,0 +1,31 @@
1
+ #pragma once
2
+
3
+ #include <react/renderer/uimanager/UIManager.h>
4
+ #include <react/renderer/uimanager/UIManagerMountHook.h>
5
+ #include "HybridUnistylesRuntime.h"
6
+ #include "Parser.h"
7
+ #include "ShadowTreeManager.h"
8
+
9
+ namespace margelo::nitro::unistyles::core {
10
+
11
+ using namespace facebook::react;
12
+
13
+ struct UnistylesMountHook : public UIManagerMountHook {
14
+ UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, jsi::Runtime& rt)
15
+ : _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager}, _rt{&rt} {
16
+ _uiManager->registerMountHook(*this);
17
+ }
18
+
19
+ ~UnistylesMountHook() noexcept override;
20
+
21
+ void shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept override;
22
+
23
+ shadow::ShadowLeafUpdates getUnistylesUpdates();
24
+
25
+ private:
26
+ jsi::Runtime* _rt;
27
+ std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
28
+ std::shared_ptr<UIManager> _uiManager;
29
+ };
30
+
31
+ }
@@ -5,11 +5,6 @@ using namespace margelo::nitro::unistyles;
5
5
  using namespace facebook;
6
6
  using namespace facebook::react;
7
7
 
8
- using DependencyMap = std::unordered_map<
9
- std::shared_ptr<core::StyleSheet>,
10
- std::unordered_map<const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>>
11
- >;
12
-
13
8
  void core::UnistylesRegistry::registerTheme(jsi::Runtime& rt, std::string name, jsi::Object&& theme) {
14
9
  auto& state = this->getState(rt);
15
10
 
@@ -62,113 +57,93 @@ void core::UnistylesRegistry::createState(jsi::Runtime& rt) {
62
57
  void core::UnistylesRegistry::updateTheme(jsi::Runtime& rt, std::string& themeName, jsi::Function&& callback) {
63
58
  auto& state = this->getState(rt);
64
59
  auto it = state._jsThemes.find(themeName);
65
-
66
- helpers::assertThat(rt, it != state._jsThemes.end(), "you're trying to update theme '" + themeName + "' but it wasn't registered.");
67
-
60
+
61
+ helpers::assertThat(rt, it != state._jsThemes.end(), "Unistyles: You're trying to update theme '" + themeName + "' but it wasn't registered.");
62
+
68
63
  auto currentThemeValue = it->second.lock(rt);
69
-
70
- helpers::assertThat(rt, currentThemeValue.isObject(), "unable to update your theme from C++. It was already garbage collected.");
71
-
64
+
65
+ helpers::assertThat(rt, currentThemeValue.isObject(), "Unistyles: Unable to update your theme from C++. It was already garbage collected.");
66
+
72
67
  auto result = callback.call(rt, currentThemeValue.asObject(rt));
73
-
74
- helpers::assertThat(rt, result.isObject(), "returned theme is not an object. Please check your updateTheme function.");
68
+
69
+ helpers::assertThat(rt, result.isObject(), "Unistyles: Returned theme is not an object. Please check your updateTheme function.");
75
70
 
76
71
  it->second = jsi::WeakObject(rt, result.asObject(rt));
77
72
  }
78
73
 
79
- void core::UnistylesRegistry::linkShadowNodeWithUnistyle(const ShadowNodeFamily* shadowNodeFamily, const core::Unistyle::Shared unistyle) {
80
- if (!this->_shadowRegistry.contains(shadowNodeFamily)) {
81
- this->_shadowRegistry[shadowNodeFamily] = {};
74
+ void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
75
+ jsi::Runtime& rt,
76
+ const ShadowNodeFamily* shadowNodeFamily,
77
+ std::vector<core::Unistyle::Shared>& unistyles,
78
+ Variants& variants,
79
+ std::vector<folly::dynamic>& arguments
80
+ ) {
81
+ if (!this->_shadowRegistry[&rt].contains(shadowNodeFamily)) {
82
+ this->_shadowRegistry[&rt][shadowNodeFamily] = {};
82
83
  }
83
-
84
- this->_shadowRegistry[shadowNodeFamily].emplace_back(unistyle);
85
- }
86
84
 
87
- void core::UnistylesRegistry::unlinkShadowNodeWithUnistyle(const ShadowNodeFamily* shadowNodeFamily, const core::Unistyle::Shared unistyle) {
88
- auto& unistylesVec = this->_shadowRegistry[shadowNodeFamily];
89
- auto it = std::find(unistylesVec.begin(), unistylesVec.end(), unistyle);
90
-
91
- if (it != unistylesVec.end()) {
92
- this->_shadowRegistry[shadowNodeFamily].erase(it);
93
- }
85
+ std::for_each(unistyles.begin(), unistyles.end(), [&, this](Unistyle::Shared unistyle){
86
+ this->_shadowRegistry[&rt][shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments));
87
+ });
94
88
  }
95
89
 
96
- std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(int tag, core::StyleSheetType type, jsi::Object&& rawValue) {
97
- this->_styleSheetRegistry.emplace_back(std::make_shared<core::StyleSheet>(tag, type, std::move(rawValue)));
98
-
99
- return this->_styleSheetRegistry.back();
90
+ void core::UnistylesRegistry::unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily* shadowNodeFamily) {
91
+ this->_shadowRegistry[&rt][shadowNodeFamily].clear();
100
92
  }
101
93
 
102
- std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::getStyleSheetById(int tag) {
103
- auto it = std::find_if(
104
- this->_styleSheetRegistry.begin(),
105
- this->_styleSheetRegistry.end(),
106
- [tag](std::shared_ptr<StyleSheet> styleSheet){
107
- return styleSheet->tag == tag;
108
- }
109
- );
94
+ core::Unistyle::Shared core::UnistylesRegistry::findUnistyleFromKey(jsi::Runtime& rt, std::string styleKey, int tag) {
95
+ auto targetStyleSheet = this->_styleSheetRegistry[&rt][tag];
110
96
 
111
- if (it == this->_styleSheetRegistry.cend()) {
112
- throw std::runtime_error("stylesheet with tag: " + std::to_string(tag) + " cannot be found.");
97
+ if (targetStyleSheet == nullptr) {
98
+ return nullptr;
113
99
  }
114
100
 
115
- return *it;
101
+ return targetStyleSheet.get()->unistyles[styleKey];
116
102
  }
117
-
118
- DependencyMap core::UnistylesRegistry::buildDependencyMap(std::vector<UnistyleDependency>& deps) {
103
+
104
+ std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(jsi::Runtime& rt, int unid, core::StyleSheetType type, jsi::Object&& rawValue) {
105
+ this->_styleSheetRegistry[&rt][unid] = std::make_shared<core::StyleSheet>(unid, type, std::move(rawValue));
106
+
107
+ return this->_styleSheetRegistry[&rt][unid];
108
+ }
109
+
110
+ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps) {
119
111
  DependencyMap dependencyMap;
120
-
121
- for (const auto& styleSheet : this->_styleSheetRegistry) {
122
- for (const auto& [_, unistyle] : styleSheet->unistyles) {
123
- // check if in the given stylesheet we have unistyle
124
- // that depends on something affected
112
+ std::set<UnistyleDependency> uniqueDependencies(deps.begin(), deps.end());
113
+
114
+ for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
115
+ for (const auto& unistyleData : unistyles) {
125
116
  bool hasAnyOfDependencies = std::any_of(
126
- unistyle->dependencies.begin(),
127
- unistyle->dependencies.end(),
128
- [&deps](UnistyleDependency dep) {
129
- return std::find(deps.begin(), deps.end(), dep) != deps.end();
117
+ unistyleData->unistyle->dependencies.begin(),
118
+ unistyleData->unistyle->dependencies.end(),
119
+ [&uniqueDependencies](UnistyleDependency dep) {
120
+ return std::find(uniqueDependencies.begin(), uniqueDependencies.end(), dep) != uniqueDependencies.end();
130
121
  }
131
122
  );
132
-
123
+
133
124
  if (!hasAnyOfDependencies) {
134
125
  continue;
135
126
  }
136
-
137
- // if so, we need to find shadow family too
138
- for (const auto& pair : this->_shadowRegistry) {
139
- const auto& [family, unistyles] = pair;
140
-
141
- for (const auto& shadowUnistyle : unistyles) {
142
- if (unistyle != shadowUnistyle) {
143
- continue;
144
- }
145
-
146
- dependencyMap[styleSheet][family].push_back(shadowUnistyle);
147
- }
127
+
128
+ // we need to take in count all unistyles from the shadowNode
129
+ // as user might be using spreads and not all of them may have dependencies
130
+ for (const auto& unistyleData : unistyles) {
131
+ dependencyMap[family].emplace_back(unistyleData);
148
132
  }
133
+
134
+ break;
149
135
  }
150
136
  }
151
137
 
152
138
  return dependencyMap;
153
139
  }
154
140
 
155
- DependencyMap core::UnistylesRegistry::buildDependencyMap() {
141
+ core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt) {
156
142
  DependencyMap dependencyMap;
157
-
158
- for (const auto& styleSheet : this->_styleSheetRegistry) {
159
- for (const auto& [_, unistyle] : styleSheet->unistyles) {
160
- for (const auto& pair : this->_shadowRegistry) {
161
- const auto& [family, unistyles] = pair;
162
-
163
- for (const auto& shadowUnistyle : unistyles) {
164
- if (unistyle != shadowUnistyle) {
165
- continue;
166
- }
167
-
168
- // make sure to use base Unistyle class
169
- dependencyMap[styleSheet][family].push_back(shadowUnistyle);
170
- }
171
- }
143
+
144
+ for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
145
+ for (const auto& unistyleData : unistyles) {
146
+ dependencyMap[family].emplace_back(unistyleData);
172
147
  }
173
148
  }
174
149
 
@@ -1,6 +1,8 @@
1
1
  #pragma once
2
2
 
3
+ #include "set"
3
4
  #include <jsi/jsi.h>
5
+ #include <folly/dynamic.h>
4
6
  #include <react/renderer/uimanager/UIManager.h>
5
7
  #include <unordered_map>
6
8
  #include <unordered_set>
@@ -8,6 +10,8 @@
8
10
  #include "StyleSheetRegistry.h"
9
11
  #include "StyleSheet.h"
10
12
  #include "Unistyle.h"
13
+ #include "UnistyleData.h"
14
+ #include "ShadowTrafficController.h"
11
15
 
12
16
  namespace margelo::nitro::unistyles::core {
13
17
 
@@ -16,10 +20,7 @@ struct UnistylesState;
16
20
  using namespace facebook;
17
21
  using namespace facebook::react;
18
22
 
19
- using DependencyMap = std::unordered_map<
20
- std::shared_ptr<core::StyleSheet>,
21
- std::unordered_map<const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>>
22
- >;
23
+ using DependencyMap = std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>;
23
24
 
24
25
  struct UnistylesRegistry: public StyleSheetRegistry {
25
26
  static UnistylesRegistry& get();
@@ -35,19 +36,20 @@ struct UnistylesRegistry: public StyleSheetRegistry {
35
36
 
36
37
  UnistylesState& getState(jsi::Runtime& rt);
37
38
  void createState(jsi::Runtime& rt);
38
- void linkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared);
39
- void unlinkShadowNodeWithUnistyle(const ShadowNodeFamily*, const core::Unistyle::Shared);
40
- std::shared_ptr<core::StyleSheet> addStyleSheet(int tag, core::StyleSheetType type, jsi::Object&& rawValue);
41
- std::shared_ptr<core::StyleSheet> getStyleSheetById(int tag);
42
- DependencyMap buildDependencyMap(std::vector<UnistyleDependency>& deps);
43
- DependencyMap buildDependencyMap();
44
-
39
+ void linkShadowNodeWithUnistyle(jsi::Runtime& rt, const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>& unistyles, Variants& variants, std::vector<folly::dynamic>&);
40
+ void unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily*);
41
+ std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
42
+ DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
43
+ Unistyle::Shared findUnistyleFromKey(jsi::Runtime& rt, std::string styleKey, int tag);
44
+ DependencyMap buildDependencyMap(jsi::Runtime& rt);
45
+ shadow::ShadowTrafficController trafficController{};
46
+
45
47
  private:
46
48
  UnistylesRegistry() = default;
47
49
 
48
50
  std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
49
- std::vector<std::shared_ptr<core::StyleSheet>> _styleSheetRegistry{};
50
- std::unordered_map<const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>> _shadowRegistry{};
51
+ std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
52
+ std::unordered_map<jsi::Runtime*, std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>> _shadowRegistry{};
51
53
  };
52
54
 
53
55
  UnistylesRegistry& UnistylesRegistry::get() {
@@ -12,7 +12,7 @@ bool core::UnistylesState::hasAdaptiveThemes() {
12
12
  }
13
13
 
14
14
  void core::UnistylesState::setTheme(std::string themeName) {
15
- helpers::assertThat(*_rt, helpers::vecContainsKeys(this->_registeredThemeNames, {themeName}), "You're trying to set theme to: '" + std::string(themeName) + "', but it wasn't registered.");
15
+ helpers::assertThat(*_rt, helpers::vecContainsKeys(this->_registeredThemeNames, {themeName}), "Unistyles: You're trying to set theme to: '" + std::string(themeName) + "', but it wasn't registered.");
16
16
 
17
17
  if (themeName != this->_currentThemeName) {
18
18
  this->_currentThemeName = themeName;
@@ -31,15 +31,15 @@ jsi::Object core::UnistylesState::getJSTheme() {
31
31
  return jsi::Object(*_rt);
32
32
  }
33
33
 
34
- helpers::assertThat(*_rt, _currentThemeName.has_value(), "one of your stylesheets is trying to get the theme, but no theme has been selected yet. Did you forget to select an initial theme?");
34
+ helpers::assertThat(*_rt, _currentThemeName.has_value(), "Unistyles: One of your stylesheets is trying to get the theme, but no theme has been selected yet. Did you forget to select an initial theme?");
35
35
 
36
36
  auto it = this->_jsThemes.find(_currentThemeName.value());
37
37
 
38
- helpers::assertThat(*_rt, it != this->_jsThemes.end(), "you're trying to get theme '" + _currentThemeName.value() + "', but it was not registered. Did you forget to register it with StyleSheet.configure?");
38
+ helpers::assertThat(*_rt, it != this->_jsThemes.end(), "Unistyles: You're trying to get theme '" + _currentThemeName.value() + "', but it was not registered. Did you forget to register it with StyleSheet.configure?");
39
39
 
40
40
  auto maybeTheme = it->second.lock(*_rt);
41
41
 
42
- helpers::assertThat(*_rt, maybeTheme.isObject(), "unable to retrieve your theme from C++ as it has already been garbage collected, likely due to multiple hot reloads. Please live reload the app.");
42
+ helpers::assertThat(*_rt, maybeTheme.isObject(), "Unistyles: Unable to retrieve your theme from C++ as it has already been garbage collected, likely due to multiple hot reloads. Please live reload the app.");
43
43
 
44
44
  return maybeTheme.asObject(*_rt);
45
45
  }
@@ -88,8 +88,14 @@ int core::UnistylesState::parseColor(jsi::Value& maybeColor) {
88
88
  return 0;
89
89
  }
90
90
 
91
- // we must convert it to uint32_t first, otherwise color will be broken
92
- uint32_t color = this->_processColorFn.get()->call(*_rt, maybeColor.asString(*_rt)).asNumber();
93
-
94
- return color;
91
+ auto colorString = maybeColor.asString(*_rt);
92
+
93
+ if (!this->_colorCache.contains(colorString.utf8(*_rt).c_str())) {
94
+ // we must convert it to uint32_t first, otherwise color will be broken
95
+ uint32_t color = this->_processColorFn.get()->call(*_rt, colorString).asNumber();
96
+
97
+ this->_colorCache[colorString.utf8(*_rt).c_str()] = color ? color : 0;
98
+ }
99
+
100
+ return this->_colorCache[colorString.utf8(*_rt).c_str()];
95
101
  }
@@ -43,6 +43,7 @@ private:
43
43
  std::vector<std::string> _registeredThemeNames{};
44
44
  std::optional<std::string> _currentThemeName = std::nullopt;
45
45
  std::shared_ptr<jsi::Function> _processColorFn;
46
+ std::unordered_map<std::string, uint32_t> _colorCache{};
46
47
 
47
48
  friend class UnistylesRegistry;
48
49
  };
@@ -4,23 +4,29 @@ using namespace margelo::nitro::unistyles;
4
4
  using namespace facebook::react;
5
5
 
6
6
  jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
7
+ helpers::assertThat(rt, count == 4, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 4 arguments.");
8
+
7
9
  ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
8
- core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
9
-
10
+ std::vector<core::Unistyle::Shared> unistyleWrappers = core::unistyleFromValue(rt, args[1]);
11
+ core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
12
+ auto rawArguments = args[3].asObject(rt).asArray(rt);
13
+ std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
14
+
10
15
  auto& registry = core::UnistylesRegistry::get();
11
-
12
- registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper);
13
-
16
+
17
+ registry.linkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrappers, variants, arguments);
18
+
14
19
  return jsi::Value::undefined();
15
20
  }
16
21
 
17
22
  jsi::Value HybridShadowRegistry::unlink(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
23
+ helpers::assertThat(rt, count == 1, "Unistyles: Invalid babel transform 'ShadowRegistry unlink' expected 1 arguments.");
24
+
18
25
  ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
19
- core::Unistyle::Shared unistyleWrapper = core::unistyleFromValue(rt, args[1]);
20
-
26
+
21
27
  auto& registry = core::UnistylesRegistry::get();
22
28
 
23
- registry.unlinkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(), unistyleWrapper);
24
-
29
+ registry.unlinkShadowNodeWithUnistyles(rt, &shadowNodeWrapper->getFamily());
30
+
25
31
  return jsi::Value::undefined();
26
32
  }
@@ -9,27 +9,21 @@ double HybridStyleSheet::getHairlineWidth() {
9
9
  return nearestPixel / pixelRatio;
10
10
  }
11
11
 
12
- double HybridStyleSheet::get___unid() {
12
+ double HybridStyleSheet::get__unid() {
13
13
  return this->__unid;
14
14
  }
15
15
 
16
- jsi::Value HybridStyleSheet::create(jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
17
- helpers::assertThat(rt, arguments[0].isObject(), "expected to be called with object or function.");
16
+ jsi::Value HybridStyleSheet::create(jsi::Runtime& rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
17
+ // second argument is hidden, so validation is perfectly fine
18
+ helpers::assertThat(rt, count == 2, "StyleSheet.create expected to be called with one argument.");
19
+ helpers::assertThat(rt, arguments[0].isObject(), "StyleSheet.create expected to be called with object or function.");
18
20
 
19
21
  auto thisStyleSheet = thisVal.asObject(rt);
20
22
  auto& registry = core::UnistylesRegistry::get();
21
-
22
- // this might happen only when hot reloading
23
- if (this->__unid != -1) {
24
- auto registeredStyleSheet = registry.getStyleSheetById(this->__unid);
25
- auto style = std::make_shared<core::HostStyle>(registeredStyleSheet, this->_unistylesRuntime);
26
- auto styleHostObject = jsi::Object::createFromHostObject(rt, style);
27
-
28
- return styleHostObject;
29
- }
23
+ int unid = arguments[1].asNumber();
30
24
 
31
25
  jsi::Object rawStyleSheet = arguments[0].asObject(rt);
32
- auto registeredStyleSheet = registry.addStyleSheetFromValue(rt, std::move(rawStyleSheet));
26
+ auto registeredStyleSheet = registry.addStyleSheetFromValue(rt, std::move(rawStyleSheet), unid);
33
27
 
34
28
  this->__unid = registeredStyleSheet->tag;
35
29
 
@@ -45,7 +39,8 @@ jsi::Value HybridStyleSheet::create(jsi::Runtime &rt, const jsi::Value &thisVal,
45
39
  }
46
40
 
47
41
  jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
48
- helpers::assertThat(rt, arguments[0].isObject(), "expected to be called with object.");
42
+ helpers::assertThat(rt, count == 1, "StyleSheet.configure expected to be called with one argument.");
43
+ helpers::assertThat(rt, arguments[0].isObject(), "StyleSheet.configure expected to be called with object.");
49
44
 
50
45
  // create new state
51
46
  auto config = arguments[0].asObject(rt);
@@ -55,29 +50,29 @@ jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisV
55
50
 
56
51
  helpers::enumerateJSIObject(rt, config, [&](const std::string& propertyName, jsi::Value& propertyValue){
57
52
  if (propertyName == "settings") {
58
- helpers::assertThat(rt, propertyValue.isObject(), "settings must be an object.");
53
+ helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's settings must be an object.");
59
54
 
60
55
  return this->parseSettings(rt, propertyValue.asObject(rt));
61
56
  }
62
57
 
63
58
  if (propertyName == "breakpoints") {
64
- helpers::assertThat(rt, propertyValue.isObject(), "breakpoints must be an object.");
59
+ helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's breakpoints must be an object.");
65
60
 
66
61
  return this->parseBreakpoints(rt, propertyValue.asObject(rt));
67
62
  }
68
63
 
69
64
  if (propertyName == "themes") {
70
- helpers::assertThat(rt, propertyValue.isObject(), "themes must be an object.");
65
+ helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's themes must be an object.");
71
66
 
72
67
  return this->parseThemes(rt, propertyValue.asObject(rt));
73
68
  }
74
69
 
75
- helpers::assertThat(rt, false, "received unexpected key: '" + std::string(propertyName) + "'.");
70
+ helpers::assertThat(rt, false, "StyleSheet.configure received unexpected key: '" + std::string(propertyName) + "'.");
76
71
  });
77
72
 
78
73
  verifyAndSelectTheme(rt);
79
74
  loadExternalMethods(thisVal, rt);
80
- registerCommitHook(rt);
75
+ registerHooks(rt);
81
76
 
82
77
  return jsi::Value::undefined();
83
78
  }
@@ -87,7 +82,7 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
87
82
 
88
83
  helpers::enumerateJSIObject(rt, settings, [&](const std::string& propertyName, jsi::Value& propertyValue){
89
84
  if (propertyName == "adaptiveThemes") {
90
- helpers::assertThat(rt, propertyValue.isBool(), "adaptiveThemes configuration must be of boolean type.");
85
+ helpers::assertThat(rt, propertyValue.isBool(), "StyleSheet.configure's adaptiveThemes must be of boolean type.");
91
86
 
92
87
  registry.setPrefersAdaptiveThemes(rt, propertyValue.asBool());
93
88
 
@@ -96,31 +91,31 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
96
91
 
97
92
  if (propertyName == "initialTheme") {
98
93
  if (propertyValue.isObject()) {
99
- helpers::assertThat(rt, propertyValue.asObject(rt).isFunction(rt), "initialTheme configuration must be either a string or a function.");
94
+ helpers::assertThat(rt, propertyValue.asObject(rt).isFunction(rt), "StyleSheet.configure's initialTheme must be either a string or a function.");
100
95
 
101
96
  auto result = propertyValue.asObject(rt).asFunction(rt).call(rt);
102
97
 
103
- helpers::assertThat(rt, result.isString(), "initialTheme resolved from function is not a string. Please check your initialTheme function.");
98
+ helpers::assertThat(rt, result.isString(), "StyleSheet.configure's initialTheme resolved from function is not a string. Please check your initialTheme function.");
104
99
 
105
100
  return registry.setInitialThemeName(rt, result.asString(rt).utf8(rt));
106
101
  }
107
102
 
108
- helpers::assertThat(rt, propertyValue.isString(), "initialTheme configuration must be either a string or a function.");
103
+ helpers::assertThat(rt, propertyValue.isString(), "StyleSheet.configure's initialTheme must be either a string or a function.");
109
104
 
110
105
  registry.setInitialThemeName(rt, propertyValue.asString(rt).utf8(rt));
111
106
 
112
107
  return;
113
108
  }
114
109
 
115
- helpers::assertThat(rt, false, "settings received unexpected key: '" + std::string(propertyName) + "'");
110
+ helpers::assertThat(rt, false, "StyleSheet.configure's settings received unexpected key: '" + std::string(propertyName) + "'");
116
111
  });
117
112
  }
118
113
 
119
114
  void HybridStyleSheet::parseBreakpoints(jsi::Runtime &rt, jsi::Object breakpoints){
120
115
  helpers::Breakpoints sortedBreakpoints = helpers::jsiBreakpointsToVecPairs(rt, std::move(breakpoints));
121
116
 
122
- helpers::assertThat(rt, sortedBreakpoints.size() > 0, "registered breakpoints can't be empty.");
123
- helpers::assertThat(rt, sortedBreakpoints.front().second == 0, "first breakpoint must start from 0.");
117
+ helpers::assertThat(rt, sortedBreakpoints.size() > 0, "StyleSheet.configure's breakpoints can't be empty.");
118
+ helpers::assertThat(rt, sortedBreakpoints.front().second == 0, "StyleSheet.configure's first breakpoint must start from 0.");
124
119
 
125
120
  auto& registry = core::UnistylesRegistry::get();
126
121
  auto& state = registry.getState(rt);
@@ -133,7 +128,7 @@ void HybridStyleSheet::parseThemes(jsi::Runtime &rt, jsi::Object themes) {
133
128
  auto& registry = core::UnistylesRegistry::get();
134
129
 
135
130
  helpers::enumerateJSIObject(rt, themes, [&](const std::string& propertyName, jsi::Value& propertyValue){
136
- helpers::assertThat(rt, propertyValue.isObject(), "registered theme '" + propertyName + "' must be an object.");
131
+ helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's registered theme '" + propertyName + "' must be an object.");
137
132
 
138
133
  registry.registerTheme(rt, propertyName, propertyValue.asObject(rt));
139
134
  });
@@ -151,7 +146,7 @@ void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
151
146
 
152
147
  // user tries to enable adaptive themes, but didn't register both 'light' and 'dark' themes
153
148
  if (prefersAdaptiveThemes && !hasAdaptiveThemes) {
154
- helpers::assertThat(rt, false, "you're trying to enable adaptiveThemes, but you didn't register both 'light' and 'dark' themes.");
149
+ helpers::assertThat(rt, false, "Unistyles: You're trying to enable adaptiveThemes, but you didn't register both 'light' and 'dark' themes.");
155
150
  }
156
151
 
157
152
  // user didn't select initial theme nor can have adaptive themes, and registered more than 1 theme
@@ -175,14 +170,14 @@ void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
175
170
  // user selected both initial theme and adaptive themes
176
171
  // we should throw an error as these options are mutually exclusive
177
172
  if (hasInitialTheme && hasAdaptiveThemes) {
178
- helpers::assertThat(rt, false, "you're trying to set initial theme and enable adaptiveThemes, but these options are mutually exclusive.");
173
+ helpers::assertThat(rt, false, "Unistyles: You're trying to set initial theme and enable adaptiveThemes, but these options are mutually exclusive.");
179
174
  }
180
175
 
181
176
  // user only selected initial theme
182
177
  // validate if following theme exist
183
178
  std::string selectedTheme = state.getInitialTheme().value();
184
179
 
185
- helpers::assertThat(rt, state.hasTheme(selectedTheme), "you're trying to select theme '" + selectedTheme + "' but it wasn't registered.");
180
+ helpers::assertThat(rt, state.hasTheme(selectedTheme), "Unistyles: You're trying to select theme '" + selectedTheme + "' but it wasn't registered.");
186
181
 
187
182
  state.setTheme(selectedTheme);
188
183
  }
@@ -201,18 +196,18 @@ void HybridStyleSheet::setThemeFromColorScheme(jsi::Runtime& rt) {
201
196
 
202
197
  return;
203
198
  default:
204
- throw std::runtime_error("unable to set adaptive theme as your device doesn't support it.");
199
+ throw std::runtime_error("Unistyles: Unable to set adaptive theme as your device doesn't support it.");
205
200
  }
206
201
  }
207
202
 
208
203
  void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt) {
209
204
  auto jsMethods = thisValue.getObject(rt).getProperty(rt, "jsMethods");
210
205
 
211
- helpers::assertThat(rt, jsMethods.isObject(), "can't find jsMethods.");
206
+ helpers::assertThat(rt, jsMethods.isObject(), "Unistyles: Can't find jsMethods.");
212
207
 
213
208
  auto maybeProcessColorFn = jsMethods.asObject(rt).getProperty(rt, "processColor");
214
209
 
215
- helpers::assertThat(rt, maybeProcessColorFn.isObject(), "can't load processColor function from JS.");
210
+ helpers::assertThat(rt, maybeProcessColorFn.isObject(), "Unistyles: Can't load processColor function from JS.");
216
211
 
217
212
  auto processColorFn = maybeProcessColorFn.asObject(rt).asFunction(rt);
218
213
  auto& registry = core::UnistylesRegistry::get();
@@ -224,22 +219,32 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
224
219
  void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies) {
225
220
  auto& registry = core::UnistylesRegistry::get();
226
221
  auto parser = parser::Parser(this->_unistylesRuntime);
227
- auto dependencyMap = registry.buildDependencyMap(dependencies);
228
222
  auto& rt = this->_unistylesRuntime->getRuntime();
229
223
 
224
+ // check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
225
+ auto colorSchemeIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::COLORSCHEME);
226
+
227
+ if (colorSchemeIt != dependencies.end()) {
228
+ this->_unistylesRuntime->includeDependenciesForColorSchemeChange(dependencies);
229
+ }
230
+
231
+ auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
232
+
230
233
  if (dependencyMap.size() == 0) {
231
234
  return;
232
235
  }
233
236
 
234
237
  parser.rebuildUnistylesInDependencyMap(rt, dependencyMap);
235
238
 
239
+ // this is required, otherwise shadow tree will ignore Unistyles commit
240
+ registry.trafficController.setHasUnistylesCommit(true);
241
+
236
242
  auto shadowLeafUpdates = parser.dependencyMapToShadowLeafUpdates(dependencyMap);
237
243
 
238
244
  shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
239
245
  }
240
246
 
241
- void HybridStyleSheet::registerCommitHook(jsi::Runtime &rt) {
242
- UIManager& uiManager = const_cast<UIManager&>(UIManagerBinding::getBinding(rt)->getUIManager());
243
-
244
- this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(uiManager, this->_unistylesRuntime);
247
+ void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
248
+ this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager, this->_unistylesRuntime, rt);
249
+ this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime, rt);
245
250
  }