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
@@ -14,9 +14,9 @@ pluginTester({
14
14
  },
15
15
  tests: [
16
16
  {
17
- title: 'Does nothing if there is no import from Unistyles',
17
+ title: 'Does nothing if there is no import from React Native',
18
18
  code: `
19
- import { StyleSheet } from 'react-native'
19
+ import { StyleSheet, View, Text } from 'custom-lib'
20
20
 
21
21
  export const Example = () => {
22
22
  return (
@@ -33,7 +33,7 @@ pluginTester({
33
33
  })
34
34
  `,
35
35
  output: `
36
- import { StyleSheet } from 'react-native'
36
+ import { StyleSheet, View, Text } from 'custom-lib'
37
37
 
38
38
  export const Example = () => {
39
39
  return (
@@ -51,9 +51,9 @@ pluginTester({
51
51
  `
52
52
  },
53
53
  {
54
- title: 'Adds ref if there is any import from Unistyles',
54
+ title: 'Adds ref if there is any import from React Native',
55
55
  code: `
56
- import 'react-native-unistyles'
56
+ import { View, Text } from 'react-native'
57
57
 
58
58
  export const Example = () => {
59
59
  return (
@@ -71,15 +71,15 @@ pluginTester({
71
71
  `,
72
72
  output: `
73
73
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
74
- import 'react-native-unistyles'
74
+ import { View, Text } from 'react-native'
75
75
 
76
76
  export const Example = () => {
77
77
  return (
78
78
  <View
79
- style={styles.container}
79
+ style={[styles.container]}
80
80
  ref={ref => {
81
- UnistylesShadowRegistry.add(ref, styles.container)
82
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
81
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
82
+ return () => UnistylesShadowRegistry.remove(ref)
83
83
  }}
84
84
  >
85
85
  <Text>Hello world</Text>
@@ -94,10 +94,63 @@ pluginTester({
94
94
  })
95
95
  `
96
96
  },
97
+ {
98
+ title: 'Adds ref only for React Native components',
99
+ code: `
100
+ import { View } from 'react-native'
101
+ import { Text } from 'custom-lib'
102
+
103
+ export const Example = () => {
104
+ return (
105
+ <View style={styles.container}>
106
+ <Text style={styles.text}>Hello world</Text>
107
+ </View>
108
+ )
109
+ }
110
+
111
+ const styles = StyleSheet.create({
112
+ container: {
113
+ backgroundColor: 'red'
114
+ },
115
+ text: {
116
+ color: 'blue'
117
+ }
118
+ })
119
+ `,
120
+ output: `
121
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
122
+ import { View } from 'react-native'
123
+ import { Text } from 'custom-lib'
124
+
125
+ export const Example = () => {
126
+ return (
127
+ <View
128
+ style={[styles.container]}
129
+ ref={ref => {
130
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
131
+ return () => UnistylesShadowRegistry.remove(ref)
132
+ }}
133
+ >
134
+ <Text style={styles.text}>Hello world</Text>
135
+ </View>
136
+ )
137
+ }
138
+
139
+ const styles = StyleSheet.create({
140
+ container: {
141
+ backgroundColor: 'red'
142
+ },
143
+ text: {
144
+ color: 'blue'
145
+ }
146
+ })
147
+ `
148
+ },
97
149
  {
98
150
  title: 'Preserves user\'s ref',
99
151
  code: `
100
152
  import React from 'react'
153
+ import { View, Text } from 'react-native'
101
154
  import { StyleSheet } from 'react-native-unistyles'
102
155
 
103
156
  export const Example = () => {
@@ -122,6 +175,7 @@ pluginTester({
122
175
  output: `
123
176
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
124
177
  import React from 'react'
178
+ import { View, Text } from 'react-native'
125
179
  import { StyleSheet } from 'react-native-unistyles'
126
180
 
127
181
  export const Example = () => {
@@ -130,38 +184,42 @@ pluginTester({
130
184
  return (
131
185
  <View
132
186
  ref={_ref => {
133
- ref = _ref
134
- UnistylesShadowRegistry.add(_ref, styles.container)
135
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
187
+ ref.current = _ref
188
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
189
+ return () => UnistylesShadowRegistry.remove(_ref)
136
190
  }}
137
- style={styles.container}
191
+ style={[styles.container]}
138
192
  >
139
193
  <Text>Hello world</Text>
140
194
  </View>
141
195
  )
142
196
  }
143
197
 
144
- const styles = StyleSheet.create({
145
- container: {
146
- backgroundColor: 'red'
147
- }
148
- })
198
+ const styles = StyleSheet.create(
199
+ {
200
+ container: {
201
+ backgroundColor: 'red'
202
+ }
203
+ },
204
+ 921918562
205
+ )
149
206
  `
150
207
  },
151
208
  {
152
209
  title: 'Preserves user\'s ref as function',
153
210
  code: `
154
211
  import { useRef } from 'react'
212
+ import { View, Text } from 'react-native'
155
213
  import { StyleSheet } from 'react-native-unistyles'
156
214
 
157
215
  export const Example = () => {
158
- let myRef = useRef()
216
+ const myRef = useRef()
159
217
 
160
218
  return (
161
219
  <View
162
220
  ref={ref => {
163
221
  doSomething(ref)
164
- myRef = ref
222
+ myRef.current = ref
165
223
  }}
166
224
  style={styles.container}
167
225
  >
@@ -179,49 +237,54 @@ pluginTester({
179
237
  output: `
180
238
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
181
239
  import { useRef } from 'react'
240
+ import { View, Text } from 'react-native'
182
241
  import { StyleSheet } from 'react-native-unistyles'
183
242
 
184
243
  export const Example = () => {
185
- let myRef = useRef()
244
+ const myRef = useRef()
186
245
 
187
246
  return (
188
247
  <View
189
248
  ref={ref => {
190
249
  doSomething(ref)
191
- myRef = ref
192
- UnistylesShadowRegistry.add(ref, styles.container)
250
+ myRef.current = ref
251
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
193
252
  return () => {
194
- UnistylesShadowRegistry.remove(ref, styles.container)
253
+ UnistylesShadowRegistry.remove(ref)
195
254
  }
196
255
  }}
197
- style={styles.container}
256
+ style={[styles.container]}
198
257
  >
199
258
  <Text>Hello world</Text>
200
259
  </View>
201
260
  )
202
261
  }
203
262
 
204
- const styles = StyleSheet.create({
205
- container: {
206
- backgroundColor: 'red'
207
- }
208
- })
263
+ const styles = StyleSheet.create(
264
+ {
265
+ container: {
266
+ backgroundColor: 'red'
267
+ }
268
+ },
269
+ 921918562
270
+ )
209
271
  `
210
272
  },
211
273
  {
212
274
  title: 'Preserves user\'s ref as function with cleanup',
213
275
  code: `
214
276
  import React from 'react'
277
+ import { View, Text } from 'react-native'
215
278
  import { StyleSheet } from 'react-native-unistyles'
216
279
 
217
280
  export const Example = () => {
218
- let myRef = React.useRef()
281
+ const myRef = React.useRef()
219
282
 
220
283
  return (
221
284
  <View
222
285
  ref={ref => {
223
286
  doSomething(ref)
224
- myRef = ref
287
+ myRef.current = ref
225
288
 
226
289
  return () => {
227
290
  customCleanup()
@@ -243,49 +306,54 @@ pluginTester({
243
306
  output: `
244
307
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
245
308
  import React from 'react'
309
+ import { View, Text } from 'react-native'
246
310
  import { StyleSheet } from 'react-native-unistyles'
247
311
 
248
312
  export const Example = () => {
249
- let myRef = React.useRef()
313
+ const myRef = React.useRef()
250
314
 
251
315
  return (
252
316
  <View
253
317
  ref={ref => {
254
318
  doSomething(ref)
255
- myRef = ref
256
- UnistylesShadowRegistry.add(ref, styles.container)
319
+ myRef.current = ref
320
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
257
321
  return () => {
258
322
  ;(() => {
259
323
  customCleanup()
260
324
  })()
261
- UnistylesShadowRegistry.remove(ref, styles.container)
325
+ UnistylesShadowRegistry.remove(ref)
262
326
  }
263
327
  }}
264
- style={styles.container}
328
+ style={[styles.container]}
265
329
  >
266
330
  <Text>Hello world</Text>
267
331
  </View>
268
332
  )
269
333
  }
270
334
 
271
- const styles = StyleSheet.create({
272
- container: {
273
- backgroundColor: 'red'
274
- }
275
- })
335
+ const styles = StyleSheet.create(
336
+ {
337
+ container: {
338
+ backgroundColor: 'red'
339
+ }
340
+ },
341
+ 921918562
342
+ )
276
343
  `
277
344
  },
278
345
  {
279
346
  title: 'Preserves user\'s ref as assigned arrow function',
280
347
  code: `
281
348
  import React from 'react'
349
+ import { View, Text } from 'react-native'
282
350
  import { StyleSheet } from 'react-native-unistyles'
283
351
 
284
352
  export const Example = () => {
285
- let myRef = React.useRef()
353
+ const myRef = React.useRef()
286
354
  const fn = ref => {
287
355
  doSomething(ref)
288
- myRef = ref
356
+ myRef.current = ref
289
357
 
290
358
  return () => {
291
359
  customCleanup2()
@@ -311,52 +379,57 @@ pluginTester({
311
379
  output: `
312
380
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
313
381
  import React from 'react'
382
+ import { View, Text } from 'react-native'
314
383
  import { StyleSheet } from 'react-native-unistyles'
315
384
 
316
385
  export const Example = () => {
317
- let myRef = React.useRef()
386
+ const myRef = React.useRef()
318
387
  const fn = ref => {
319
388
  doSomething(ref)
320
- myRef = ref
389
+ myRef.current = ref
321
390
  }
322
391
 
323
392
  return (
324
393
  <View
325
394
  ref={_ref => {
326
395
  fn(_ref)
327
- UnistylesShadowRegistry.add(_ref, styles.container)
396
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
328
397
  return () => {
329
398
  ;(() => {
330
399
  customCleanup2()
331
400
  })()
332
- UnistylesShadowRegistry.remove(_ref, styles.container)
401
+ UnistylesShadowRegistry.remove(_ref)
333
402
  }
334
403
  }}
335
- style={styles.container}
404
+ style={[styles.container]}
336
405
  >
337
406
  <Text>Hello world</Text>
338
407
  </View>
339
408
  )
340
409
  }
341
410
 
342
- const styles = StyleSheet.create({
343
- container: {
344
- backgroundColor: 'red'
345
- }
346
- })
411
+ const styles = StyleSheet.create(
412
+ {
413
+ container: {
414
+ backgroundColor: 'red'
415
+ }
416
+ },
417
+ 921918562
418
+ )
347
419
  `
348
420
  },
349
421
  {
350
422
  title: 'Preserves user\'s ref as assigned function function',
351
423
  code: `
352
424
  import React from 'react'
425
+ import { View, Text } from 'react-native'
353
426
  import { StyleSheet } from 'react-native-unistyles'
354
427
 
355
428
  export const Example = () => {
356
- let myRef = React.useRef()
429
+ const myRef = React.useRef()
357
430
  function fn(ref) {
358
431
  doSomething(ref)
359
- myRef = ref
432
+ myRef.current = ref
360
433
 
361
434
  return () => {
362
435
  customCleanup2()
@@ -382,49 +455,54 @@ pluginTester({
382
455
  output: `
383
456
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
384
457
  import React from 'react'
458
+ import { View, Text } from 'react-native'
385
459
  import { StyleSheet } from 'react-native-unistyles'
386
460
 
387
461
  export const Example = () => {
388
- let myRef = React.useRef()
462
+ const myRef = React.useRef()
389
463
  function fn(ref) {
390
464
  doSomething(ref)
391
- myRef = ref
465
+ myRef.current = ref
392
466
  }
393
467
 
394
468
  return (
395
469
  <View
396
470
  ref={_ref => {
397
471
  fn(_ref)
398
- UnistylesShadowRegistry.add(_ref, styles.container)
472
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
399
473
  return () => {
400
474
  ;(() => {
401
475
  customCleanup2()
402
476
  })()
403
- UnistylesShadowRegistry.remove(_ref, styles.container)
477
+ UnistylesShadowRegistry.remove(_ref)
404
478
  }
405
479
  }}
406
- style={styles.container}
480
+ style={[styles.container]}
407
481
  >
408
482
  <Text>Hello world</Text>
409
483
  </View>
410
484
  )
411
485
  }
412
486
 
413
- const styles = StyleSheet.create({
414
- container: {
415
- backgroundColor: 'red'
416
- }
417
- })
487
+ const styles = StyleSheet.create(
488
+ {
489
+ container: {
490
+ backgroundColor: 'red'
491
+ }
492
+ },
493
+ 921918562
494
+ )
418
495
  `
419
496
  },
420
497
  {
421
498
  title: 'Should not modify ref if user is using inline styles',
422
499
  code: `
423
500
  import { useRef } from 'react'
501
+ import { View, Text } from 'react-native'
424
502
  import { StyleSheet } from 'react-native-unistyles'
425
503
 
426
504
  export const Example = () => {
427
- let myRef = useRef()
505
+ const myRef = useRef()
428
506
 
429
507
  return (
430
508
  <View
@@ -445,39 +523,54 @@ pluginTester({
445
523
  })
446
524
  `,
447
525
  output: `
526
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
448
527
  import { useRef } from 'react'
528
+ import { View, Text } from 'react-native'
449
529
  import { StyleSheet } from 'react-native-unistyles'
450
530
 
451
531
  export const Example = () => {
452
- let myRef = useRef()
532
+ const myRef = useRef()
453
533
 
454
534
  return (
455
535
  <View
456
- ref={myRef}
457
- style={{
458
- backgroundColor: 'red'
536
+ ref={_ref => {
537
+ myRef.current = _ref
538
+ UnistylesShadowRegistry.add(
539
+ _ref,
540
+ {
541
+ backgroundColor: 'red'
542
+ },
543
+ undefined,
544
+ undefined
545
+ )
546
+ return () => UnistylesShadowRegistry.remove(_ref)
459
547
  }}
548
+ style={[{ backgroundColor: 'red' }]}
460
549
  >
461
550
  <Text>Hello world</Text>
462
551
  </View>
463
552
  )
464
553
  }
465
554
 
466
- const styles = StyleSheet.create({
467
- container: {
468
- backgroundColor: 'red'
469
- }
470
- })
555
+ const styles = StyleSheet.create(
556
+ {
557
+ container: {
558
+ backgroundColor: 'red'
559
+ }
560
+ },
561
+ 921918562
562
+ )
471
563
  `
472
564
  },
473
565
  {
474
- title: 'Should not modify ref if user is not member accessing styles',
566
+ title: 'Should modify ref if user is not member accessing styles',
475
567
  code: `
476
568
  import { useRef } from 'react'
569
+ import { View, Text } from 'react-native'
477
570
  import { StyleSheet } from 'react-native-unistyles'
478
571
 
479
572
  export const Example = () => {
480
- let myRef = useRef()
573
+ const myRef = useRef()
481
574
 
482
575
  return (
483
576
  <View
@@ -499,40 +592,51 @@ pluginTester({
499
592
  })
500
593
  `,
501
594
  output: `
595
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
502
596
  import { useRef } from 'react'
597
+ import { View, Text } from 'react-native'
503
598
  import { StyleSheet } from 'react-native-unistyles'
504
599
 
505
600
  export const Example = () => {
506
- let myRef = useRef()
601
+ const myRef = useRef()
507
602
 
508
603
  return (
509
604
  <View
510
- ref={myRef}
511
- style={{
512
- ...obj1,
513
- ...obj2
605
+ ref={_ref => {
606
+ myRef.current = _ref
607
+ UnistylesShadowRegistry.add(_ref, obj1, undefined, undefined)
608
+ UnistylesShadowRegistry.add(_ref, obj2, undefined, undefined)
609
+ return () => {
610
+ ;(() => UnistylesShadowRegistry.remove(_ref))()
611
+ UnistylesShadowRegistry.remove(_ref)
612
+ }
514
613
  }}
614
+ style={[obj1, obj2]}
515
615
  >
516
616
  <Text>Hello world</Text>
517
617
  </View>
518
618
  )
519
619
  }
520
620
 
521
- const styles = StyleSheet.create({
522
- container: {
523
- backgroundColor: 'red'
524
- }
525
- })
621
+ const styles = StyleSheet.create(
622
+ {
623
+ container: {
624
+ backgroundColor: 'red'
625
+ }
626
+ },
627
+ 921918562
628
+ )
526
629
  `
527
630
  },
528
631
  {
529
- title: 'Should not modify ref if user is not member accessing styles in array',
632
+ title: 'Should modify ref if user is not member accessing styles in array',
530
633
  code: `
531
634
  import { useRef } from 'react'
635
+ import { View, Text } from 'react-native'
532
636
  import { StyleSheet } from 'react-native-unistyles'
533
637
 
534
638
  export const Example = () => {
535
- let myRef = useRef()
639
+ const myRef = useRef()
536
640
 
537
641
  return (
538
642
  <View
@@ -551,34 +655,51 @@ pluginTester({
551
655
  })
552
656
  `,
553
657
  output: `
658
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
554
659
  import { useRef } from 'react'
660
+ import { View, Text } from 'react-native'
555
661
  import { StyleSheet } from 'react-native-unistyles'
556
662
 
557
663
  export const Example = () => {
558
- let myRef = useRef()
664
+ const myRef = useRef()
559
665
 
560
666
  return (
561
- <View ref={myRef} style={[obj1, obj2]}>
667
+ <View
668
+ ref={_ref => {
669
+ myRef.current = _ref
670
+ UnistylesShadowRegistry.add(_ref, obj1, undefined, undefined)
671
+ UnistylesShadowRegistry.add(_ref, obj2, undefined, undefined)
672
+ return () => {
673
+ ;(() => UnistylesShadowRegistry.remove(_ref))()
674
+ UnistylesShadowRegistry.remove(_ref)
675
+ }
676
+ }}
677
+ style={[obj1, obj2]}
678
+ >
562
679
  <Text>Hello world</Text>
563
680
  </View>
564
681
  )
565
682
  }
566
683
 
567
- const styles = StyleSheet.create({
568
- container: {
569
- backgroundColor: 'red'
570
- }
571
- })
684
+ const styles = StyleSheet.create(
685
+ {
686
+ container: {
687
+ backgroundColor: 'red'
688
+ }
689
+ },
690
+ 921918562
691
+ )
572
692
  `
573
693
  },
574
694
  {
575
695
  title: 'Should modify ref if user is using spreads on styles',
576
696
  code: `
577
697
  import { useRef } from 'react'
698
+ import { View, Text } from 'react-native'
578
699
  import { StyleSheet } from 'react-native-unistyles'
579
700
 
580
701
  export const Example = () => {
581
- let myRef = useRef()
702
+ const myRef = useRef()
582
703
 
583
704
  return (
584
705
  <View
@@ -604,45 +725,56 @@ pluginTester({
604
725
  output: `
605
726
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
606
727
  import { useRef } from 'react'
728
+ import { View, Text } from 'react-native'
607
729
  import { StyleSheet } from 'react-native-unistyles'
608
730
 
609
731
  export const Example = () => {
610
- let myRef = useRef()
732
+ const myRef = useRef()
611
733
 
612
734
  return (
613
735
  <View
614
736
  ref={_ref => {
615
- myRef = _ref
616
- UnistylesShadowRegistry.add(_ref, styles.container)
617
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
618
- }}
619
- style={{
620
- ...styles.container,
621
- ...{
622
- backgroundColor: 'red'
737
+ myRef.current = _ref
738
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
739
+ UnistylesShadowRegistry.add(
740
+ _ref,
741
+ {
742
+ backgroundColor: 'red'
743
+ },
744
+ undefined,
745
+ undefined
746
+ )
747
+ return () => {
748
+ ;(() => UnistylesShadowRegistry.remove(_ref))()
749
+ UnistylesShadowRegistry.remove(_ref)
623
750
  }
624
751
  }}
752
+ style={[styles.container, { backgroundColor: 'red' }]}
625
753
  >
626
754
  <Text>Hello world</Text>
627
755
  </View>
628
756
  )
629
757
  }
630
758
 
631
- const styles = StyleSheet.create({
632
- container: {
633
- backgroundColor: 'red'
634
- }
635
- })
759
+ const styles = StyleSheet.create(
760
+ {
761
+ container: {
762
+ backgroundColor: 'red'
763
+ }
764
+ },
765
+ 921918562
766
+ )
636
767
  `
637
768
  },
638
769
  {
639
770
  title: 'Should modify ref if user is using array for styles',
640
771
  code: `
641
772
  import { useRef } from 'react'
773
+ import { View, Text } from 'react-native'
642
774
  import { StyleSheet } from 'react-native-unistyles'
643
775
 
644
776
  export const Example = () => {
645
- let myRef = useRef()
777
+ const myRef = useRef()
646
778
 
647
779
  return (
648
780
  <View
@@ -668,50 +800,61 @@ pluginTester({
668
800
  output: `
669
801
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
670
802
  import { useRef } from 'react'
803
+ import { View, Text } from 'react-native'
671
804
  import { StyleSheet } from 'react-native-unistyles'
672
805
 
673
806
  export const Example = () => {
674
- let myRef = useRef()
807
+ const myRef = useRef()
675
808
 
676
809
  return (
677
810
  <View
678
811
  ref={_ref => {
679
- myRef = _ref
680
- UnistylesShadowRegistry.add(_ref, styles.container)
681
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
682
- }}
683
- style={[
684
- styles.container,
685
- {
686
- backgroundColor: 'red'
812
+ myRef.current = _ref
813
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
814
+ UnistylesShadowRegistry.add(
815
+ _ref,
816
+ {
817
+ backgroundColor: 'red'
818
+ },
819
+ undefined,
820
+ undefined
821
+ )
822
+ return () => {
823
+ ;(() => UnistylesShadowRegistry.remove(_ref))()
824
+ UnistylesShadowRegistry.remove(_ref)
687
825
  }
688
- ]}
826
+ }}
827
+ style={[styles.container, { backgroundColor: 'red' }]}
689
828
  >
690
829
  <Text>Hello world</Text>
691
830
  </View>
692
831
  )
693
832
  }
694
833
 
695
- const styles = StyleSheet.create({
696
- container: {
697
- backgroundColor: 'red'
698
- }
699
- })
834
+ const styles = StyleSheet.create(
835
+ {
836
+ container: {
837
+ backgroundColor: 'red'
838
+ }
839
+ },
840
+ 921918562
841
+ )
700
842
  `
701
843
  },
702
844
  {
703
845
  title: 'Should modify ref if user is using single style in array',
704
846
  code: `
705
847
  import { useRef } from 'react'
848
+ import { View, Text } from 'react-native'
706
849
  import { StyleSheet } from 'react-native-unistyles'
707
850
 
708
851
  export const Example = () => {
709
- let myRef = useRef()
852
+ const myRef = useRef()
710
853
 
711
854
  return (
712
855
  <View
713
856
  ref={myRef}
714
- style={[styles.container]}
857
+ style={styles.container}
715
858
  >
716
859
  <Text>Hello world</Text>
717
860
  </View>
@@ -727,17 +870,18 @@ pluginTester({
727
870
  output: `
728
871
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
729
872
  import { useRef } from 'react'
873
+ import { View, Text } from 'react-native'
730
874
  import { StyleSheet } from 'react-native-unistyles'
731
875
 
732
876
  export const Example = () => {
733
- let myRef = useRef()
877
+ const myRef = useRef()
734
878
 
735
879
  return (
736
880
  <View
737
881
  ref={_ref => {
738
- myRef = _ref
739
- UnistylesShadowRegistry.add(_ref, styles.container)
740
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
882
+ myRef.current = _ref
883
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, undefined)
884
+ return () => UnistylesShadowRegistry.remove(_ref)
741
885
  }}
742
886
  style={[styles.container]}
743
887
  >
@@ -746,21 +890,25 @@ pluginTester({
746
890
  )
747
891
  }
748
892
 
749
- const styles = StyleSheet.create({
750
- container: {
751
- backgroundColor: 'red'
752
- }
753
- })
893
+ const styles = StyleSheet.create(
894
+ {
895
+ container: {
896
+ backgroundColor: 'red'
897
+ }
898
+ },
899
+ 921918562
900
+ )
754
901
  `
755
902
  },
756
903
  {
757
904
  title: 'Should modify ref if user is using dynamic function in array',
758
905
  code: `
759
906
  import { useRef } from 'react'
907
+ import { View, Text } from 'react-native'
760
908
  import { StyleSheet } from 'react-native-unistyles'
761
909
 
762
910
  export const Example = () => {
763
- let myRef = useRef()
911
+ const myRef = useRef()
764
912
 
765
913
  return (
766
914
  <View
@@ -783,40 +931,45 @@ pluginTester({
783
931
  output: `
784
932
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
785
933
  import { useRef } from 'react'
934
+ import { View, Text } from 'react-native'
786
935
  import { StyleSheet } from 'react-native-unistyles'
787
936
 
788
937
  export const Example = () => {
789
- let myRef = useRef()
938
+ const myRef = useRef()
790
939
 
791
940
  return (
792
941
  <View
793
942
  ref={_ref => {
794
- myRef = _ref
795
- UnistylesShadowRegistry.add(_ref, styles.container)
796
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
943
+ myRef.current = _ref
944
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, [1, 2])
945
+ return () => UnistylesShadowRegistry.remove(_ref)
797
946
  }}
798
- style={[styles.container(1, 2, 1)]}
947
+ style={[styles.container(1, 2)]}
799
948
  >
800
949
  <Text>Hello world</Text>
801
950
  </View>
802
951
  )
803
952
  }
804
953
 
805
- const styles = StyleSheet.create({
806
- container: () => ({
807
- backgroundColor: 'red'
808
- })
809
- })
954
+ const styles = StyleSheet.create(
955
+ {
956
+ container: () => ({
957
+ backgroundColor: 'red'
958
+ })
959
+ },
960
+ 921918562
961
+ )
810
962
  `
811
963
  },
812
964
  {
813
965
  title: 'Should modify ref if user is using dynamic function in object',
814
966
  code: `
815
967
  import { useRef } from 'react'
968
+ import { View, Text } from 'react-native'
816
969
  import { StyleSheet } from 'react-native-unistyles'
817
970
 
818
971
  export const Example = () => {
819
- let myRef = useRef()
972
+ const myRef = useRef()
820
973
 
821
974
  return (
822
975
  <View
@@ -832,51 +985,61 @@ pluginTester({
832
985
  }
833
986
 
834
987
  const styles = StyleSheet.create({
835
- container: () => ({
988
+ container: {
836
989
  backgroundColor: 'red'
837
- })
990
+ }
838
991
  })
839
992
  `,
840
993
  output: `
841
994
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
842
995
  import { useRef } from 'react'
996
+ import { View, Text } from 'react-native'
843
997
  import { StyleSheet } from 'react-native-unistyles'
844
998
 
845
999
  export const Example = () => {
846
- let myRef = useRef()
1000
+ const myRef = useRef()
847
1001
 
848
1002
  return (
849
1003
  <View
850
1004
  ref={_ref => {
851
- myRef = _ref
852
- UnistylesShadowRegistry.add(_ref, styles.container)
853
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
854
- }}
855
- style={{
856
- backgroundColor: 'red',
857
- ...styles.container(1, 2, 1)
1005
+ myRef.current = _ref
1006
+ UnistylesShadowRegistry.add(_ref, styles.container, undefined, [1, 2])
1007
+ UnistylesShadowRegistry.add(_ref, { backgroundColor: 'red' }, undefined, undefined)
1008
+ return () => {
1009
+ ;(() => UnistylesShadowRegistry.remove(_ref))()
1010
+ UnistylesShadowRegistry.remove(_ref)
1011
+ }
858
1012
  }}
1013
+ style={[{ backgroundColor: 'red' }, styles.container(1, 2)]}
859
1014
  >
860
1015
  <Text>Hello world</Text>
861
1016
  </View>
862
1017
  )
863
1018
  }
864
1019
 
865
- const styles = StyleSheet.create({
866
- container: () => ({
867
- backgroundColor: 'red'
868
- })
869
- })
1020
+ const styles = StyleSheet.create(
1021
+ {
1022
+ container: {
1023
+ backgroundColor: 'red'
1024
+ }
1025
+ },
1026
+ 921918562
1027
+ )
870
1028
  `
871
1029
  },
872
1030
  {
873
- title: 'Should modify registry names if user changes name of member expression',
1031
+ title: 'It should extract variants and pass them to ShadowReigstry',
874
1032
  code: `
875
1033
  import { useRef } from 'react'
1034
+ import { View, Text } from 'react-native'
876
1035
  import { StyleSheet } from 'react-native-unistyles'
877
1036
 
878
1037
  export const Example = () => {
879
- let myRef = useRef()
1038
+ const myRef = useRef()
1039
+
1040
+ styles.useVariants({
1041
+ size: 'default'
1042
+ })
880
1043
 
881
1044
  return (
882
1045
  <View
@@ -890,62 +1053,90 @@ pluginTester({
890
1053
 
891
1054
  const uhh = StyleSheet.create({
892
1055
  dkk: () => ({
893
- backgroundColor: 'red'
1056
+ backgroundColor: 'red',
1057
+ variants: {
1058
+ size: {
1059
+ small: {
1060
+ backgroundColor: 'blue'
1061
+ },
1062
+ default: {
1063
+ backgroundColor: 'green'
1064
+ }
1065
+ }
1066
+ }
894
1067
  })
895
1068
  })
896
1069
  `,
897
1070
  output: `
898
1071
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
899
1072
  import { useRef } from 'react'
1073
+ import { View, Text } from 'react-native'
900
1074
  import { StyleSheet } from 'react-native-unistyles'
901
1075
 
902
1076
  export const Example = () => {
903
- let myRef = useRef()
1077
+ const myRef = useRef()
1078
+ const __uni__variants = {
1079
+ size: 'default'
1080
+ }
1081
+ styles.useVariants(__uni__variants)
904
1082
 
905
1083
  return (
906
1084
  <View
907
1085
  ref={_ref => {
908
- myRef = _ref
909
- UnistylesShadowRegistry.add(_ref, uhh.dkk)
910
- return () => UnistylesShadowRegistry.remove(_ref, uhh.dkk)
1086
+ myRef.current = _ref
1087
+ UnistylesShadowRegistry.add(_ref, uhh.dkk, __uni__variants, [])
1088
+ return () => UnistylesShadowRegistry.remove(_ref)
911
1089
  }}
912
- style={uhh.dkk(1)}
1090
+ style={[uhh.dkk()]}
913
1091
  >
914
1092
  <Text>Hello world</Text>
915
1093
  </View>
916
1094
  )
917
1095
  }
918
1096
 
919
- const uhh = StyleSheet.create({
920
- dkk: () => ({
921
- backgroundColor: 'red'
922
- })
923
- })
1097
+ const uhh = StyleSheet.create(
1098
+ {
1099
+ dkk: () => ({
1100
+ backgroundColor: 'red',
1101
+ variants: {
1102
+ size: {
1103
+ small: {
1104
+ backgroundColor: 'blue'
1105
+ },
1106
+ default: {
1107
+ backgroundColor: 'green'
1108
+ }
1109
+ }
1110
+ },
1111
+ uni__dependencies: [4]
1112
+ })
1113
+ },
1114
+ 921918562
1115
+ )
924
1116
  `
925
1117
  },
926
1118
  {
927
- title: 'Should increment counter for web dynamic functions',
1119
+ title: 'Should modify registry names if user changes name of member expression',
928
1120
  code: `
929
1121
  import { useRef } from 'react'
1122
+ import { View, Text } from 'react-native'
930
1123
  import { StyleSheet } from 'react-native-unistyles'
931
1124
 
932
1125
  export const Example = () => {
933
- let myRef = useRef()
1126
+ const myRef = useRef()
934
1127
 
935
1128
  return (
936
1129
  <View
937
1130
  ref={myRef}
938
- style={styles.container()}
1131
+ style={uhh.dkk()}
939
1132
  >
940
- <Text style={styles.container()}>
941
- Hello world
942
- </Text>
1133
+ <Text>Hello world</Text>
943
1134
  </View>
944
1135
  )
945
1136
  }
946
1137
 
947
- const styles = StyleSheet.create({
948
- container: () => ({
1138
+ const uhh = StyleSheet.create({
1139
+ dkk: () => ({
949
1140
  backgroundColor: 'red'
950
1141
  })
951
1142
  })
@@ -953,39 +1144,284 @@ pluginTester({
953
1144
  output: `
954
1145
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
955
1146
  import { useRef } from 'react'
1147
+ import { View, Text } from 'react-native'
956
1148
  import { StyleSheet } from 'react-native-unistyles'
957
1149
 
958
1150
  export const Example = () => {
959
- let myRef = useRef()
1151
+ const myRef = useRef()
960
1152
 
961
1153
  return (
962
1154
  <View
963
1155
  ref={_ref => {
964
- myRef = _ref
965
- UnistylesShadowRegistry.add(_ref, styles.container)
966
- return () => UnistylesShadowRegistry.remove(_ref, styles.container)
1156
+ myRef.current = _ref
1157
+ UnistylesShadowRegistry.add(_ref, uhh.dkk, undefined, [])
1158
+ return () => UnistylesShadowRegistry.remove(_ref)
967
1159
  }}
968
- style={styles.container(1)}
1160
+ style={[uhh.dkk()]}
969
1161
  >
970
- <Text
971
- style={styles.container(2)}
1162
+ <Text>Hello world</Text>
1163
+ </View>
1164
+ )
1165
+ }
1166
+
1167
+ const uhh = StyleSheet.create(
1168
+ {
1169
+ dkk: () => ({
1170
+ backgroundColor: 'red'
1171
+ })
1172
+ },
1173
+ 921918562
1174
+ )
1175
+ `
1176
+ },
1177
+ {
1178
+ title: 'Should pass ref for dynamic functions to bind it to shadow node',
1179
+ code: `
1180
+ import { View } from 'react-native'
1181
+ import { StyleSheet } from 'react-native-unistyles'
1182
+
1183
+ export const Example = () => {
1184
+ return (
1185
+ <React.Fragment>
1186
+ <View style={styles.container(1, 5)} />
1187
+ <View style={styles.container(2, 6)} />
1188
+ <View style={styles.container(5, 1)} />
1189
+ </React.Fragment>
1190
+ )
1191
+ }
1192
+
1193
+ const styles = StyleSheet.create({
1194
+ container: (flex, gap) => ({
1195
+ flex,
1196
+ gap
1197
+ })
1198
+ })
1199
+ `,
1200
+ output: `
1201
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
1202
+ import { View } from 'react-native'
1203
+ import { StyleSheet } from 'react-native-unistyles'
1204
+
1205
+ export const Example = () => {
1206
+ return (
1207
+ <React.Fragment>
1208
+ <View
1209
+ style={[styles.container(1, 5)]}
972
1210
  ref={ref => {
973
- UnistylesShadowRegistry.add(ref, styles.container)
974
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
1211
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [1, 5])
1212
+ return () => UnistylesShadowRegistry.remove(ref)
975
1213
  }}
976
- >
977
- Hello world
978
- </Text>
979
- </View>
1214
+ />
1215
+ <View
1216
+ style={[styles.container(2, 6)]}
1217
+ ref={ref => {
1218
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [2, 6])
1219
+ return () => UnistylesShadowRegistry.remove(ref)
1220
+ }}
1221
+ />
1222
+ <View
1223
+ style={[styles.container(5, 1)]}
1224
+ ref={ref => {
1225
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [5, 1])
1226
+ return () => UnistylesShadowRegistry.remove(ref)
1227
+ }}
1228
+ />
1229
+ </React.Fragment>
1230
+ )
1231
+ }
1232
+
1233
+ const styles = StyleSheet.create(
1234
+ {
1235
+ container: (flex, gap) => ({
1236
+ flex,
1237
+ gap
1238
+ })
1239
+ },
1240
+ 921918562
1241
+ )
1242
+ `
1243
+ },
1244
+ {
1245
+ title: 'Should pass refs for dynamic functions',
1246
+ code: `
1247
+ import { View } from 'react-native'
1248
+ import { StyleSheet } from 'react-native-unistyles'
1249
+
1250
+ export const Example = () => {
1251
+ return (
1252
+ <React.Fragment>
1253
+ <View style={[styles.container(1, 5), styles.container2(1, 6)]} />
1254
+ </React.Fragment>
980
1255
  )
981
1256
  }
982
1257
 
983
1258
  const styles = StyleSheet.create({
984
- container: () => ({
985
- backgroundColor: 'red'
1259
+ container: (flex, gap) => ({
1260
+ flex,
1261
+ gap
986
1262
  })
987
1263
  })
1264
+ `,
1265
+ output: `
1266
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
1267
+ import { View } from 'react-native'
1268
+ import { StyleSheet } from 'react-native-unistyles'
1269
+
1270
+ export const Example = () => {
1271
+ return (
1272
+ <React.Fragment>
1273
+ <View
1274
+ style={[styles.container(1, 5), styles.container2(1, 6)]}
1275
+ ref={ref => {
1276
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, [1, 5])
1277
+ UnistylesShadowRegistry.add(ref, styles.container2, undefined, [1, 6])
1278
+ return () => {
1279
+ ;(() => UnistylesShadowRegistry.remove(ref))()
1280
+ UnistylesShadowRegistry.remove(ref)
1281
+ }
1282
+ }}
1283
+ />
1284
+ </React.Fragment>
1285
+ )
1286
+ }
1287
+
1288
+ const styles = StyleSheet.create(
1289
+ {
1290
+ container: (flex, gap) => ({
1291
+ flex,
1292
+ gap
1293
+ })
1294
+ },
1295
+ 921918562
1296
+ )
1297
+ `
1298
+ },
1299
+ {
1300
+ title: 'Should keep order of spreads',
1301
+ code: `
1302
+ import { View } from 'react-native'
1303
+ import { StyleSheet } from 'react-native-unistyles'
1304
+
1305
+ export const Example = () => {
1306
+ return (
1307
+ <View style={{...styles.container, ...styles.secondProp, ...styles.thirdProp}} />
1308
+ )
1309
+ }
1310
+
1311
+ const styles = StyleSheet.create(theme => ({
1312
+ container: {
1313
+ flex: 1,
1314
+ alignItems: 'center',
1315
+ justifyContent: 'center',
1316
+ backgroundColor: theme.colors.backgroundColor
1317
+ },
1318
+ secondProp: {
1319
+ marginHorizontal: theme.gap(10),
1320
+ backgroundColor: 'red'
1321
+ },
1322
+ thirdProp: {
1323
+ backgroundColor: 'blue'
1324
+ }
1325
+ }))
1326
+ `,
1327
+ output: `
1328
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
1329
+ import { View } from 'react-native'
1330
+ import { StyleSheet } from 'react-native-unistyles'
1331
+
1332
+ export const Example = () => {
1333
+ return (
1334
+ <View
1335
+ style={[styles.container, styles.secondProp, styles.thirdProp]}
1336
+ ref={ref => {
1337
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
1338
+ UnistylesShadowRegistry.add(ref, styles.secondProp, undefined, undefined)
1339
+ UnistylesShadowRegistry.add(ref, styles.thirdProp, undefined, undefined)
1340
+ return () => {
1341
+ ;(() => {
1342
+ ;(() => UnistylesShadowRegistry.remove(ref))()
1343
+ UnistylesShadowRegistry.remove(ref)
1344
+ })()
1345
+ UnistylesShadowRegistry.remove(ref)
1346
+ }
1347
+ }}
1348
+ />
1349
+ )
1350
+ }
1351
+
1352
+ const styles = StyleSheet.create(
1353
+ theme => ({
1354
+ container: {
1355
+ flex: 1,
1356
+ alignItems: 'center',
1357
+ justifyContent: 'center',
1358
+ backgroundColor: theme.colors.backgroundColor,
1359
+ uni__dependencies: [0]
1360
+ },
1361
+ secondProp: {
1362
+ marginHorizontal: theme.gap(10),
1363
+ backgroundColor: 'red',
1364
+ uni__dependencies: [0]
1365
+ },
1366
+ thirdProp: {
1367
+ backgroundColor: 'blue'
1368
+ }
1369
+ }),
1370
+ 921918562
1371
+ )
988
1372
  `
989
1373
  },
1374
+ {
1375
+ title: 'Should support nested styles',
1376
+ code: `
1377
+ import { View } from 'react-native'
1378
+ import { StyleSheet } from 'react-native-unistyles'
1379
+
1380
+ export const Example = ({ styles }) => {
1381
+ return (
1382
+ <View style={styles.nested.prop} />
1383
+ )
1384
+ }
1385
+
1386
+ const styles = StyleSheet.create(theme => ({
1387
+ container: {
1388
+ flex: 1,
1389
+ alignItems: 'center',
1390
+ justifyContent: 'center',
1391
+ backgroundColor: theme.colors.backgroundColor
1392
+ }
1393
+ }))
1394
+ `,
1395
+ output: `
1396
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
1397
+ import { View } from 'react-native'
1398
+ import { StyleSheet } from 'react-native-unistyles'
1399
+
1400
+ export const Example = ({ styles }) => {
1401
+ return (
1402
+ <View
1403
+ style={[styles.nested.prop]}
1404
+ ref={ref => {
1405
+ UnistylesShadowRegistry.add(ref, styles.nested.prop, undefined, undefined)
1406
+ return () => UnistylesShadowRegistry.remove(ref)
1407
+ }}
1408
+ />
1409
+ )
1410
+ }
1411
+
1412
+ const styles = StyleSheet.create(
1413
+ theme => ({
1414
+ container: {
1415
+ flex: 1,
1416
+ alignItems: 'center',
1417
+ justifyContent: 'center',
1418
+ backgroundColor: theme.colors.backgroundColor,
1419
+ uni__dependencies: [0]
1420
+ }
1421
+ }),
1422
+ 921918562
1423
+ )
1424
+ `
1425
+ }
990
1426
  ]
991
1427
  })