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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (328) hide show
  1. package/Unistyles.podspec +3 -2
  2. package/cxx/common/Constants.h +3 -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 +58 -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/expo-example/app/(tabs)/_layout.d.ts +3 -0
  172. package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts.map +1 -0
  173. package/lib/typescript/expo-example/app/(tabs)/explore.d.ts +3 -0
  174. package/lib/typescript/expo-example/app/(tabs)/explore.d.ts.map +1 -0
  175. package/lib/typescript/expo-example/app/(tabs)/index.d.ts +3 -0
  176. package/lib/typescript/expo-example/app/(tabs)/index.d.ts.map +1 -0
  177. package/lib/typescript/expo-example/app/+html.d.ts +4 -0
  178. package/lib/typescript/expo-example/app/+html.d.ts.map +1 -0
  179. package/lib/typescript/expo-example/app/+not-found.d.ts +3 -0
  180. package/lib/typescript/expo-example/app/+not-found.d.ts.map +1 -0
  181. package/lib/typescript/expo-example/app/_layout.d.ts +3 -0
  182. package/lib/typescript/expo-example/app/_layout.d.ts.map +1 -0
  183. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
  184. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  185. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  186. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  187. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  188. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  189. package/lib/typescript/src/types/stylesheet.d.ts +2 -2
  190. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  191. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  192. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  193. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  194. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  195. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  196. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  197. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  198. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  199. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  200. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  201. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  202. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  203. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  204. package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
  205. package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
  206. package/lib/typescript/{web → src/web}/index.d.ts +14 -13
  207. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  208. package/lib/typescript/src/web/listener/index.d.ts +3 -0
  209. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  210. package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
  211. package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
  212. package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
  213. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  214. package/lib/typescript/src/web/mock.d.ts +5 -0
  215. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  216. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  217. package/lib/typescript/src/web/pseudo.d.ts +6 -0
  218. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  219. package/lib/typescript/src/web/registry.d.ts +15 -0
  220. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  221. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
  222. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  223. package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
  224. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
  225. package/lib/typescript/{web → src/web}/state.d.ts +4 -9
  226. package/lib/typescript/src/web/state.d.ts.map +1 -0
  227. package/lib/typescript/src/web/utils.d.ts +35 -0
  228. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  229. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  230. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  231. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  232. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  233. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  234. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  235. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -3
  236. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
  237. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
  238. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
  239. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
  240. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -0
  241. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
  242. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
  243. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
  244. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
  245. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  246. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
  247. package/package.json +3 -3
  248. package/plugin/__tests__/dependencies.spec.js +199 -111
  249. package/plugin/__tests__/ref.spec.js +638 -202
  250. package/plugin/__tests__/stylesheet.spec.js +182 -71
  251. package/plugin/index.js +110 -23
  252. package/plugin/ref.js +64 -13
  253. package/plugin/style.js +82 -22
  254. package/plugin/stylesheet.js +44 -1
  255. package/plugin/variants.js +33 -0
  256. package/src/index.ts +3 -0
  257. package/src/specs/NavigtionBar/index.ts +1 -1
  258. package/src/specs/ShadowRegistry/index.ts +10 -9
  259. package/src/specs/StatusBar/index.ts +1 -1
  260. package/src/specs/StyleSheet/index.ts +3 -1
  261. package/src/specs/UnistylesRuntime/index.ts +1 -1
  262. package/src/specs/index.web.ts +1 -1
  263. package/src/types/stylesheet.ts +2 -2
  264. package/{web → src/web}/convert/breakpoint.ts +1 -1
  265. package/{web → src/web}/convert/index.ts +2 -2
  266. package/{web → src/web}/convert/types.ts +1 -1
  267. package/src/web/create.ts +50 -0
  268. package/src/web/createUnistylesComponent.tsx +54 -0
  269. package/{web → src/web}/index.ts +3 -2
  270. package/src/web/listener/index.ts +2 -0
  271. package/src/web/listener/listenToDependencies.ts +45 -0
  272. package/{web → src/web}/listener/listener.ts +2 -2
  273. package/{web → src/web}/mock.ts +2 -12
  274. package/src/web/pseudo.ts +137 -0
  275. package/src/web/registry.ts +60 -0
  276. package/{web → src/web}/runtime.ts +4 -6
  277. package/src/web/shadowRegistry.ts +124 -0
  278. package/{web → src/web}/state.ts +5 -49
  279. package/{web → src/web}/utils.ts +91 -17
  280. package/src/web/variants/getVariants.ts +42 -0
  281. package/src/web/variants/index.ts +2 -0
  282. package/src/web/variants/useVariants.ts +65 -0
  283. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  284. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  285. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  286. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  287. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  288. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  289. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  290. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  291. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  292. package/lib/typescript/web/listener/index.d.ts +0 -2
  293. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  294. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  295. package/lib/typescript/web/mock.d.ts +0 -14
  296. package/lib/typescript/web/mock.d.ts.map +0 -1
  297. package/lib/typescript/web/mq.d.ts.map +0 -1
  298. package/lib/typescript/web/pseudo.d.ts +0 -4
  299. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  300. package/lib/typescript/web/registry.d.ts +0 -12
  301. package/lib/typescript/web/registry.d.ts.map +0 -1
  302. package/lib/typescript/web/runtime.d.ts.map +0 -1
  303. package/lib/typescript/web/state.d.ts.map +0 -1
  304. package/lib/typescript/web/useVariants.d.ts +0 -3
  305. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  306. package/lib/typescript/web/utils.d.ts +0 -18
  307. package/lib/typescript/web/utils.d.ts.map +0 -1
  308. package/web/create.ts +0 -102
  309. package/web/listener/index.ts +0 -1
  310. package/web/pseudo.ts +0 -11
  311. package/web/registry.ts +0 -41
  312. package/web/useVariants.ts +0 -99
  313. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  314. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  315. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  316. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  317. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  318. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  319. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  320. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  321. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  322. /package/{web → src/web}/convert/module.d.ts +0 -0
  323. /package/{web → src/web}/convert/shadow.ts +0 -0
  324. /package/{web → src/web}/convert/style.ts +0 -0
  325. /package/{web → src/web}/convert/textShadow.ts +0 -0
  326. /package/{web → src/web}/convert/transform.ts +0 -0
  327. /package/{web → src/web}/convert/utils.ts +0 -0
  328. /package/{web → src/web}/mq.ts +0 -0
package/Unistyles.podspec CHANGED
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
- s.platforms = { :ios => min_ios_version_supported, :osx => "10.14", :tvos => "9.0", :visionos => "1.0" }
13
+ s.platforms = { :ios => min_ios_version_supported }
14
14
  s.source = { :git => package["repository"], :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = [
@@ -18,7 +18,8 @@ Pod::Spec.new do |s|
18
18
  "cxx/**/*.{h,cpp,hpp}"
19
19
  ]
20
20
  s.pod_target_xcconfig = {
21
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++20"
21
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
22
+ "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES"
22
23
  }
23
24
 
24
25
  s.public_header_files = [
@@ -5,6 +5,9 @@ namespace margelo::nitro::unistyles::helpers {
5
5
  static const std::string UNISTYLES_ID = "__unid";
6
6
  static const std::string ADD_VARIANTS_FN = "useVariants";
7
7
  static const std::string STYLE_DEPENDENCIES = "uni__dependencies";
8
+ static const std::string STYLE_VARIANTS = "uni__variants";
8
9
  static const std::string WEB_STYLE_KEY = "_web";
10
+ static const std::string EXOTIC_STYLE_KEY = "_exotic";
11
+ static const std::string NAME_STYLE_KEY = "__unistyles_name";
9
12
 
10
13
  }
@@ -1,12 +1,16 @@
1
1
  #pragma once
2
2
 
3
3
  #include <jsi/jsi.h>
4
+ #include <jsi/JSIDynamic.h>
5
+ #include <folly/dynamic.h>
4
6
  #include <unordered_set>
5
7
 
6
8
  using namespace facebook;
7
9
 
8
10
  namespace margelo::nitro::unistyles::helpers {
9
11
 
12
+ using Variants = std::vector<std::pair<std::string, std::string>>;
13
+
10
14
  inline void assertThat(jsi::Runtime& rt, bool condition, const std::string& message) {
11
15
  if (!condition) {
12
16
  throw jsi::JSError(rt, message);
@@ -16,11 +20,11 @@ inline void assertThat(jsi::Runtime& rt, bool condition, const std::string& mess
16
20
  inline void enumerateJSIObject(jsi::Runtime& rt, const jsi::Object& obj, std::function<void(const std::string& propertyName, jsi::Value& propertyValue)> callback) {
17
21
  jsi::Array propertyNames = obj.getPropertyNames(rt);
18
22
  size_t length = propertyNames.size(rt);
19
-
23
+
20
24
  for (size_t i = 0; i < length; i++) {
21
25
  auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt).utf8(rt);
22
26
  auto propertyValue = obj.getProperty(rt, propertyName.c_str());
23
-
27
+
24
28
  callback(propertyName, propertyValue);
25
29
  }
26
30
  }
@@ -28,15 +32,15 @@ inline void enumerateJSIObject(jsi::Runtime& rt, const jsi::Object& obj, std::fu
28
32
  template<typename PropertyType>
29
33
  inline bool vecContainsKeys(std::vector<PropertyType>& vec, std::vector<PropertyType>&& keys) {
30
34
  std::unordered_set<PropertyType> availableKeys(keys.begin(), keys.end());
31
-
35
+
32
36
  for (const auto& key : vec) {
33
37
  availableKeys.erase(key);
34
-
38
+
35
39
  if (availableKeys.empty()) {
36
40
  return true;
37
41
  }
38
42
  }
39
-
43
+
40
44
  return false;
41
45
  }
42
46
 
@@ -90,4 +94,92 @@ inline bool isPlatformColor(jsi::Runtime& rt, jsi::Object& maybePlatformColor) {
90
94
  return maybePlatformColor.hasProperty(rt, "resource_paths") && maybePlatformColor.getProperty(rt, "resource_paths").isObject();
91
95
  }
92
96
 
97
+ inline Variants variantsToPairs(jsi::Runtime& rt, jsi::Object&& variants) {
98
+ Variants pairs{};
99
+
100
+ helpers::enumerateJSIObject(rt, variants, [&](const std::string& variantName, jsi::Value& variantValue){
101
+ if (variantValue.isUndefined() || variantValue.isNull()) {
102
+ return;
103
+ }
104
+
105
+ if (variantValue.isBool()) {
106
+ pairs.emplace_back(std::make_pair(variantName, variantValue.asBool() ? "true" : "false"));
107
+
108
+ return;
109
+ }
110
+
111
+ if (variantValue.isString()) {
112
+ pairs.emplace_back(std::make_pair(variantName, variantValue.asString(rt).utf8(rt)));
113
+ }
114
+ });
115
+
116
+ return pairs;
117
+ }
118
+
119
+ inline jsi::Object variantsToValue(jsi::Runtime& rt, Variants& variants) {
120
+ jsi::Object rawVariants = jsi::Object(rt);
121
+
122
+ std::for_each(variants.begin(), variants.end(), [&](std::pair<std::string, std::string>& pair){
123
+ rawVariants.setProperty(rt, pair.first.c_str(), jsi::String::createFromUtf8(rt, pair.second));
124
+ });
125
+
126
+ return rawVariants;
127
+ }
128
+
129
+ inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, jsi::Array& arguments) {
130
+ std::vector<folly::dynamic> parsedArgument{};
131
+ size_t count = arguments.size(rt);
132
+
133
+ parsedArgument.reserve(count);
134
+
135
+ for (size_t i = 0; i < count; i++) {
136
+ jsi::Value arg = arguments.getValueAtIndex(rt, i);
137
+
138
+ if (arg.isBool()) {
139
+ parsedArgument.push_back(folly::dynamic(arg.asBool()));
140
+
141
+ continue;
142
+ }
143
+
144
+ if (arg.isNumber()) {
145
+ parsedArgument.push_back(folly::dynamic(arg.asNumber()));
146
+
147
+ continue;
148
+ }
149
+
150
+ if (arg.isString()) {
151
+ parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
152
+
153
+ continue;
154
+ }
155
+
156
+ if (arg.isUndefined()) {
157
+ parsedArgument.push_back(folly::dynamic());
158
+
159
+ continue;
160
+ }
161
+
162
+ if (arg.isNull()) {
163
+ parsedArgument.push_back(folly::dynamic(nullptr));
164
+
165
+ continue;
166
+ }
167
+
168
+ if (!arg.isObject()) {
169
+ continue;;
170
+ }
171
+
172
+ auto argObj = arg.asObject(rt);
173
+
174
+ // allow arrays and objects too
175
+ if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
176
+ parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
177
+
178
+ continue;
179
+ }
180
+ }
181
+
182
+ return parsedArgument;
183
+ }
184
+
93
185
  }
@@ -7,10 +7,12 @@ using namespace facebook;
7
7
  std::vector<jsi::PropNameID> HostStyle::getPropertyNames(jsi::Runtime& rt) {
8
8
  auto propertyNames = std::vector<jsi::PropNameID> {};
9
9
 
10
+ propertyNames.reserve(8);
11
+
10
12
  for (const auto& pair : this->_styleSheet->unistyles) {
11
13
  propertyNames.emplace_back(jsi::PropNameID::forUtf8(rt, pair.first));
12
14
  }
13
-
15
+
14
16
  return propertyNames;
15
17
  }
16
18
 
@@ -20,15 +22,19 @@ jsi::Value HostStyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId) {
20
22
  if (propertyName == helpers::UNISTYLES_ID) {
21
23
  return jsi::Value(this->_styleSheet->tag);
22
24
  }
23
-
25
+
24
26
  if (propertyName == helpers::ADD_VARIANTS_FN) {
25
27
  return this->createAddVariantsProxyFunction(rt);
26
28
  }
27
29
 
28
30
  if (this->_styleSheet->unistyles.contains(propertyName)) {
29
- return valueFromUnistyle(rt, this->_styleSheet->unistyles[propertyName]);
31
+ return valueFromUnistyle(rt, this->_styleSheet->unistyles[propertyName], this->_styleSheet->tag);
30
32
  }
31
33
 
34
+ if (propertyName == helpers::STYLE_VARIANTS) {
35
+ return helpers::variantsToValue(rt, this->_variants);
36
+ }
37
+
32
38
  return jsi::Value::undefined();
33
39
  }
34
40
 
@@ -36,20 +42,20 @@ jsi::Function HostStyle::createAddVariantsProxyFunction(jsi::Runtime& rt) {
36
42
  auto useVariantsFnName = jsi::PropNameID::forUtf8(rt, helpers::ADD_VARIANTS_FN);
37
43
 
38
44
  return jsi::Function::createFromHostFunction(rt, useVariantsFnName, 1, [&](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count){
39
- helpers::assertThat(rt, count == 1, "useVariants expected to be called with one argument.");
40
- helpers::assertThat(rt, arguments[0].isObject(), "useVariants expected to be called with object.");
45
+ helpers::assertThat(rt, count == 1, "Unistyles: useVariants expected to be called with one argument.");
46
+ helpers::assertThat(rt, arguments[0].isObject(), "Unistyles: useVariants expected to be called with object.");
41
47
 
42
48
  auto parser = parser::Parser(this->_unistylesRuntime);
43
- auto pairs = parser.variantsToPairs(rt, arguments[0].asObject(rt));
44
-
45
- if (pairs == this->_styleSheet->variants) {
49
+ auto pairs = helpers::variantsToPairs(rt, arguments[0].asObject(rt));
50
+
51
+ if (pairs == this->_variants) {
46
52
  return jsi::Value::undefined();
47
53
  }
48
-
49
- this->_styleSheet->variants = pairs;
50
-
51
- parser.rebuildUnistylesWithVariants(rt, this->_styleSheet);
52
-
54
+
55
+ this->_variants = pairs;
56
+
57
+ parser.rebuildUnistylesWithVariants(rt, this->_styleSheet, this->_variants);
58
+
53
59
  return jsi::Value::undefined();
54
60
  });
55
61
  }
@@ -4,10 +4,13 @@
4
4
  #include "StyleSheet.h"
5
5
  #include "Constants.h"
6
6
  #include "Parser.h"
7
+ #include "UnistyleWrapper.h"
7
8
  #include "HybridUnistylesRuntime.h"
8
9
 
9
10
  namespace margelo::nitro::unistyles::core {
10
11
 
12
+ using Variants = std::vector<std::pair<std::string, std::string>>;
13
+
11
14
  struct JSI_EXPORT HostStyle : public jsi::HostObject {
12
15
  HostStyle(std::shared_ptr<StyleSheet> styleSheet, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
13
16
  : _styleSheet{styleSheet}, _unistylesRuntime{unistylesRuntime} {};
@@ -20,6 +23,7 @@ struct JSI_EXPORT HostStyle : public jsi::HostObject {
20
23
  private:
21
24
  std::shared_ptr<StyleSheet> _styleSheet;
22
25
  std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
26
+ std::vector<std::pair<std::string, std::string>> _variants{};
23
27
  };
24
28
 
25
29
  }
@@ -2,7 +2,6 @@
2
2
 
3
3
  #include <jsi/jsi.h>
4
4
  #include "Unistyle.h"
5
- #include "UnistyleWrapper.h"
6
5
  #include "Helpers.h"
7
6
  #include "Constants.h"
8
7
 
@@ -26,7 +25,6 @@ struct StyleSheet {
26
25
  StyleSheetType type;
27
26
  jsi::Object rawValue;
28
27
  std::unordered_map<std::string, Unistyle::Shared> unistyles{};
29
- std::vector<std::pair<std::string, std::string>> variants{};
30
28
  };
31
29
 
32
30
  }
@@ -4,20 +4,18 @@
4
4
  using namespace margelo::nitro::unistyles::core;
5
5
  using namespace facebook;
6
6
 
7
- std::shared_ptr<StyleSheet> StyleSheetRegistry::addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet) {
8
- static unsigned int tag = 0;
9
-
7
+ std::shared_ptr<StyleSheet> StyleSheetRegistry::addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet, int unid) {
10
8
  if (rawStyleSheet.isFunction(rt)) {
11
- return this->addFromFunction(rt, ++tag, rawStyleSheet.asFunction(rt));
9
+ return this->addFromFunction(rt, unid, rawStyleSheet.asFunction(rt));
12
10
  }
13
11
 
14
- return this->addFromObject(rt, ++tag, std::move(rawStyleSheet));
12
+ return this->addFromObject(rt, unid, std::move(rawStyleSheet));
15
13
  }
16
14
 
17
- std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt, unsigned int tag, jsi::Function styleSheetFn) {
15
+ std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt, int unid, jsi::Function styleSheetFn) {
18
16
  auto numberOfArgs = styleSheetFn.getProperty(rt, "length").getNumber();
19
17
 
20
- helpers::assertThat(rt, numberOfArgs <= 2, "expected up to 2 arguments.");
18
+ helpers::assertThat(rt, numberOfArgs <= 2, "StyleSheet.create expected up to 2 arguments.");
21
19
 
22
20
  auto& registry = UnistylesRegistry::get();
23
21
 
@@ -25,21 +23,20 @@ std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt
25
23
  if (numberOfArgs == 0) {
26
24
  auto staticStyleSheet = styleSheetFn.call(rt).asObject(rt);
27
25
 
28
- return registry.addStyleSheet(tag, core::StyleSheetType::Static, std::move(staticStyleSheet));
26
+ return registry.addStyleSheet(rt, unid, core::StyleSheetType::Static, std::move(staticStyleSheet));
29
27
  }
30
28
 
31
29
  // stylesheet depends only on theme
32
30
  if (numberOfArgs == 1) {
33
- return registry.addStyleSheet(tag, core::StyleSheetType::Themable, std::move(styleSheetFn));
31
+ return registry.addStyleSheet(rt, unid, core::StyleSheetType::Themable, std::move(styleSheetFn));
34
32
  }
35
33
 
36
34
  // stylesheet depends on theme and mini runtime
37
- return registry.addStyleSheet(tag, core::StyleSheetType::ThemableWithMiniRuntime, std::move(styleSheetFn));
35
+ return registry.addStyleSheet(rt, unid, core::StyleSheetType::ThemableWithMiniRuntime, std::move(styleSheetFn));
38
36
  }
39
37
 
40
- std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromObject(jsi::Runtime& rt, unsigned int tag, jsi::Object rawStyleSheet) {
38
+ std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromObject(jsi::Runtime& rt, int tag, jsi::Object rawStyleSheet) {
41
39
  auto& registry = UnistylesRegistry::get();
42
40
 
43
- return registry.addStyleSheet(tag, core::StyleSheetType::Static, std::move(rawStyleSheet));
41
+ return registry.addStyleSheet(rt, tag, core::StyleSheetType::Static, std::move(rawStyleSheet));
44
42
  }
45
-
@@ -16,11 +16,11 @@ struct StyleSheetRegistry {
16
16
  StyleSheetRegistry(const StyleSheetRegistry&) = delete;
17
17
  StyleSheetRegistry(StyleSheetRegistry&&) = delete;
18
18
 
19
- virtual std::shared_ptr<StyleSheet> addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet);
20
-
19
+ virtual std::shared_ptr<StyleSheet> addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet, int unid);
20
+
21
21
  private:
22
- virtual std::shared_ptr<StyleSheet> addFromFunction(jsi::Runtime& rt, unsigned int tag, jsi::Function styleSheetFn);
23
- virtual std::shared_ptr<StyleSheet> addFromObject(jsi::Runtime& rt, unsigned int tag, jsi::Object rawStyleSheet);
22
+ virtual std::shared_ptr<StyleSheet> addFromFunction(jsi::Runtime& rt, int unid, jsi::Function styleSheetFn);
23
+ virtual std::shared_ptr<StyleSheet> addFromObject(jsi::Runtime& rt, int unid, jsi::Object rawStyleSheet);
24
24
  };
25
25
 
26
26
  }
@@ -7,6 +7,8 @@
7
7
 
8
8
  namespace margelo::nitro::unistyles::core {
9
9
 
10
+ class StyleSheet;
11
+
10
12
  using namespace facebook;
11
13
 
12
14
  enum class UnistyleType {
@@ -14,16 +16,11 @@ enum class UnistyleType {
14
16
  DynamicFunction
15
17
  };
16
18
 
17
- struct DynamicFunctionMetadata {
18
- size_t count;
19
- std::vector<folly::dynamic> arguments;
20
- };
21
-
22
19
  struct Unistyle {
23
20
  using Shared = std::shared_ptr<Unistyle>;
24
21
 
25
- Unistyle(UnistyleType type, std::string styleKey, jsi::Object& rawObject)
26
- : styleKey{styleKey}, type{type}, rawValue{std::move(rawObject)} {}
22
+ Unistyle(UnistyleType type, std::string styleKey, jsi::Object& rawObject, std::shared_ptr<StyleSheet> styleSheet)
23
+ : styleKey{styleKey}, type{type}, rawValue{std::move(rawObject)}, parent{styleSheet} {}
27
24
  virtual ~Unistyle() = default;
28
25
 
29
26
  Unistyle(const Unistyle&) = delete;
@@ -34,6 +31,7 @@ struct Unistyle {
34
31
  jsi::Object rawValue;
35
32
  std::optional<jsi::Object> parsedStyle;
36
33
  std::vector<UnistyleDependency> dependencies{};
34
+ std::shared_ptr<StyleSheet> parent;
37
35
 
38
36
  inline void addDependency(UnistyleDependency dependency) {
39
37
  // we can't add dependencies if unistyle is sealed
@@ -67,15 +65,14 @@ struct UnistyleDynamicFunction: public Unistyle {
67
65
  // unprocessedValue <- object generated after calling proxy and user's original function
68
66
  // parsedStyle <- parsed with Unistyle's parser
69
67
 
70
- UnistyleDynamicFunction(UnistyleType type, std::string styleKey, jsi::Object& rawObject)
71
- : Unistyle(type, styleKey, rawObject) {}
68
+ UnistyleDynamicFunction(UnistyleType type, std::string styleKey, jsi::Object& rawObject, std::shared_ptr<StyleSheet> styleSheet)
69
+ : Unistyle(type, styleKey, rawObject, styleSheet) {}
72
70
 
73
71
  UnistyleDynamicFunction(const UnistyleDynamicFunction&) = delete;
74
72
  UnistyleDynamicFunction(UnistyleDynamicFunction&& other) = delete;
75
73
 
76
74
  std::optional<jsi::Object> unprocessedValue;
77
75
  std::optional<jsi::Function> proxiedFunction = std::nullopt;
78
- std::optional<DynamicFunctionMetadata> dynamicFunctionMetadata = std::nullopt;
79
76
  };
80
77
 
81
78
  }
@@ -0,0 +1,23 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include "Unistyle.h"
5
+
6
+ namespace margelo::nitro::unistyles::core {
7
+
8
+ using Variants = std::vector<std::pair<std::string, std::string>>;
9
+
10
+ struct UnistyleData {
11
+ UnistyleData(Unistyle::Shared unistyle, const Variants& variants, std::vector<folly::dynamic>& arguments)
12
+ : unistyle{unistyle}, variants(std::move(variants)), dynamicFunctionMetadata{std::move(arguments)} {}
13
+
14
+ UnistyleData(const UnistyleData&) = delete;
15
+ UnistyleData(UnistyleData&& other): unistyle{other.unistyle}, variants(std::move(other.variants)) {}
16
+
17
+ core::Unistyle::Shared unistyle;
18
+ core::Variants variants;
19
+ std::optional<jsi::Object> parsedStyle = std::nullopt;
20
+ std::optional<std::vector<folly::dynamic>> dynamicFunctionMetadata = std::nullopt;
21
+ };
22
+
23
+ }
@@ -2,6 +2,7 @@
2
2
 
3
3
  #include <jsi/jsi.h>
4
4
  #include "Unistyle.h"
5
+ #include "UnistylesRegistry.h"
5
6
  #include "Helpers.h"
6
7
  #include "Constants.h"
7
8
 
@@ -16,33 +17,80 @@ struct UnistyleWrapper: public jsi::NativeState {
16
17
  Unistyle::Shared unistyle;
17
18
  };
18
19
 
19
- inline static Unistyle::Shared unistyleFromValue(jsi::Runtime& rt, const jsi::Value& value) {
20
+ inline static Unistyle::Shared unistyleFromStaticStyleSheet(jsi::Runtime& rt, jsi::Object& value) {
21
+ auto exoticUnistyle = std::make_shared<Unistyle>(
22
+ UnistyleType::Object,
23
+ helpers::EXOTIC_STYLE_KEY,
24
+ value,
25
+ nullptr
26
+ );
27
+
28
+ exoticUnistyle->seal();
29
+
30
+ return exoticUnistyle;
31
+ }
32
+
33
+
34
+ inline static std::vector<Unistyle::Shared> unistylesFromNonExistentNativeState(jsi::Runtime& rt, jsi::Object& value) {
35
+ auto hasUnistyleName = value.hasProperty(rt, helpers::NAME_STYLE_KEY.c_str());
36
+
37
+ // return wrapped RN/inline style
38
+ if (!hasUnistyleName) {
39
+ return {unistyleFromStaticStyleSheet(rt, value)};
40
+ }
41
+
42
+ throw jsi::JSError(rt, R"(Unistyles: Style is not bound!
43
+
44
+ Potential reasons:
45
+ - You likely used the spread operator on a Unistyle style outside of a JSX component
46
+
47
+ If you need to merge styles, do it within the style prop of your JSX component:
48
+
49
+ style={{...styles.container, ...styles.otherProp}}
50
+ or
51
+ style={[styles.container, styles.otherProp]}
52
+
53
+ If you pass computed style prop to component use array syntax:
54
+
55
+ customStyleProp={[styles.container, styles.otherProp]}
56
+
57
+ Copying a Unistyle style outside of a JSX element will remove its internal C++ state, leading to unexpected behavior.)");
58
+ }
59
+
60
+ inline static std::vector<Unistyle::Shared> unistyleFromValue(jsi::Runtime& rt, const jsi::Value& value) {
20
61
  if (value.isNull()) {
21
- return nullptr;
62
+ return {};
22
63
  }
23
64
 
24
- return value.getObject(rt).getNativeState<UnistyleWrapper>(rt)->unistyle;
65
+ auto obj = value.getObject(rt);
66
+
67
+ // possible if user used React Native styles or inline styles or did spread styles
68
+ if (!obj.hasNativeState(rt)) {
69
+ return unistylesFromNonExistentNativeState(rt, obj);
70
+ }
71
+
72
+ return {value.getObject(rt).getNativeState<UnistyleWrapper>(rt)->unistyle};
25
73
  }
26
74
 
27
- inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle) {
75
+ inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle, int tag) {
28
76
  auto wrappedUnistyle = std::make_shared<UnistyleWrapper>(unistyle);
29
-
77
+
30
78
  if (unistyle->type == UnistyleType::Object) {
31
79
  jsi::Object obj = jsi::Object(rt);
32
-
80
+
33
81
  obj.setNativeState(rt, std::move(wrappedUnistyle));
34
- helpers::defineHiddenProperty(rt, obj, helpers::UNISTYLES_ID.c_str(), unistyle->styleKey);
82
+ obj.setProperty(rt, helpers::NAME_STYLE_KEY.c_str(), jsi::String::createFromUtf8(rt, unistyle->styleKey));
35
83
 
36
84
  helpers::mergeJSIObjects(rt, obj, unistyle->parsedStyle.value());
37
-
85
+
38
86
  return obj;
39
87
  }
40
-
88
+
41
89
  auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
42
90
  auto hostFn = jsi::Value(rt, unistyleFn->proxiedFunction.value()).asObject(rt).asFunction(rt);
43
91
 
44
92
  hostFn.setNativeState(rt, std::move(wrappedUnistyle));
45
- hostFn.setProperty(rt, helpers::UNISTYLES_ID.c_str(), unistyleFn->styleKey);
93
+ hostFn.setProperty(rt, helpers::NAME_STYLE_KEY.c_str(), jsi::String::createFromUtf8(rt, unistyleFn->styleKey));
46
94
 
47
95
  return std::move(hostFn);
48
96
  }
@@ -3,12 +3,9 @@
3
3
  using namespace margelo::nitro::unistyles;
4
4
  using namespace facebook::react;
5
5
 
6
- core::UnistylesCommitHook::UnistylesCommitHook(UIManager& uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
7
- : _unistylesRuntime{unistylesRuntime} {
8
- uiManager.registerCommitHook(*this);
9
- };
10
-
11
- core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {}
6
+ core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {
7
+ _uiManager->unregisterCommitHook(*this);
8
+ }
12
9
 
13
10
  void core::UnistylesCommitHook::commitHookWasRegistered(const UIManager &uiManager) noexcept {}
14
11
  void core::UnistylesCommitHook::commitHookWasUnregistered(const UIManager &uiManager) noexcept {}
@@ -20,24 +17,34 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
20
17
  ) noexcept {
21
18
  RootShadowNode::Unshared rootNode = newRootShadowNode;
22
19
  auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootShadowNode);
23
-
20
+
24
21
  // skip only unistyles commits
25
22
  if (unistylesRootNode->hasUnistylesCommitTrait()) {
26
23
  unistylesRootNode->removeUnistylesCommitTrait();
27
-
24
+ unistylesRootNode->addUnistylesMountTrait();
25
+
26
+ return newRootShadowNode;
27
+ }
28
+
29
+ auto& registry = core::UnistylesRegistry::get();
30
+
31
+ if (!registry.trafficController.hasUnistylesCommit()) {
28
32
  return newRootShadowNode;
29
33
  }
30
34
 
31
35
  auto shadowLeafUpdates = this->getUnistylesUpdates();
32
-
36
+
33
37
  if (shadowLeafUpdates.size() == 0) {
34
38
  return newRootShadowNode;
35
39
  }
36
-
40
+
41
+ // this is required, otherwise we end up with old shadow tree in mount hook
42
+ registry.trafficController.stopUnistylesTraffic();
43
+
37
44
  auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
38
45
 
39
46
  return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
40
- this->_unistylesRuntime->getRuntime(),
47
+ *this->_rt,
41
48
  *rootNode,
42
49
  shadowLeafUpdates,
43
50
  affectedNodes
@@ -47,7 +54,9 @@ RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
47
54
  shadow::ShadowLeafUpdates core::UnistylesCommitHook::getUnistylesUpdates() {
48
55
  auto& registry = core::UnistylesRegistry::get();
49
56
  auto parser = parser::Parser(this->_unistylesRuntime);
50
- auto dependencyMap = registry.buildDependencyMap();
51
-
57
+ auto dependencyMap = registry.buildDependencyMap(*this->_rt);
58
+
59
+ // don't rebuild dependency map, at this point it's already done
60
+
52
61
  return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
53
62
  }
@@ -5,13 +5,18 @@
5
5
  #include "HybridUnistylesRuntime.h"
6
6
  #include "Parser.h"
7
7
  #include "ShadowTreeManager.h"
8
+ #include "ShadowTrafficController.h"
8
9
 
9
10
  namespace margelo::nitro::unistyles::core {
10
11
 
11
12
  using namespace facebook::react;
12
13
 
13
14
  struct UnistylesCommitHook : public UIManagerCommitHook {
14
- UnistylesCommitHook(UIManager& uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime);
15
+ UnistylesCommitHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, jsi::Runtime& rt)
16
+ : _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager}, _rt{&rt} {
17
+ _uiManager->registerCommitHook(*this);
18
+ }
19
+
15
20
  ~UnistylesCommitHook() noexcept override;
16
21
 
17
22
  void commitHookWasRegistered(const UIManager &uiManager) noexcept override;
@@ -22,6 +27,8 @@ struct UnistylesCommitHook : public UIManagerCommitHook {
22
27
 
23
28
  private:
24
29
  std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
30
+ std::shared_ptr<UIManager> _uiManager;
31
+ jsi::Runtime* _rt;
25
32
  };
26
33
 
27
34
  }
@@ -8,6 +8,7 @@ namespace margelo::nitro::unistyles::core {
8
8
  // React Native uses 0-10
9
9
  // Reanimated uses 27-28
10
10
  constexpr shadow::ShadowNodeTraits::Trait UnistylesCommitTrait{1 << 30};
11
+ constexpr shadow::ShadowNodeTraits::Trait UnistylesMountTrait{1 << 31};
11
12
 
12
13
  struct UnistylesCommitShadowNode: public shadow::ShadowNode {
13
14
  inline void addUnistylesCommitTrait() {
@@ -21,6 +22,18 @@ struct UnistylesCommitShadowNode: public shadow::ShadowNode {
21
22
  inline bool hasUnistylesCommitTrait() {
22
23
  return traits_.check(UnistylesCommitTrait);
23
24
  }
25
+
26
+ inline void addUnistylesMountTrait() {
27
+ traits_.set(UnistylesMountTrait);
28
+ }
29
+
30
+ inline void removeUnistylesMountTrait() {
31
+ traits_.unset(UnistylesMountTrait);
32
+ }
33
+
34
+ inline bool hasUnistylesMountTrait() {
35
+ return traits_.check(UnistylesMountTrait);
36
+ }
24
37
  };
25
38
 
26
39
  }