react-native-unistyles 3.0.0-rc.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/README.md +9 -7
  2. package/Unistyles.podspec +12 -1
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -8
  5. package/android/src/main/cxx/NativeUnistylesModule.h +4 -4
  6. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -0
  7. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +21 -9
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +8 -7
  9. package/cxx/core/UnistyleWrapper.h +4 -1
  10. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  11. package/cxx/core/UnistylesRegistry.cpp +52 -49
  12. package/cxx/core/UnistylesRegistry.h +2 -1
  13. package/cxx/core/UnistylesState.cpp +10 -0
  14. package/cxx/core/UnistylesState.h +3 -0
  15. package/cxx/hybridObjects/HybridShadowRegistry.cpp +6 -1
  16. package/cxx/hybridObjects/HybridShadowRegistry.h +6 -0
  17. package/cxx/hybridObjects/HybridStyleSheet.cpp +13 -16
  18. package/cxx/hybridObjects/HybridStyleSheet.h +2 -7
  19. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +17 -2
  20. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  21. package/cxx/parser/Parser.cpp +175 -110
  22. package/cxx/parser/Parser.h +1 -0
  23. package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
  24. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  25. package/get_rn_version.rb +28 -0
  26. package/ios/UnistylesModuleOnLoad.h +1 -5
  27. package/ios/UnistylesModuleOnLoad.mm +10 -13
  28. package/lib/commonjs/components/AdaptiveTheme.js +35 -0
  29. package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
  30. package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
  31. package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
  32. package/lib/commonjs/components/NamedTheme.js +31 -0
  33. package/lib/commonjs/components/NamedTheme.js.map +1 -0
  34. package/lib/commonjs/components/ScopedTheme.js +30 -21
  35. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  36. package/lib/commonjs/components/native/Image.js +1 -2
  37. package/lib/commonjs/components/native/Image.js.map +1 -1
  38. package/lib/commonjs/components/native/ImageBackground.js +1 -2
  39. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  40. package/lib/commonjs/components/native/Pressable.js +1 -2
  41. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  42. package/lib/commonjs/components/native/Pressable.native.js +1 -2
  43. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  44. package/lib/commonjs/core/createUnistylesElement.js +5 -5
  45. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  46. package/lib/commonjs/core/createUnistylesElement.native.js +18 -31
  47. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  48. package/lib/commonjs/core/createUnistylesImageBackground.js +6 -21
  49. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  50. package/lib/commonjs/core/getClassname.js +1 -2
  51. package/lib/commonjs/core/getClassname.js.map +1 -1
  52. package/lib/commonjs/core/parseBoxShadow.js +57 -0
  53. package/lib/commonjs/core/parseBoxShadow.js.map +1 -0
  54. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +2 -3
  55. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  56. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +2 -1
  57. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  58. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
  59. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  60. package/lib/commonjs/core/withUnistyles/withUnistyles.js +10 -5
  61. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  62. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +10 -5
  63. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  64. package/lib/commonjs/index.js +6 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/mocks.js +26 -2
  67. package/lib/commonjs/mocks.js.map +1 -1
  68. package/lib/commonjs/reanimated/index.js +7 -0
  69. package/lib/commonjs/reanimated/index.js.map +1 -1
  70. package/lib/commonjs/reanimated/variant/index.js +17 -0
  71. package/lib/commonjs/reanimated/variant/index.js.map +1 -0
  72. package/lib/commonjs/reanimated/variant/types.js +2 -0
  73. package/lib/commonjs/reanimated/variant/types.js.map +1 -0
  74. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
  75. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  76. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
  77. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  78. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
  79. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  80. package/lib/commonjs/server/getServerUnistyles.js +1 -2
  81. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  82. package/lib/commonjs/server/hydrateServerUnistyles.js +1 -2
  83. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  84. package/lib/commonjs/server/resetServerUnistyles.js +1 -2
  85. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  86. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
  87. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  88. package/lib/commonjs/specs/StyleSheet/index.js +3 -1
  89. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  90. package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -1
  91. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  92. package/lib/commonjs/utils.js +0 -3
  93. package/lib/commonjs/utils.js.map +1 -1
  94. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
  95. package/lib/commonjs/web/convert/pseudo.js +13 -3
  96. package/lib/commonjs/web/convert/pseudo.js.map +1 -1
  97. package/lib/commonjs/web/convert/utils.js +1 -0
  98. package/lib/commonjs/web/convert/utils.js.map +1 -1
  99. package/lib/commonjs/web/create.js +2 -3
  100. package/lib/commonjs/web/create.js.map +1 -1
  101. package/lib/commonjs/web/css/core.js +9 -2
  102. package/lib/commonjs/web/css/core.js.map +1 -1
  103. package/lib/commonjs/web/css/state.js +10 -7
  104. package/lib/commonjs/web/css/state.js.map +1 -1
  105. package/lib/commonjs/web/index.js +1 -2
  106. package/lib/commonjs/web/index.js.map +1 -1
  107. package/lib/commonjs/web/listener.js +4 -2
  108. package/lib/commonjs/web/listener.js.map +1 -1
  109. package/lib/commonjs/web/runtime.js +26 -2
  110. package/lib/commonjs/web/runtime.js.map +1 -1
  111. package/lib/commonjs/web/shadowRegistry.js +5 -3
  112. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  113. package/lib/commonjs/web/state.js +1 -10
  114. package/lib/commonjs/web/state.js.map +1 -1
  115. package/lib/commonjs/web/types.js.map +1 -1
  116. package/lib/commonjs/web/utils/createUnistylesRef.js +1 -2
  117. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  118. package/lib/commonjs/web/utils/unistyle.js +26 -4
  119. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  120. package/lib/module/components/AdaptiveTheme.js +29 -0
  121. package/lib/module/components/AdaptiveTheme.js.map +1 -0
  122. package/lib/module/components/ApplyScopedTheme.js +14 -0
  123. package/lib/module/components/ApplyScopedTheme.js.map +1 -0
  124. package/lib/module/components/NamedTheme.js +25 -0
  125. package/lib/module/components/NamedTheme.js.map +1 -0
  126. package/lib/module/components/ScopedTheme.js +30 -20
  127. package/lib/module/components/ScopedTheme.js.map +1 -1
  128. package/lib/module/core/createUnistylesElement.js +5 -5
  129. package/lib/module/core/createUnistylesElement.js.map +1 -1
  130. package/lib/module/core/createUnistylesElement.native.js +18 -30
  131. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  132. package/lib/module/core/createUnistylesImageBackground.js +5 -19
  133. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  134. package/lib/module/core/parseBoxShadow.js +52 -0
  135. package/lib/module/core/parseBoxShadow.js.map +1 -0
  136. package/lib/module/core/useProxifiedUnistyles/listener.js +1 -1
  137. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  138. package/lib/module/core/useProxifiedUnistyles/listener.native.js +2 -1
  139. package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  140. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
  141. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  142. package/lib/module/core/withUnistyles/withUnistyles.js +9 -3
  143. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  144. package/lib/module/core/withUnistyles/withUnistyles.native.js +9 -3
  145. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  146. package/lib/module/index.js +5 -0
  147. package/lib/module/index.js.map +1 -1
  148. package/lib/module/mocks.js +26 -2
  149. package/lib/module/mocks.js.map +1 -1
  150. package/lib/module/reanimated/index.js +1 -0
  151. package/lib/module/reanimated/index.js.map +1 -1
  152. package/lib/module/reanimated/variant/index.js +4 -0
  153. package/lib/module/reanimated/variant/index.js.map +1 -0
  154. package/lib/module/reanimated/variant/types.js +2 -0
  155. package/lib/module/reanimated/variant/types.js.map +1 -0
  156. package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
  157. package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  158. package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
  159. package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  160. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
  161. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  162. package/lib/module/specs/ShadowRegistry/index.js +6 -1
  163. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  164. package/lib/module/specs/StyleSheet/index.js +3 -1
  165. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  166. package/lib/module/specs/UnistylesRuntime/index.js +0 -1
  167. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  168. package/lib/module/utils.js +0 -3
  169. package/lib/module/utils.js.map +1 -1
  170. package/lib/module/web/convert/object/boxShadow.js.map +1 -1
  171. package/lib/module/web/convert/pseudo.js +10 -2
  172. package/lib/module/web/convert/pseudo.js.map +1 -1
  173. package/lib/module/web/convert/utils.js +1 -0
  174. package/lib/module/web/convert/utils.js.map +1 -1
  175. package/lib/module/web/create.js +1 -1
  176. package/lib/module/web/create.js.map +1 -1
  177. package/lib/module/web/css/core.js +9 -2
  178. package/lib/module/web/css/core.js.map +1 -1
  179. package/lib/module/web/css/state.js +10 -7
  180. package/lib/module/web/css/state.js.map +1 -1
  181. package/lib/module/web/listener.js +4 -2
  182. package/lib/module/web/listener.js.map +1 -1
  183. package/lib/module/web/runtime.js +27 -3
  184. package/lib/module/web/runtime.js.map +1 -1
  185. package/lib/module/web/shadowRegistry.js +5 -3
  186. package/lib/module/web/shadowRegistry.js.map +1 -1
  187. package/lib/module/web/state.js +1 -10
  188. package/lib/module/web/state.js.map +1 -1
  189. package/lib/module/web/types.js.map +1 -1
  190. package/lib/module/web/utils/unistyle.js +24 -3
  191. package/lib/module/web/utils/unistyle.js.map +1 -1
  192. package/lib/typescript/plugin/src/consts.d.ts +17 -0
  193. package/lib/typescript/plugin/src/consts.d.ts.map +1 -0
  194. package/lib/typescript/repack-plugin/src/index.d.ts +18 -0
  195. package/lib/typescript/repack-plugin/src/index.d.ts.map +1 -0
  196. package/lib/typescript/repack-plugin/src/loader.d.ts +9 -0
  197. package/lib/typescript/repack-plugin/src/loader.d.ts.map +1 -0
  198. package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
  199. package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
  200. package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
  201. package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
  202. package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
  203. package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
  204. package/lib/typescript/src/components/ScopedTheme.d.ts +10 -0
  205. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
  206. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  207. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  208. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  209. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  210. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  211. package/lib/typescript/src/core/parseBoxShadow.d.ts +11 -0
  212. package/lib/typescript/src/core/parseBoxShadow.d.ts.map +1 -0
  213. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  214. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  215. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  216. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +1 -1
  217. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -1
  218. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  219. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  220. package/lib/typescript/src/core/withUnistyles/types.d.ts +3 -1
  221. package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -1
  222. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  223. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  224. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  225. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  226. package/lib/typescript/src/index.d.ts.map +1 -1
  227. package/lib/typescript/src/reanimated/index.d.ts +1 -0
  228. package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
  229. package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
  230. package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
  231. package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
  232. package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
  233. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
  234. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
  235. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
  236. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
  237. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
  238. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
  239. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  240. package/lib/typescript/src/server/serialize.d.ts.map +1 -1
  241. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  242. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -0
  243. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  244. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  245. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -0
  246. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  247. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +2 -0
  248. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  249. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  250. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  251. package/lib/typescript/src/utils.d.ts.map +1 -1
  252. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  253. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  254. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  255. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  256. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  257. package/lib/typescript/src/web/convert/pseudo.d.ts +6 -3
  258. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  259. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  260. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  261. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  262. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  263. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  264. package/lib/typescript/src/web/create.d.ts.map +1 -1
  265. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  266. package/lib/typescript/src/web/css/state.d.ts +2 -1
  267. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  268. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  269. package/lib/typescript/src/web/listener.d.ts +4 -2
  270. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  271. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  272. package/lib/typescript/src/web/runtime.d.ts +2 -0
  273. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  274. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -0
  275. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  276. package/lib/typescript/src/web/state.d.ts.map +1 -1
  277. package/lib/typescript/src/web/types.d.ts +4 -1
  278. package/lib/typescript/src/web/types.d.ts.map +1 -1
  279. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  280. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  281. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
  282. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  283. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  284. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -1
  285. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -0
  286. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +2 -0
  287. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  288. package/package.json +33 -23
  289. package/plugin/index.d.ts +6 -5
  290. package/plugin/index.js +11 -6
  291. package/repack-plugin/index.d.ts +19 -0
  292. package/repack-plugin/index.js +149 -0
  293. package/src/components/AdaptiveTheme.tsx +34 -0
  294. package/src/components/ApplyScopedTheme.tsx +17 -0
  295. package/src/components/NamedTheme.tsx +33 -0
  296. package/src/components/ScopedTheme.tsx +51 -24
  297. package/src/core/createUnistylesElement.native.tsx +21 -31
  298. package/src/core/createUnistylesElement.tsx +8 -6
  299. package/src/core/createUnistylesImageBackground.tsx +7 -22
  300. package/src/core/parseBoxShadow.ts +87 -0
  301. package/src/core/useProxifiedUnistyles/listener.native.ts +3 -1
  302. package/src/core/useProxifiedUnistyles/listener.ts +1 -1
  303. package/src/core/useProxifiedUnistyles/types.ts +1 -1
  304. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +19 -2
  305. package/src/core/withUnistyles/types.ts +1 -1
  306. package/src/core/withUnistyles/withUnistyles.native.tsx +10 -3
  307. package/src/core/withUnistyles/withUnistyles.tsx +11 -8
  308. package/src/index.ts +8 -0
  309. package/src/mocks.ts +28 -2
  310. package/src/reanimated/index.ts +1 -0
  311. package/src/reanimated/variant/index.ts +1 -0
  312. package/src/reanimated/variant/types.ts +14 -0
  313. package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
  314. package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
  315. package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
  316. package/src/specs/ShadowRegistry/index.ts +7 -1
  317. package/src/specs/StyleSheet/index.ts +5 -2
  318. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +2 -0
  319. package/src/specs/UnistylesRuntime/index.ts +0 -1
  320. package/src/utils.ts +1 -3
  321. package/src/web/convert/object/boxShadow.ts +2 -2
  322. package/src/web/convert/pseudo.ts +23 -52
  323. package/src/web/convert/utils.ts +2 -1
  324. package/src/web/create.ts +1 -1
  325. package/src/web/css/core.ts +12 -2
  326. package/src/web/css/state.ts +10 -8
  327. package/src/web/listener.ts +10 -6
  328. package/src/web/runtime.ts +37 -3
  329. package/src/web/shadowRegistry.ts +5 -3
  330. package/src/web/state.ts +7 -17
  331. package/src/web/types.ts +4 -1
  332. package/src/web/utils/unistyle.ts +34 -4
  333. package/cxx/core/UnistylesCommitHook.cpp +0 -59
  334. package/cxx/core/UnistylesCommitHook.h +0 -27
  335. package/cxx/core/UnistylesMountHook.cpp +0 -26
  336. package/cxx/core/UnistylesMountHook.h +0 -24
  337. package/lib/module/package.json +0 -1
  338. /package/{web-only → web}/package.json +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"getWebProps.d.ts","sourceRoot":"","sources":["../../../../src/web-only/getWebProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAA;AAGxD,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,SAAS,CAAC,OAAO,CAAC;;;CAYvD,CAAA"}
1
+ {"version":3,"file":"getWebProps.d.ts","sourceRoot":"","sources":["../../../../src/web-only/getWebProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAmB,MAAM,UAAU,CAAA;AAGxD,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,OAAO,SAAS,CAAC,OAAO,CAAC;;;CAYvD,CAAA"}
@@ -45,6 +45,7 @@ namespace margelo::nitro::unistyles { struct UnistylesNativeMiniRuntime; }
45
45
  #include <NitroModules/ArrayBufferHolder.hpp>
46
46
  #include <NitroModules/AnyMapHolder.hpp>
47
47
  #include <NitroModules/RuntimeError.hpp>
48
+ #include <NitroModules/DateToChronoDate.hpp>
48
49
 
49
50
  // Forward declarations of Swift defined types
50
51
  // Forward declaration of `HybridNativePlatformSpec_cxx` to properly resolve imports.
@@ -26,6 +26,8 @@ namespace margelo::nitro::unistyles {
26
26
  prototype.registerHybridGetter("pixelRatio", &HybridUnistylesRuntimeSpec::getPixelRatio);
27
27
  prototype.registerHybridGetter("fontScale", &HybridUnistylesRuntimeSpec::getFontScale);
28
28
  prototype.registerHybridGetter("rtl", &HybridUnistylesRuntimeSpec::getRtl);
29
+ prototype.registerHybridGetter("isLandscape", &HybridUnistylesRuntimeSpec::getIsLandscape);
30
+ prototype.registerHybridGetter("isPortrait", &HybridUnistylesRuntimeSpec::getIsPortrait);
29
31
  prototype.registerHybridGetter("miniRuntime", &HybridUnistylesRuntimeSpec::getMiniRuntime);
30
32
  prototype.registerHybridMethod("setTheme", &HybridUnistylesRuntimeSpec::setTheme);
31
33
  prototype.registerHybridMethod("setAdaptiveThemes", &HybridUnistylesRuntimeSpec::setAdaptiveThemes);
@@ -72,6 +72,8 @@ namespace margelo::nitro::unistyles {
72
72
  virtual double getPixelRatio() = 0;
73
73
  virtual double getFontScale() = 0;
74
74
  virtual bool getRtl() = 0;
75
+ virtual bool getIsLandscape() = 0;
76
+ virtual bool getIsPortrait() = 0;
75
77
  virtual UnistylesCxxMiniRuntime getMiniRuntime() = 0;
76
78
 
77
79
  public:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.0.0-rc.4",
3
+ "version": "3.0.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "NODE_ENV=babel-test jest ./plugin",
@@ -9,10 +9,11 @@
9
9
  "lint": "biome lint",
10
10
  "check": "biome check --write",
11
11
  "check:ci": "biome check",
12
- "prepare": "husky && bob build && yarn plugin:build",
12
+ "prepare": "husky && bob build && yarn plugin:build && yarn repack:plugin:build",
13
13
  "precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn check' 'yarn test' 'yarn circular:check'",
14
14
  "release": "release-it",
15
15
  "plugin:build": "node plugin/esbuild.js",
16
+ "repack:plugin:build": "node repack-plugin/esbuild.js",
16
17
  "circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 src/**/*.ts",
17
18
  "components:build": "node build-components.js"
18
19
  },
@@ -46,6 +47,11 @@
46
47
  "types": "./plugin/index.d.ts",
47
48
  "default": "./plugin/index.js"
48
49
  },
50
+ "./repack-plugin": {
51
+ "import": "./repack-plugin/index.js",
52
+ "types": "./repack-plugin/index.d.ts",
53
+ "default": "./repack-plugin/index.js"
54
+ },
49
55
  "./package.json": "./package.json",
50
56
  "./server": {
51
57
  "types": "./lib/typescript/src/server/index.d.ts",
@@ -84,6 +90,11 @@
84
90
  "reanimated",
85
91
  "react-native.config.js",
86
92
  "Unistyles.podspec",
93
+ "repack-plugin",
94
+ "get_rn_version.rb",
95
+ "!repack-plugin/__tests__",
96
+ "!repack-plugin/src",
97
+ "!repack-plugin/esbuild.js",
87
98
  "!plugin/__tests__",
88
99
  "!plugin/src",
89
100
  "!plugin/esbuild.js",
@@ -116,35 +127,37 @@
116
127
  "registry": "https://registry.npmjs.org/"
117
128
  },
118
129
  "devDependencies": {
119
- "@babel/core": "7.26.9",
120
- "@babel/plugin-syntax-jsx": "7.25.9",
121
- "@babel/preset-flow": "7.25.9",
122
- "@babel/preset-typescript": "7.26.0",
123
- "@babel/types": "7.26.9",
130
+ "@babel/core": "7.27.1",
131
+ "@babel/plugin-syntax-jsx": "7.27.1",
132
+ "@babel/preset-flow": "7.27.1",
133
+ "@babel/preset-typescript": "7.27.1",
134
+ "@babel/types": "7.27.1",
124
135
  "@biomejs/biome": "1.9.4",
125
- "@commitlint/config-conventional": "19.7.1",
126
- "@react-native/normalize-colors": "0.78.0",
136
+ "@callstack/repack": "5.1.0",
137
+ "@commitlint/config-conventional": "19.8.1",
138
+ "@react-native/normalize-colors": "0.79.2",
127
139
  "@release-it/conventional-changelog": "8.0.2",
140
+ "@rspack/core": "1.3.10",
128
141
  "@types/jest": "29.5.14",
129
- "@types/react": "19.0.10",
142
+ "@types/react": "19.1.4",
130
143
  "babel-plugin-tester": "11.0.4",
131
- "commitlint": "19.7.1",
144
+ "commitlint": "19.8.1",
132
145
  "concurrently": "9.1.2",
133
146
  "dpdm": "3.14.0",
134
- "esbuild": "0.25.0",
147
+ "esbuild": "0.25.4",
135
148
  "husky": "9.1.7",
136
149
  "jest": "29.7.0",
137
150
  "metro-react-native-babel-preset": "0.77.0",
138
- "nitro-codegen": "0.25.2",
139
- "react": "18.3.1",
140
- "react-native": "0.77.1",
141
- "react-native-builder-bob": "0.37.0",
142
- "react-native-nitro-modules": "0.25.2",
151
+ "nitro-codegen": "0.26.2",
152
+ "react": "19.1.0",
153
+ "react-native": "0.79.2",
154
+ "react-native-builder-bob": "0.40.10",
155
+ "react-native-nitro-modules": "0.26.2",
143
156
  "react-native-reanimated": "3.17.5",
144
- "react-native-web": "0.19.13",
145
- "react-test-renderer": "18.3.1",
157
+ "react-native-web": "0.20.0",
158
+ "react-test-renderer": "19.1.0",
146
159
  "release-it": "17.11.0",
147
- "typescript": "5.7.3"
160
+ "typescript": "5.8.3"
148
161
  },
149
162
  "peerDependencies": {
150
163
  "@react-native/normalize-colors": "*",
@@ -222,8 +235,5 @@
222
235
  "name": "TurboUnistyles",
223
236
  "type": "modules",
224
237
  "jsSrcsDir": "./src/specs/TurboUnistyles"
225
- },
226
- "resolutions": {
227
- "@babel/types": "7.26.8"
228
238
  }
229
239
  }
package/plugin/index.d.ts CHANGED
@@ -37,11 +37,12 @@ export interface RemapConfig {
37
37
 
38
38
  export interface UnistylesPluginOptions {
39
39
  /**
40
- * Example: 'src' or 'apps/mobile'
41
- * Add this option if some of your components don't have `react-native-unistyles` import.
42
- * Babel plugin will automatically process all files under this root.
40
+ * Required from RC.5
41
+ * Example: 'src' or 'app'
42
+ * Add root folder of your project. All files under this folder will be processed by the Babel plugin.
43
+ * If you need to process extra folders, use with `autoProcessPaths` option.
43
44
  */
44
- autoProcessRoot?: string,
45
+ root: string,
45
46
 
46
47
  /**
47
48
  * Example: ['@codemask/styles']
@@ -103,7 +104,7 @@ export interface UnistylesPluginOptions {
103
104
  * Defaults to:
104
105
  *
105
106
  * ```ts
106
- * ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
107
+ * ['react-native-reanimated/src/component']
107
108
  * ```
108
109
  */
109
110
  autoProcessPaths?: Array<string>,
package/plugin/index.js CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  default: () => index_default
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
+ var import_node_path2 = __toESM(require("node:path"));
36
37
  var t6 = __toESM(require("@babel/types"));
37
38
 
38
39
  // plugin/src/consts.ts
@@ -59,10 +60,7 @@ var REACT_NATIVE_COMPONENT_NAMES = [
59
60
  ];
60
61
  var REPLACE_WITH_UNISTYLES_PATHS = [
61
62
  "react-native-reanimated/src/component",
62
- "react-native-reanimated/lib/module/component",
63
- "react-native-gesture-handler/lib/module/components",
64
- "react-native-gesture-handler/lib/commonjs/components",
65
- "react-native-gesture-handler/src/components"
63
+ "react-native-reanimated/lib/module/component"
66
64
  ];
67
65
  var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
68
66
  var NATIVE_COMPONENTS_PATHS = {
@@ -165,7 +163,7 @@ function addUnistylesRequire(path2, state) {
165
163
  t2.variableDeclarator(
166
164
  t2.identifier(uniqueName),
167
165
  t2.callExpression(t2.identifier("require"), [
168
- t2.stringLiteral(`react-native-unistyles/src/components/native/${componentName}`)
166
+ t2.stringLiteral(`react-native-unistyles/components/native/${componentName}`)
169
167
  ])
170
168
  )
171
169
  ]);
@@ -724,6 +722,13 @@ function index_default() {
724
722
  visitor: {
725
723
  Program: {
726
724
  enter(path2, state) {
725
+ if (!state.opts.root) {
726
+ throw new Error("Unistyles \u{1F984}: Babel plugin requires `root` option to be set. Please check https://www.unistyl.es/v3/other/babel-plugin#extra-configuration");
727
+ }
728
+ const appRoot = toPlatformPath(import_node_path2.default.join(state.file.opts.root, state.opts.root));
729
+ if (state.file.opts.root === appRoot) {
730
+ throw new Error("Unistyles \u{1F984}: Root option can't resolve to project root as it will include node_modules folder. Please check https://www.unistyl.es/v3/other/babel-plugin#extra-configuration");
731
+ }
727
732
  state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path3) => state.filename?.includes(path3));
728
733
  state.file.hasAnyUnistyle = false;
729
734
  state.file.hasUnistylesImport = false;
@@ -733,7 +738,7 @@ function index_default() {
733
738
  state.file.reactNativeCommonJSName = "";
734
739
  state.file.tagNumber = 0;
735
740
  state.reactNativeImports = {};
736
- state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
741
+ state.file.forceProcessing = state.filename?.includes(appRoot) ?? false;
737
742
  path2.traverse({
738
743
  BlockStatement(blockPath) {
739
744
  if (isInsideNodeModules(state)) {
@@ -0,0 +1,19 @@
1
+ import type {Compiler,LoaderContext,RspackPluginInstance } from '@rspack/core'
2
+ import type { UnistylesPluginOptions } from 'react-native-unistyles/plugin'
3
+
4
+ export declare const BASE_REPACK_EXCLUDE_PATHS: Array<RegExp>
5
+ interface ConstructorParams {
6
+ ruleExcludePaths?: Array<RegExp>
7
+ unistylesPluginOptions?: UnistylesPluginOptions
8
+ }
9
+
10
+ export declare class RepackUnistylePlugin implements RspackPluginInstance {
11
+ private ruleExcludePaths
12
+ private unistylesPluginOptions
13
+ constructor({ ruleExcludePaths, unistylesPluginOptions }?: ConstructorParams)
14
+ apply(compiler: Compiler): void
15
+ }
16
+
17
+ declare function unistylesLoader(this: LoaderContext<UnistylesLoaderOptions>, source: string): void;
18
+
19
+ export default unistylesLoader
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // repack-plugin/src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BASE_REPACK_EXCLUDE_PATHS: () => BASE_REPACK_EXCLUDE_PATHS,
24
+ RepackUnistylePlugin: () => RepackUnistylePlugin,
25
+ default: () => index_default
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var import_repack = require("@callstack/repack");
29
+
30
+ // repack-plugin/src/loader.ts
31
+ var import_core = require("@babel/core");
32
+
33
+ // plugin/src/consts.ts
34
+ var REACT_NATIVE_COMPONENT_NAMES = [
35
+ "ActivityIndicator",
36
+ "View",
37
+ "Text",
38
+ "Image",
39
+ "ImageBackground",
40
+ "KeyboardAvoidingView",
41
+ "Pressable",
42
+ "ScrollView",
43
+ "FlatList",
44
+ "SectionList",
45
+ "Switch",
46
+ "TextInput",
47
+ "RefreshControl",
48
+ "TouchableHighlight",
49
+ "TouchableOpacity",
50
+ "VirtualizedList",
51
+ "Animated"
52
+ // Modal - there is no exposed native handle
53
+ // TouchableWithoutFeedback - can't accept a ref
54
+ ];
55
+ var REPLACE_WITH_UNISTYLES_PATHS = [
56
+ "react-native-reanimated/src/component",
57
+ "react-native-reanimated/lib/module/component"
58
+ ];
59
+
60
+ // repack-plugin/src/loader.ts
61
+ var importName = "react-native-unistyles";
62
+ var UNISTYLES_REGEX = new RegExp(
63
+ [...REACT_NATIVE_COMPONENT_NAMES, ...REPLACE_WITH_UNISTYLES_PATHS, importName].join("|")
64
+ );
65
+ function unistylesLoader(source) {
66
+ this.cacheable();
67
+ const callback = this.async();
68
+ const options = this.getOptions();
69
+ if (!UNISTYLES_REGEX.test(source)) {
70
+ callback(null, source);
71
+ return;
72
+ }
73
+ const unistylesOptions = options.unistylesPluginOptions;
74
+ const unistylesPlugin = unistylesOptions ? ["react-native-unistyles/plugin", unistylesOptions] : "react-native-unistyles/plugin";
75
+ const babelPlugins = options.babelPlugins ?? [];
76
+ (0, import_core.transform)(
77
+ source,
78
+ {
79
+ filename: this.resourcePath,
80
+ babelrc: false,
81
+ configFile: false,
82
+ compact: false,
83
+ comments: true,
84
+ plugins: [...babelPlugins, unistylesPlugin]
85
+ },
86
+ (err, result) => {
87
+ if (err) {
88
+ callback(err);
89
+ return;
90
+ }
91
+ callback(null, result.code, result.map);
92
+ return;
93
+ }
94
+ );
95
+ }
96
+
97
+ // repack-plugin/src/index.ts
98
+ var BASE_REPACK_EXCLUDE_PATHS = (0, import_repack.getModulePaths)([
99
+ "react",
100
+ "react-native",
101
+ "@react-native",
102
+ "react-native-macos",
103
+ "react-native-windows",
104
+ "react-native-tvos",
105
+ "@callstack/react-native-visionos",
106
+ "@module-federation",
107
+ "react-native-unistyles",
108
+ "whatwg-fetch",
109
+ "@callstack",
110
+ "react-native-nitro-modules",
111
+ "@callstack/repack"
112
+ ]);
113
+ var getUnistyleModuleRules = (excludePathLoader, unistylesPluginOptions) => {
114
+ const createRule = (test, babelPlugins) => ({
115
+ test,
116
+ use: {
117
+ loader: "react-native-unistyles/repack-plugin",
118
+ options: {
119
+ babelPlugins,
120
+ unistylesPluginOptions
121
+ }
122
+ }
123
+ });
124
+ return {
125
+ exclude: excludePathLoader,
126
+ oneOf: [
127
+ createRule(/\.[cm]?ts$/, [["@babel/plugin-syntax-typescript", { isTSX: false, allowNamespaces: true }]]),
128
+ createRule(/\.[cm]?tsx$/, [["@babel/plugin-syntax-typescript", { isTSX: true, allowNamespaces: true }]]),
129
+ createRule(/\.[cm]?jsx?$/, ["babel-plugin-syntax-hermes-parser"])
130
+ ]
131
+ };
132
+ };
133
+ var RepackUnistylePlugin = class {
134
+ ruleExcludePaths;
135
+ unistylesPluginOptions;
136
+ constructor({ ruleExcludePaths = BASE_REPACK_EXCLUDE_PATHS, unistylesPluginOptions } = {}) {
137
+ this.ruleExcludePaths = ruleExcludePaths;
138
+ this.unistylesPluginOptions = unistylesPluginOptions;
139
+ }
140
+ apply(compiler) {
141
+ compiler.options.module.rules.push(getUnistyleModuleRules(this.ruleExcludePaths, this.unistylesPluginOptions));
142
+ }
143
+ };
144
+ var index_default = unistylesLoader;
145
+ // Annotate the CommonJS export names for ESM import in node:
146
+ 0 && (module.exports = {
147
+ BASE_REPACK_EXCLUDE_PATHS,
148
+ RepackUnistylePlugin
149
+ });
@@ -0,0 +1,34 @@
1
+ import React, { useLayoutEffect } from 'react'
2
+ import type { PropsWithChildren } from 'react'
3
+ import { useUnistyles } from '../core'
4
+ import type { UnistylesThemes } from '../global'
5
+ import { UnistylesShadowRegistry } from '../specs'
6
+ import { ApplyScopedTheme } from './ApplyScopedTheme'
7
+
8
+ interface AdaptiveThemeProps extends PropsWithChildren {
9
+ previousScopedTheme?: string
10
+ }
11
+
12
+ export const AdaptiveTheme: React.FunctionComponent<AdaptiveThemeProps> = ({
13
+ children,
14
+ previousScopedTheme
15
+ }) => {
16
+ const { rt } = useUnistyles()
17
+ const name = (rt.colorScheme === 'dark' ? 'light' : 'dark') as keyof UnistylesThemes
18
+ const mappedChildren = [
19
+ <ApplyScopedTheme key={name} name={name} />,
20
+ children,
21
+ <ApplyScopedTheme key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
22
+ ]
23
+
24
+ useLayoutEffect(() => {
25
+ // this will affect only scoped styles as other styles are not yet mounted
26
+ UnistylesShadowRegistry.flush()
27
+ })
28
+
29
+ return (
30
+ <React.Fragment key={name}>
31
+ {mappedChildren}
32
+ </React.Fragment>
33
+ )
34
+ }
@@ -0,0 +1,17 @@
1
+ import { useLayoutEffect } from 'react'
2
+ import type { UnistylesThemes } from '../global'
3
+ import { UnistylesShadowRegistry } from '../specs'
4
+
5
+ type ApplyScopedThemeProps = {
6
+ name?: keyof UnistylesThemes
7
+ }
8
+
9
+ export const ApplyScopedTheme: React.FunctionComponent<ApplyScopedThemeProps> = ({ name }) => {
10
+ UnistylesShadowRegistry.setScopedTheme(name)
11
+
12
+ useLayoutEffect(() => {
13
+ UnistylesShadowRegistry.setScopedTheme(name)
14
+ })
15
+
16
+ return null
17
+ }
@@ -0,0 +1,33 @@
1
+ import React, { useLayoutEffect } from 'react'
2
+ import type { PropsWithChildren } from 'react'
3
+ import type { UnistylesThemes } from '../global'
4
+ import { UnistylesShadowRegistry } from '../specs'
5
+ import { ApplyScopedTheme } from './ApplyScopedTheme'
6
+
7
+ interface NamedThemeProps extends PropsWithChildren {
8
+ name: keyof UnistylesThemes | undefined,
9
+ previousScopedTheme?: string
10
+ }
11
+
12
+ export const NamedTheme: React.FunctionComponent<NamedThemeProps> = ({
13
+ name,
14
+ children,
15
+ previousScopedTheme
16
+ }) => {
17
+ const mappedChildren = [
18
+ <ApplyScopedTheme key='apply' name={name} />,
19
+ children,
20
+ <ApplyScopedTheme key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
21
+ ]
22
+
23
+ useLayoutEffect(() => {
24
+ // this will affect only scoped styles as other styles are not yet mounted
25
+ UnistylesShadowRegistry.flush()
26
+ })
27
+
28
+ return (
29
+ <React.Fragment>
30
+ {mappedChildren}
31
+ </React.Fragment>
32
+ )
33
+ }
@@ -1,32 +1,59 @@
1
- import React, { useLayoutEffect } from 'react'
1
+ import React from 'react'
2
2
  import type { UnistylesThemes } from '../global'
3
- import { UnistylesShadowRegistry } from '../specs'
3
+ import { UnistylesRuntime, UnistylesShadowRegistry } from '../specs'
4
+ import { AdaptiveTheme } from './AdaptiveTheme'
5
+ import { NamedTheme } from './NamedTheme'
4
6
 
5
7
  type ThemeProps = {
6
- name: keyof UnistylesThemes
8
+ name: keyof UnistylesThemes,
9
+ invertedAdaptive?: never
10
+ reset?: never
11
+ } | {
12
+ name?: never,
13
+ invertedAdaptive: boolean,
14
+ reset?: never
15
+ } | {
16
+ name?: never,
17
+ invertedAdaptive?: never,
18
+ reset: boolean
7
19
  }
8
20
 
9
- const Apply = ({ name }: { name?: keyof UnistylesThemes }) => {
10
- UnistylesShadowRegistry.setScopedTheme(name)
11
-
12
- useLayoutEffect(() => {
13
- UnistylesShadowRegistry.setScopedTheme(name)
14
- })
15
-
16
- return null
17
- }
18
-
19
- export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({ name, children }) => {
21
+ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({
22
+ name,
23
+ children,
24
+ invertedAdaptive,
25
+ reset
26
+ }) => {
27
+ const hasAdaptiveThemes = UnistylesRuntime.hasAdaptiveThemes
28
+ const isAdaptiveTheme = invertedAdaptive && hasAdaptiveThemes
20
29
  const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
21
- const mappedChildren = [
22
- <Apply key={name} name={name} />,
23
- children,
24
- <Apply key='dispose' name={previousScopedTheme as keyof UnistylesThemes | undefined} />
25
- ]
26
30
 
27
- return (
28
- <React.Fragment>
29
- {mappedChildren}
30
- </React.Fragment>
31
- )
31
+ switch (true) {
32
+ case name !== undefined:
33
+ return (
34
+ <NamedTheme
35
+ name={name as keyof UnistylesThemes}
36
+ previousScopedTheme={previousScopedTheme}
37
+ >
38
+ {children}
39
+ </NamedTheme>
40
+ )
41
+ case isAdaptiveTheme:
42
+ return (
43
+ <AdaptiveTheme previousScopedTheme={previousScopedTheme}>
44
+ {children}
45
+ </AdaptiveTheme>
46
+ )
47
+ case reset:
48
+ return (
49
+ <NamedTheme
50
+ name={undefined}
51
+ previousScopedTheme={previousScopedTheme}
52
+ >
53
+ {children}
54
+ </NamedTheme>
55
+ )
56
+ default:
57
+ return children
58
+ }
32
59
  }
@@ -1,49 +1,39 @@
1
- import React, { useLayoutEffect, useRef } from 'react'
1
+ import React, { useRef } from 'react'
2
+ import type { ScrollView } from 'react-native'
2
3
  import { UnistylesShadowRegistry } from '../specs'
3
4
  import { copyComponentProperties } from '../utils'
4
5
  import { passForwardedRef } from './passForwardRef'
5
6
  import { maybeWarnAboutMultipleUnistyles } from './warn'
6
7
 
7
- const getNativeRef = (Component: any, ref: any) => {
8
- switch (Component.name) {
9
- case 'KeyboardAvoidingView':
10
- return ref.viewRef?.current
11
- case 'FlatList':
12
- return ref.getNativeScrollRef?.()
13
- case 'VirtualizedList':
14
- return ref.getScrollRef?.()
15
- default:
16
- return ref
17
- }
18
- }
19
-
20
8
  export const createUnistylesElement = (Component: any) => {
21
- const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
22
- const storedRef = useRef<unknown>(null)
23
-
24
- useLayoutEffect(() => {
25
- return () => {
26
- if (storedRef.current) {
27
- // @ts-ignore
28
- UnistylesShadowRegistry.remove(storedRef.current)
29
- }
30
- }
31
- }, [])
9
+ const UnistylesComponent = (props: any) => {
10
+ const scrollViewRef = useRef<ScrollView>(null)
32
11
 
33
12
  return (
34
13
  <Component
35
14
  {...props}
36
15
  ref={(ref: unknown) => {
37
- if (ref) {
38
- storedRef.current = getNativeRef(Component, ref)
16
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
17
+
18
+ // https://github.com/facebook/react-native/issues/51878
19
+ // tested with ScrollView, REA ScrolLView and Animated ScrollView
20
+ const isScrollView = Component.displayName === 'ScrollView'
21
+
22
+ if (isScrollView && ref) {
23
+ scrollViewRef.current = ref as ScrollView
39
24
  }
40
25
 
41
- // @ts-ignore we don't know the type of the component
42
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
26
+ if (isScrollView && !ref) {
27
+ // @ts-ignore this is hidden from TS
28
+ UnistylesShadowRegistry.remove(scrollViewRef.current)
29
+ scrollViewRef.current = null
30
+
31
+ return
32
+ }
43
33
 
44
34
  return passForwardedRef(
45
35
  ref,
46
- forwardedRef,
36
+ props.ref,
47
37
  () => {
48
38
  // @ts-ignore this is hidden from TS
49
39
  UnistylesShadowRegistry.add(ref, props.style)
@@ -56,7 +46,7 @@ export const createUnistylesElement = (Component: any) => {
56
46
  }}
57
47
  />
58
48
  )
59
- })
49
+ }
60
50
 
61
51
  return copyComponentProperties(Component, UnistylesComponent)
62
52
  }