react-native-unistyles 3.5.2 → 3.6.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 (317) hide show
  1. package/README.md +3 -0
  2. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +44 -7
  3. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +1 -1
  4. package/cxx/converters/BackgroundImageConverter.cpp +198 -11
  5. package/cxx/converters/BackgroundImageConverter.h +1 -0
  6. package/cxx/core/HostUnistyle.cpp +6 -0
  7. package/cxx/core/UnistylesRegistry.cpp +5 -5
  8. package/cxx/core/UnistylesRegistry.h +3 -3
  9. package/cxx/hybridObjects/HybridShadowRegistry.cpp +53 -14
  10. package/cxx/hybridObjects/HybridShadowRegistry.h +3 -2
  11. package/cxx/hybridObjects/HybridStyleSheet.cpp +3 -3
  12. package/cxx/parser/Parser.cpp +47 -9
  13. package/cxx/shadowTree/ShadowTreeManager.cpp +5 -5
  14. package/cxx/shadowTree/ShadowTreeManager.h +1 -1
  15. package/ios/NativePlatform+ios.swift +28 -15
  16. package/ios/NativePlatformListener+ios.swift +9 -0
  17. package/lib/commonjs/components/native/deep/ActivityIndicator.js +19 -0
  18. package/lib/commonjs/components/native/deep/ActivityIndicator.js.map +1 -0
  19. package/lib/commonjs/components/native/deep/Animated.js +19 -0
  20. package/lib/commonjs/components/native/deep/Animated.js.map +1 -0
  21. package/lib/commonjs/components/native/deep/FlatList.js +19 -0
  22. package/lib/commonjs/components/native/deep/FlatList.js.map +1 -0
  23. package/lib/commonjs/components/native/deep/Image.js +19 -0
  24. package/lib/commonjs/components/native/deep/Image.js.map +1 -0
  25. package/lib/commonjs/components/native/deep/ImageBackground.js +19 -0
  26. package/lib/commonjs/components/native/deep/ImageBackground.js.map +1 -0
  27. package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js +19 -0
  28. package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js.map +1 -0
  29. package/lib/commonjs/components/native/deep/Pressable.js +19 -0
  30. package/lib/commonjs/components/native/deep/Pressable.js.map +1 -0
  31. package/lib/commonjs/components/native/deep/RefreshControl.js +19 -0
  32. package/lib/commonjs/components/native/deep/RefreshControl.js.map +1 -0
  33. package/lib/commonjs/components/native/deep/SafeAreaView.js +19 -0
  34. package/lib/commonjs/components/native/deep/SafeAreaView.js.map +1 -0
  35. package/lib/commonjs/components/native/deep/ScrollView.js +19 -0
  36. package/lib/commonjs/components/native/deep/ScrollView.js.map +1 -0
  37. package/lib/commonjs/components/native/deep/SectionList.js +19 -0
  38. package/lib/commonjs/components/native/deep/SectionList.js.map +1 -0
  39. package/lib/commonjs/components/native/deep/Switch.js +19 -0
  40. package/lib/commonjs/components/native/deep/Switch.js.map +1 -0
  41. package/lib/commonjs/components/native/deep/Text.js +19 -0
  42. package/lib/commonjs/components/native/deep/Text.js.map +1 -0
  43. package/lib/commonjs/components/native/deep/TextInput.js +19 -0
  44. package/lib/commonjs/components/native/deep/TextInput.js.map +1 -0
  45. package/lib/commonjs/components/native/deep/TextNativeComponent.js +28 -0
  46. package/lib/commonjs/components/native/deep/TextNativeComponent.js.map +1 -0
  47. package/lib/commonjs/components/native/deep/TouchableHighlight.js +19 -0
  48. package/lib/commonjs/components/native/deep/TouchableHighlight.js.map +1 -0
  49. package/lib/commonjs/components/native/deep/TouchableOpacity.js +19 -0
  50. package/lib/commonjs/components/native/deep/TouchableOpacity.js.map +1 -0
  51. package/lib/commonjs/components/native/deep/View.js +19 -0
  52. package/lib/commonjs/components/native/deep/View.js.map +1 -0
  53. package/lib/commonjs/components/native/deep/ViewNativeComponent.js +26 -0
  54. package/lib/commonjs/components/native/deep/ViewNativeComponent.js.map +1 -0
  55. package/lib/commonjs/components/native/deep/VirtualizedList.js +19 -0
  56. package/lib/commonjs/components/native/deep/VirtualizedList.js.map +1 -0
  57. package/lib/commonjs/components/native/index.js +43 -0
  58. package/lib/commonjs/components/native/index.js.map +1 -0
  59. package/lib/commonjs/core/createUnistylesActivityIndicator.js +13 -3
  60. package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -1
  61. package/lib/commonjs/core/createUnistylesElement.native.js +6 -0
  62. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  63. package/lib/commonjs/core/createUnistylesImageBackground.js +20 -17
  64. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  65. package/lib/commonjs/core/createUnistylesTouchableHighlight.js +6 -0
  66. package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -1
  67. package/lib/commonjs/core/getClassname.js +15 -0
  68. package/lib/commonjs/core/getClassname.js.map +1 -1
  69. package/lib/commonjs/core/hasUnistyles.js +26 -0
  70. package/lib/commonjs/core/hasUnistyles.js.map +1 -0
  71. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +10 -0
  72. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  73. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +16 -15
  74. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  75. package/lib/commonjs/specs/ShadowRegistry/index.js +86 -110
  76. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  77. package/lib/commonjs/specs/ShadowRegistry/styleSource.js +65 -0
  78. package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -0
  79. package/lib/commonjs/unifiber/src/adapters/reanimated.js +157 -0
  80. package/lib/commonjs/unifiber/src/adapters/reanimated.js.map +1 -0
  81. package/lib/commonjs/unifiber/src/adapters/registry.js +67 -0
  82. package/lib/commonjs/unifiber/src/adapters/registry.js.map +1 -0
  83. package/lib/commonjs/unifiber/src/diagnostics.js +59 -0
  84. package/lib/commonjs/unifiber/src/diagnostics.js.map +1 -0
  85. package/lib/commonjs/unifiber/src/fiber.js +199 -0
  86. package/lib/commonjs/unifiber/src/fiber.js.map +1 -0
  87. package/lib/commonjs/unifiber/src/host.js +214 -0
  88. package/lib/commonjs/unifiber/src/host.js.map +1 -0
  89. package/lib/commonjs/unifiber/src/index.js +38 -0
  90. package/lib/commonjs/unifiber/src/index.js.map +1 -0
  91. package/lib/commonjs/web/css/core.js +30 -5
  92. package/lib/commonjs/web/css/core.js.map +1 -1
  93. package/lib/commonjs/web/css/state.js +4 -1
  94. package/lib/commonjs/web/css/state.js.map +1 -1
  95. package/lib/commonjs/web/registry.js +1 -1
  96. package/lib/commonjs/web/registry.js.map +1 -1
  97. package/lib/commonjs/web/utils/unistyle.js +11 -3
  98. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  99. package/lib/module/components/native/deep/ActivityIndicator.js +5 -0
  100. package/lib/module/components/native/deep/ActivityIndicator.js.map +1 -0
  101. package/lib/module/components/native/deep/Animated.js +5 -0
  102. package/lib/module/components/native/deep/Animated.js.map +1 -0
  103. package/lib/module/components/native/deep/FlatList.js +5 -0
  104. package/lib/module/components/native/deep/FlatList.js.map +1 -0
  105. package/lib/module/components/native/deep/Image.js +5 -0
  106. package/lib/module/components/native/deep/Image.js.map +1 -0
  107. package/lib/module/components/native/deep/ImageBackground.js +5 -0
  108. package/lib/module/components/native/deep/ImageBackground.js.map +1 -0
  109. package/lib/module/components/native/deep/KeyboardAvoidingView.js +5 -0
  110. package/lib/module/components/native/deep/KeyboardAvoidingView.js.map +1 -0
  111. package/lib/module/components/native/deep/Pressable.js +5 -0
  112. package/lib/module/components/native/deep/Pressable.js.map +1 -0
  113. package/lib/module/components/native/deep/RefreshControl.js +5 -0
  114. package/lib/module/components/native/deep/RefreshControl.js.map +1 -0
  115. package/lib/module/components/native/deep/SafeAreaView.js +5 -0
  116. package/lib/module/components/native/deep/SafeAreaView.js.map +1 -0
  117. package/lib/module/components/native/deep/ScrollView.js +5 -0
  118. package/lib/module/components/native/deep/ScrollView.js.map +1 -0
  119. package/lib/module/components/native/deep/SectionList.js +5 -0
  120. package/lib/module/components/native/deep/SectionList.js.map +1 -0
  121. package/lib/module/components/native/deep/Switch.js +5 -0
  122. package/lib/module/components/native/deep/Switch.js.map +1 -0
  123. package/lib/module/components/native/deep/Text.js +5 -0
  124. package/lib/module/components/native/deep/Text.js.map +1 -0
  125. package/lib/module/components/native/deep/TextInput.js +5 -0
  126. package/lib/module/components/native/deep/TextInput.js.map +1 -0
  127. package/lib/module/components/native/deep/TextNativeComponent.js +8 -0
  128. package/lib/module/components/native/deep/TextNativeComponent.js.map +1 -0
  129. package/lib/module/components/native/deep/TouchableHighlight.js +5 -0
  130. package/lib/module/components/native/deep/TouchableHighlight.js.map +1 -0
  131. package/lib/module/components/native/deep/TouchableOpacity.js +5 -0
  132. package/lib/module/components/native/deep/TouchableOpacity.js.map +1 -0
  133. package/lib/module/components/native/deep/View.js +5 -0
  134. package/lib/module/components/native/deep/View.js.map +1 -0
  135. package/lib/module/components/native/deep/ViewNativeComponent.js +8 -0
  136. package/lib/module/components/native/deep/ViewNativeComponent.js.map +1 -0
  137. package/lib/module/components/native/deep/VirtualizedList.js +5 -0
  138. package/lib/module/components/native/deep/VirtualizedList.js.map +1 -0
  139. package/lib/module/components/native/index.js +43 -0
  140. package/lib/module/components/native/index.js.map +1 -0
  141. package/lib/module/core/createUnistylesActivityIndicator.js +13 -3
  142. package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -1
  143. package/lib/module/core/createUnistylesElement.native.js +6 -0
  144. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  145. package/lib/module/core/createUnistylesImageBackground.js +20 -17
  146. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  147. package/lib/module/core/createUnistylesTouchableHighlight.js +6 -0
  148. package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -1
  149. package/lib/module/core/getClassname.js +16 -1
  150. package/lib/module/core/getClassname.js.map +1 -1
  151. package/lib/module/core/hasUnistyles.js +21 -0
  152. package/lib/module/core/hasUnistyles.js.map +1 -0
  153. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +10 -0
  154. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  155. package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -14
  156. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  157. package/lib/module/specs/ShadowRegistry/index.js +86 -110
  158. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  159. package/lib/module/specs/ShadowRegistry/styleSource.js +60 -0
  160. package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -0
  161. package/lib/module/unifiber/src/adapters/reanimated.js +152 -0
  162. package/lib/module/unifiber/src/adapters/reanimated.js.map +1 -0
  163. package/lib/module/unifiber/src/adapters/registry.js +62 -0
  164. package/lib/module/unifiber/src/adapters/registry.js.map +1 -0
  165. package/lib/module/unifiber/src/diagnostics.js +52 -0
  166. package/lib/module/unifiber/src/diagnostics.js.map +1 -0
  167. package/lib/module/unifiber/src/fiber.js +183 -0
  168. package/lib/module/unifiber/src/fiber.js.map +1 -0
  169. package/lib/module/unifiber/src/host.js +191 -0
  170. package/lib/module/unifiber/src/host.js.map +1 -0
  171. package/lib/module/unifiber/src/index.js +33 -0
  172. package/lib/module/unifiber/src/index.js.map +1 -0
  173. package/lib/module/web/css/core.js +28 -4
  174. package/lib/module/web/css/core.js.map +1 -1
  175. package/lib/module/web/css/state.js +5 -2
  176. package/lib/module/web/css/state.js.map +1 -1
  177. package/lib/module/web/registry.js +1 -1
  178. package/lib/module/web/registry.js.map +1 -1
  179. package/lib/module/web/utils/unistyle.js +11 -3
  180. package/lib/module/web/utils/unistyle.js.map +1 -1
  181. package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts +2 -0
  182. package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts.map +1 -0
  183. package/lib/typescript/src/components/native/deep/Animated.d.ts +2 -0
  184. package/lib/typescript/src/components/native/deep/Animated.d.ts.map +1 -0
  185. package/lib/typescript/src/components/native/deep/FlatList.d.ts +2 -0
  186. package/lib/typescript/src/components/native/deep/FlatList.d.ts.map +1 -0
  187. package/lib/typescript/src/components/native/deep/Image.d.ts +2 -0
  188. package/lib/typescript/src/components/native/deep/Image.d.ts.map +1 -0
  189. package/lib/typescript/src/components/native/deep/ImageBackground.d.ts +2 -0
  190. package/lib/typescript/src/components/native/deep/ImageBackground.d.ts.map +1 -0
  191. package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts +2 -0
  192. package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts.map +1 -0
  193. package/lib/typescript/src/components/native/deep/Pressable.d.ts +2 -0
  194. package/lib/typescript/src/components/native/deep/Pressable.d.ts.map +1 -0
  195. package/lib/typescript/src/components/native/deep/RefreshControl.d.ts +2 -0
  196. package/lib/typescript/src/components/native/deep/RefreshControl.d.ts.map +1 -0
  197. package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts +2 -0
  198. package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts.map +1 -0
  199. package/lib/typescript/src/components/native/deep/ScrollView.d.ts +2 -0
  200. package/lib/typescript/src/components/native/deep/ScrollView.d.ts.map +1 -0
  201. package/lib/typescript/src/components/native/deep/SectionList.d.ts +2 -0
  202. package/lib/typescript/src/components/native/deep/SectionList.d.ts.map +1 -0
  203. package/lib/typescript/src/components/native/deep/Switch.d.ts +2 -0
  204. package/lib/typescript/src/components/native/deep/Switch.d.ts.map +1 -0
  205. package/lib/typescript/src/components/native/deep/Text.d.ts +2 -0
  206. package/lib/typescript/src/components/native/deep/Text.d.ts.map +1 -0
  207. package/lib/typescript/src/components/native/deep/TextInput.d.ts +2 -0
  208. package/lib/typescript/src/components/native/deep/TextInput.d.ts.map +1 -0
  209. package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts +3 -0
  210. package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts.map +1 -0
  211. package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts +2 -0
  212. package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts.map +1 -0
  213. package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts +2 -0
  214. package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts.map +1 -0
  215. package/lib/typescript/src/components/native/deep/View.d.ts +2 -0
  216. package/lib/typescript/src/components/native/deep/View.d.ts.map +1 -0
  217. package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts +3 -0
  218. package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts.map +1 -0
  219. package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts +2 -0
  220. package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts.map +1 -0
  221. package/lib/typescript/src/components/native/index.d.ts +4 -0
  222. package/lib/typescript/src/components/native/index.d.ts.map +1 -0
  223. package/lib/typescript/src/components/scopeChildren.d.ts +1 -1
  224. package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -1
  225. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  226. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  227. package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -1
  228. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  229. package/lib/typescript/src/core/hasUnistyles.d.ts +2 -0
  230. package/lib/typescript/src/core/hasUnistyles.d.ts.map +1 -0
  231. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  232. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +6 -0
  233. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  234. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
  235. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  236. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts +11 -0
  237. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -0
  238. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +4 -41
  239. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  240. package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts +17 -0
  241. package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts.map +1 -0
  242. package/lib/typescript/src/unifiber/src/adapters/registry.d.ts +23 -0
  243. package/lib/typescript/src/unifiber/src/adapters/registry.d.ts.map +1 -0
  244. package/lib/typescript/src/unifiber/src/diagnostics.d.ts +10 -0
  245. package/lib/typescript/src/unifiber/src/diagnostics.d.ts.map +1 -0
  246. package/lib/typescript/src/unifiber/src/fiber.d.ts +48 -0
  247. package/lib/typescript/src/unifiber/src/fiber.d.ts.map +1 -0
  248. package/lib/typescript/src/unifiber/src/host.d.ts +32 -0
  249. package/lib/typescript/src/unifiber/src/host.d.ts.map +1 -0
  250. package/lib/typescript/src/unifiber/src/index.d.ts +49 -0
  251. package/lib/typescript/src/unifiber/src/index.d.ts.map +1 -0
  252. package/lib/typescript/src/web/css/core.d.ts +1 -0
  253. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  254. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  255. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  256. package/metro/babel-transformer.js +1040 -0
  257. package/metro/index.d.ts +31 -0
  258. package/metro/index.js +170 -0
  259. package/package.json +26 -8
  260. package/plugin/index.d.ts +7 -0
  261. package/plugin/index.js +36 -16
  262. package/src/components/native/deep/ActivityIndicator.ts +2 -0
  263. package/src/components/native/deep/Animated.ts +2 -0
  264. package/src/components/native/deep/FlatList.ts +2 -0
  265. package/src/components/native/deep/Image.ts +2 -0
  266. package/src/components/native/deep/ImageBackground.ts +2 -0
  267. package/src/components/native/deep/KeyboardAvoidingView.ts +2 -0
  268. package/src/components/native/deep/Pressable.ts +2 -0
  269. package/src/components/native/deep/RefreshControl.ts +2 -0
  270. package/src/components/native/deep/SafeAreaView.ts +2 -0
  271. package/src/components/native/deep/ScrollView.ts +2 -0
  272. package/src/components/native/deep/SectionList.ts +2 -0
  273. package/src/components/native/deep/Switch.ts +2 -0
  274. package/src/components/native/deep/Text.ts +2 -0
  275. package/src/components/native/deep/TextInput.ts +2 -0
  276. package/src/components/native/deep/TextNativeComponent.ts +5 -0
  277. package/src/components/native/deep/TouchableHighlight.ts +2 -0
  278. package/src/components/native/deep/TouchableOpacity.ts +2 -0
  279. package/src/components/native/deep/View.ts +2 -0
  280. package/src/components/native/deep/ViewNativeComponent.ts +5 -0
  281. package/src/components/native/deep/VirtualizedList.ts +2 -0
  282. package/src/components/native/index.ts +41 -0
  283. package/src/core/createUnistylesActivityIndicator.tsx +11 -4
  284. package/src/core/createUnistylesElement.native.tsx +5 -0
  285. package/src/core/createUnistylesImageBackground.tsx +27 -23
  286. package/src/core/createUnistylesTouchableHighlight.tsx +5 -0
  287. package/src/core/getClassname.ts +10 -1
  288. package/src/core/hasUnistyles.ts +20 -0
  289. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +11 -0
  290. package/src/core/withUnistyles/withUnistyles.native.tsx +22 -25
  291. package/src/specs/ShadowRegistry/index.ts +87 -149
  292. package/src/specs/ShadowRegistry/styleSource.ts +78 -0
  293. package/src/specs/ShadowRegistry/types.ts +3 -43
  294. package/src/unifiber/LICENSE +21 -0
  295. package/src/unifiber/README.md +92 -0
  296. package/src/unifiber/src/adapters/reanimated.ts +204 -0
  297. package/src/unifiber/src/adapters/registry.ts +102 -0
  298. package/src/unifiber/src/diagnostics.ts +55 -0
  299. package/src/unifiber/src/fiber.ts +262 -0
  300. package/src/unifiber/src/host.ts +236 -0
  301. package/src/unifiber/src/index.ts +43 -0
  302. package/src/web/css/core.ts +29 -4
  303. package/src/web/css/state.ts +6 -2
  304. package/src/web/registry.ts +1 -1
  305. package/src/web/utils/unistyle.ts +12 -3
  306. package/lib/typescript/src/__tests__/mocks.spec.d.ts +0 -2
  307. package/lib/typescript/src/__tests__/mocks.spec.d.ts.map +0 -1
  308. package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts +0 -2
  309. package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts.map +0 -1
  310. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts +0 -2
  311. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts.map +0 -1
  312. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts +0 -2
  313. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts.map +0 -1
  314. package/lib/typescript/src/__tests__/web-listener.spec.d.ts +0 -2
  315. package/lib/typescript/src/__tests__/web-listener.spec.d.ts.map +0 -1
  316. package/lib/typescript/src/__tests__/web-runtime.spec.d.ts +0 -2
  317. package/lib/typescript/src/__tests__/web-runtime.spec.d.ts.map +0 -1
@@ -5,6 +5,7 @@ import React, { useContext } from 'react'
5
5
  import { ScopedThemeContext } from '../components/ScopedThemeContext'
6
6
  import { UnistylesShadowRegistry } from '../specs'
7
7
  import { copyComponentProperties } from '../utils'
8
+ import { hasUnistyles } from './hasUnistyles'
8
9
  import { passForwardedRef } from './passForwardRef'
9
10
  import { maybeWarnAboutMultipleUnistyles } from './warn'
10
11
 
@@ -17,32 +18,35 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
17
18
  // @ts-ignore we don't know the type of the component
18
19
  maybeWarnAboutMultipleUnistyles(props.imageStyle, 'ImageBackground')
19
20
 
21
+ const linkRef = (ref: ImageBackground | null) => {
22
+ return passForwardedRef(
23
+ ref,
24
+ forwardedRef,
25
+ () => {
26
+ // @ts-expect-error - this is hidden from TS
27
+ UnistylesShadowRegistry.add(ref, props.style, scope)
28
+ },
29
+ () => {
30
+ // @ts-expect-error - this is hidden from TS
31
+ UnistylesShadowRegistry.remove(ref)
32
+ },
33
+ )
34
+ }
35
+ const linkImageRef = (ref: unknown) => {
36
+ // @ts-expect-error web types are not compatible with RN styles
37
+ UnistylesShadowRegistry.add(ref, props.imageStyle, scope)
38
+
39
+ return () => {
40
+ // @ts-ignore this is hidden from TS
41
+ UnistylesShadowRegistry.remove(ref)
42
+ }
43
+ }
44
+
20
45
  return (
21
46
  <Component
22
47
  {...props}
23
- ref={(ref) => {
24
- return passForwardedRef(
25
- ref,
26
- forwardedRef,
27
- () => {
28
- // @ts-expect-error - this is hidden from TS
29
- UnistylesShadowRegistry.add(ref, props.style, scope)
30
- },
31
- () => {
32
- // @ts-expect-error - this is hidden from TS
33
- UnistylesShadowRegistry.remove(ref)
34
- },
35
- )
36
- }}
37
- imageRef={(ref) => {
38
- // @ts-expect-error web types are not compatible with RN styles
39
- UnistylesShadowRegistry.add(ref, props.imageStyle, scope)
40
-
41
- return () => {
42
- // @ts-ignore this is hidden from TS
43
- UnistylesShadowRegistry.remove(ref)
44
- }
45
- }}
48
+ ref={hasUnistyles(props.style) ? linkRef : forwardedRef}
49
+ imageRef={hasUnistyles(props.imageStyle) ? linkImageRef : props.imageRef}
46
50
  />
47
51
  )
48
52
  })
@@ -5,6 +5,7 @@ import React, { useCallback, useContext, useLayoutEffect, useRef, useState } fro
5
5
  import { ScopedThemeContext } from '../components/ScopedThemeContext'
6
6
  import { UnistylesShadowRegistry } from '../specs'
7
7
  import { copyComponentProperties } from '../utils'
8
+ import { hasUnistyles } from './hasUnistyles'
8
9
  import { passForwardedRef } from './passForwardRef'
9
10
  import { maybeWarnAboutMultipleUnistyles } from './warn'
10
11
 
@@ -49,6 +50,10 @@ export const createUnistylesTouchableHighlight = (Component: typeof TouchableHig
49
50
  [props, scope],
50
51
  )
51
52
 
53
+ if (!hasUnistyles(props.style)) {
54
+ return <Component {...props} />
55
+ }
56
+
52
57
  return (
53
58
  <Component
54
59
  {...props}
@@ -1,7 +1,7 @@
1
1
  import type { UnistylesValues } from '../types'
2
2
 
3
3
  import * as unistyles from '../web/services'
4
- import { checkForAnimated } from '../web/utils'
4
+ import { checkForAnimated, isGeneratedUnistyle } from '../web/utils'
5
5
 
6
6
  export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>, forChild?: boolean) => {
7
7
  if (!unistyle) {
@@ -11,6 +11,15 @@ export const getClassName = (unistyle: UnistylesValues | undefined | Array<Unist
11
11
  const flattenedStyles = Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
12
12
  const animatedStyles = flattenedStyles.filter(checkForAnimated)
13
13
  const regularStyles = flattenedStyles.filter((style) => !checkForAnimated(style))
14
+ const [firstStyle, ...otherStyles] = regularStyles
15
+
16
+ // Already processed by an outer Unistyles component, e.g. createUnistylesElement(Animated.View),
17
+ // styles added after it (like Reanimated's initial animated values) stay inline
18
+ if (firstStyle && isGeneratedUnistyle(firstStyle) && firstStyle.hash) {
19
+ const { hash, injectedClassName } = firstStyle
20
+
21
+ return [{ $$css: true, hash, injectedClassName }, otherStyles.concat(animatedStyles)] as const
22
+ }
14
23
 
15
24
  const { hash, injectedClassName } = unistyles.services.shadowRegistry.addStyles(regularStyles, forChild)
16
25
 
@@ -0,0 +1,20 @@
1
+ // whether a style prop (also nested arrays) holds a unistyle, the only styles Unistyles updates
2
+ // a view without one renders like a React Native view, it never links
3
+ export const hasUnistyles = (style: unknown): boolean => {
4
+ if (Array.isArray(style)) {
5
+ return style.some(hasUnistyles)
6
+ }
7
+
8
+ if (!style || typeof style !== 'object') {
9
+ return false
10
+ }
11
+
12
+ // own keys only, like the registry. A unistyle starts with its `unistyles_` key, so it exits early
13
+ for (const key in style) {
14
+ if (key.startsWith('unistyles_') && Object.prototype.hasOwnProperty.call(style, key)) {
15
+ return true
16
+ }
17
+ }
18
+
19
+ return false
20
+ }
@@ -39,6 +39,7 @@ export const useProxifiedUnistyles = () => {
39
39
  const disposeRef = useRef<VoidFunction>(undefined)
40
40
  const syncedDependenciesSizeRef = useRef(-1)
41
41
  const syncedScopedThemeRef = useRef<UnistylesTheme | undefined>(undefined)
42
+ const wasDisposedRef = useRef(false)
42
43
 
43
44
  const reinitListener = () => {
44
45
  disposeRef.current?.()
@@ -59,12 +60,22 @@ export const useProxifiedUnistyles = () => {
59
60
  runtimeChanged()
60
61
  },
61
62
  })
63
+
64
+ // <Activity> cleans up effects, a theme change made while hidden was missed (#1297)
65
+ if (wasDisposedRef.current) {
66
+ wasDisposedRef.current = false
67
+
68
+ if (!scopedTheme) {
69
+ setTheme(UnistylesRuntime.getTheme())
70
+ }
71
+ }
62
72
  }
63
73
 
64
74
  useEffect(() => {
65
75
  return () => {
66
76
  disposeRef.current?.()
67
77
  syncedDependenciesSizeRef.current = -1
78
+ wasDisposedRef.current = true
68
79
  }
69
80
  }, [disposeRef])
70
81
 
@@ -31,6 +31,28 @@ type MappedSecrets = {
31
31
  dependencies: Array<UnistyleDependency>
32
32
  }
33
33
 
34
+ export const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
35
+ const styles = Array.isArray(styleProps) ? styleProps.flat(Infinity) : [styleProps]
36
+
37
+ const secrets: Array<UnistylesSecrets> = styles.filter(Boolean).reduce((acc, style) => {
38
+ const unistyleKey = Object.keys(style).find((key) => key.startsWith('unistyles_'))
39
+
40
+ return acc.concat([
41
+ unistyleKey
42
+ ? style[unistyleKey]
43
+ : {
44
+ uni__getStyles: () => style,
45
+ uni__dependencies: [],
46
+ },
47
+ ])
48
+ }, [])
49
+
50
+ return {
51
+ styles: secrets.reduce((acc, secret) => Object.assign(acc, secret.uni__getStyles()), {} as Record<string, any>),
52
+ dependencies: secrets.flatMap((secret) => secret.uni__dependencies),
53
+ }
54
+ }
55
+
34
56
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(
35
57
  Component: TComponent,
36
58
  mappings?: Mappings<TMappings>,
@@ -44,31 +66,6 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
44
66
  contentContainerStyle?: UnistylesValues
45
67
  }
46
68
 
47
- const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
48
- const styles = Array.isArray(styleProps) ? styleProps.flat() : [styleProps]
49
-
50
- const secrets: Array<UnistylesSecrets> = styles.filter(Boolean).reduce((acc, style) => {
51
- const unistyleKey = Object.keys(style).find((key) => key.startsWith('unistyles_'))
52
-
53
- return acc.concat([
54
- unistyleKey
55
- ? style[unistyleKey]
56
- : {
57
- uni__getStyles: () => style,
58
- uni__dependencies: [],
59
- },
60
- ])
61
- }, [])
62
-
63
- return {
64
- styles: secrets.reduce(
65
- (acc, secret) => Object.assign(acc, secret.uni__getStyles()),
66
- {} as Record<string, any>,
67
- ),
68
- dependencies: secrets.flatMap((secret) => secret.uni__dependencies),
69
- }
70
- }
71
-
72
69
  return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
73
70
  const narrowedProps = props as PropsWithUnistyles & UnistyleStyles
74
71
  const NativeComponent = Component as ComponentType
@@ -2,10 +2,13 @@ import { NitroModules } from 'react-native-nitro-modules'
2
2
 
3
3
  import type { Scope } from '../../components/ScopedThemeContext'
4
4
  import type { VerifyReport } from '../../diagnostics/types'
5
+ import type { Host } from '../../unifiber/src'
5
6
  import type { UnistylesShadowRegistry as UnistylesShadowRegistrySpec } from './ShadowRegistry.nitro'
6
7
  import type { ShadowNode, Unistyle, ViewHandle } from './types'
7
8
 
9
+ import { Fiber, Reanimated } from '../../unifiber/src'
8
10
  import { StyleSheet } from '../StyleSheet'
11
+ import { createUnistylesStyleSource } from './styleSource'
9
12
 
10
13
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
11
14
  // Babel API
@@ -19,175 +22,96 @@ interface ShadowRegistry extends UnistylesShadowRegistrySpec {
19
22
  setScopedTheme(themeName?: string): void
20
23
  getScopedTheme(): string | undefined
21
24
  verify(): VerifyReport
22
- takeCommittedTags(): Array<number>
25
+ takeCommittedInstanceHandles(): Array<any>
23
26
  refreshReactNodes(nodes: Array<ShadowNode>): void
24
27
  }
25
28
 
26
29
  const HybridShadowRegistry = NitroModules.createHybridObject<ShadowRegistry>('UnistylesShadowRegistry')
27
30
 
28
- const HOST_COMPONENT_TAG = 5
29
- const SUSPENSE_TAG = 13
30
- const OFFSCREEN_TAG = 22
31
+ const { collectVisibleAncestors, getHostFor, getHostForInstanceHandle, getShadowNode, getShadowNodes, isHidden } = Fiber
31
32
 
32
- const isInsideSuspendedBoundary = (fiber: any): boolean => {
33
- let current = fiber?.return
33
+ const { source: styleSource, bumpEpoch } = createUnistylesStyleSource({
34
+ get: () => HybridShadowRegistry.getScopedTheme(),
35
+ set: (name) => HybridShadowRegistry.setScopedTheme(name),
36
+ })
37
+ const owners = Fiber.createOwnerRegistry(styleSource, [Reanimated.cssAdapter], (reason) => {
38
+ console.warn(`Unistyles: ${reason}. CSS transitions won't follow theme changes.`)
39
+ })
34
40
 
35
- while (current) {
36
- if ((current.tag === SUSPENSE_TAG || current.tag === OFFSCREEN_TAG) && current.memoizedState !== null) {
37
- return true
38
- }
39
-
40
- current = current.return
41
- }
42
-
43
- return false
44
- }
45
-
46
- const findFiberForHandle = (handle: ViewHandle) => {
47
- return (
48
- handle?.__internalInstanceHandle ??
49
- handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle ??
50
- handle?.getNativeScrollRef?.()?.__internalInstanceHandle ??
51
- handle?._viewRef?.__internalInstanceHandle ??
52
- handle?.viewRef?.current?.__internalInstanceHandle ??
53
- handle?._nativeRef?.__internalInstanceHandle
54
- )
55
- }
56
-
57
- const findShadowNodeForHandle = (handle: ViewHandle) => {
58
- const node =
59
- handle?.__internalInstanceHandle?.stateNode?.node ??
60
- handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node ??
61
- handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node ??
62
- handle?._viewRef?.__internalInstanceHandle?.stateNode?.node ??
63
- handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node ??
64
- handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node
65
-
66
- // @ts-ignore we don't know the type of handle
67
- if (!node && handle?.props?.horizontal && handle?.constructor?.name === 'FlatList') {
68
- throw new Error(
69
- 'Unistyles: detected an unsupported FlatList with the horizontal prop. This will cause crashes on Android due to a bug in React Native core. Read more: https://github.com/facebook/react-native/issues/51601',
70
- )
71
- }
72
-
73
- return node
74
- }
75
-
76
- const getNativeTag = (handle: ViewHandle): number | undefined =>
77
- findFiberForHandle(handle)?.stateNode?.canonical?.nativeTag
78
-
79
- // by native tag, weak: views unmounted while frozen never unlink, their dead refs are dropped when the map doubles
80
- const linkedHandles = new Map<number, WeakRef<ViewHandle>>()
81
- const MIN_SWEEP_SIZE = 256
82
- let sweepSize = MIN_SWEEP_SIZE
83
-
84
- const sweepUnmountedHandles = () => {
85
- linkedHandles.forEach((ref, tag) => {
86
- if (!ref.deref()) {
87
- linkedHandles.delete(tag)
88
- }
89
- })
90
-
91
- sweepSize = Math.max(MIN_SWEEP_SIZE, linkedHandles.size * 2)
92
- }
93
-
94
- const trackHandle = (handle: ViewHandle) => {
95
- const tag = getNativeTag(handle)
96
-
97
- // views re-link on every render
98
- if (tag === undefined || linkedHandles.get(tag)?.deref() === handle) {
99
- return
100
- }
101
-
102
- linkedHandles.set(tag, new WeakRef(handle))
103
-
104
- if (linkedHandles.size >= sweepSize) {
105
- sweepUnmountedHandles()
106
- }
107
- }
41
+ // A component can point at another native view by the time its ref is cleaned up, eg. FlatList on Android remounts
42
+ // its native ScrollView when `horizontal` changes, so remove unlinks the view it was linked with
43
+ // The host points at its current node, while a stored node would keep its first revision (and children) alive
44
+ // Native views always resolve to their own host, so they skip it
45
+ const linkedHosts = new WeakMap<object, Host>()
108
46
 
109
- const untrackHandle = (handle: ViewHandle) => {
110
- const tag = getNativeTag(handle)
47
+ const committedHosts: Array<Host | undefined> = []
48
+ let refreshNodes: Array<ShadowNode> = []
111
49
 
112
- if (tag !== undefined && linkedHandles.get(tag)?.deref() === handle) {
113
- linkedHandles.delete(tag)
114
- }
50
+ const collectShadowNodes = (host: Host) => {
51
+ getShadowNodes(host, refreshNodes)
115
52
  }
116
53
 
117
54
  // React re-attaches an untouched subtree through its root's node and only follows clones made on the JS thread.
118
55
  // Once a node was cloned elsewhere (state updates, Reanimated), React would commit a subtree from before a Unistyles
119
56
  // update, so after a Unistyles commit the committed nodes and their host ancestors must point at the committed tree
120
57
  const refreshReactNodes = () => {
121
- const tags = HybridShadowRegistry.takeCommittedTags()
58
+ bumpEpoch()
59
+
60
+ const handles = HybridShadowRegistry.takeCommittedInstanceHandles()
122
61
 
123
- if (tags.length === 0) {
62
+ if (handles.length === 0) {
124
63
  return
125
64
  }
126
65
 
127
- const nodes = new Set<ShadowNode>()
128
- const visited = new Set<any>()
129
-
130
- for (const tag of tags) {
131
- const handle = linkedHandles.get(tag)?.deref()
132
-
133
- if (!handle) {
134
- continue
135
- }
136
-
137
- const fiber = findFiberForHandle(handle)
138
-
139
- // hidden by Suspense or a frozen screen
140
- if (!fiber || isInsideSuspendedBoundary(fiber)) {
141
- continue
66
+ try {
67
+ for (let i = 0; i < handles.length; i++) {
68
+ committedHosts[i] = getHostForInstanceHandle(handles[i])
142
69
  }
143
70
 
144
- for (let current: any = fiber; current && !visited.has(current); current = current.return) {
145
- visited.add(current)
146
-
147
- if (current.alternate) {
148
- visited.add(current.alternate)
149
- }
71
+ collectVisibleAncestors(committedHosts, collectShadowNodes)
150
72
 
151
- if (current.tag !== HOST_COMPONENT_TAG) {
152
- continue
153
- }
154
-
155
- for (const target of [current, current.alternate]) {
156
- const node = target?.stateNode?.node
157
-
158
- if (node) {
159
- nodes.add(node)
160
- }
161
- }
73
+ if (refreshNodes.length > 0) {
74
+ HybridShadowRegistry.refreshReactNodes(refreshNodes)
162
75
  }
163
- }
164
76
 
165
- if (nodes.size > 0) {
166
- HybridShadowRegistry.refreshReactNodes(Array.from(nodes))
77
+ owners.refresh(committedHosts)
78
+ } finally {
79
+ committedHosts.length = 0
80
+ refreshNodes = []
167
81
  }
168
82
  }
169
83
 
170
84
  StyleSheet.addChangeListener(refreshReactNodes)
171
85
 
172
- // runs for every style on every link, so it allocates only for the rare merged style (eg. flattened by Animated)
173
- const splitMergedUnistyles = (style: any) => {
174
- let hasUnistyle = false
86
+ // skips empty styles and splits a style merged from many unistyles (eg. flattened by Animated) into one per unistyle
87
+ // runs for every style on every link, so it reads the keys once and allocates only for the rare merged style
88
+ const collectStyle = (style: any, collected: Array<any>) => {
89
+ if (!style) {
90
+ return
91
+ }
92
+
93
+ const keys = Object.keys(style)
94
+ let unistylesCount = 0
175
95
 
176
- for (const key in style) {
177
- if (!key.startsWith('unistyles_') || !Object.prototype.hasOwnProperty.call(style, key)) {
178
- continue
96
+ for (const key of keys) {
97
+ if (key.startsWith('unistyles_')) {
98
+ unistylesCount++
179
99
  }
100
+ }
180
101
 
181
- if (hasUnistyle) {
182
- return Object.keys(style)
183
- .filter((unistyleKey) => unistyleKey.startsWith('unistyles_'))
184
- .map((unistyleKey) => ({ [unistyleKey]: style[unistyleKey] }))
102
+ if (unistylesCount < 2) {
103
+ if (keys.length > 0) {
104
+ collected.push(style)
185
105
  }
186
106
 
187
- hasUnistyle = true
107
+ return
188
108
  }
189
109
 
190
- return style
110
+ for (const key of keys) {
111
+ if (key.startsWith('unistyles_')) {
112
+ collected.push({ [key]: style[key] })
113
+ }
114
+ }
191
115
  }
192
116
 
193
117
  HybridShadowRegistry.add = (handle, styles, scope) => {
@@ -196,18 +120,19 @@ HybridShadowRegistry.add = (handle, styles, scope) => {
196
120
  return
197
121
  }
198
122
 
199
- const stylesArray = Array.isArray(styles) ? styles.flat(Infinity) : [styles]
123
+ const filteredStyles: Array<any> = []
200
124
 
201
- // filter styles that are undefined or with no keys
202
- const filteredStyles = stylesArray
203
- .filter((style) => style && Object.keys(style).length > 0)
204
- .filter(Boolean)
205
- .flatMap(splitMergedUnistyles)
125
+ if (Array.isArray(styles)) {
126
+ styles.flat(Infinity).forEach((style) => collectStyle(style, filteredStyles))
127
+ } else {
128
+ collectStyle(styles, filteredStyles)
129
+ }
206
130
 
207
131
  if (filteredStyles.length > 0) {
208
- const node = findShadowNodeForHandle(handle)
132
+ const host = getHostFor(handle)
133
+ const node = host && getShadowNode(host)
209
134
 
210
- if (!node) {
135
+ if (!host || !node) {
211
136
  throw new Error(
212
137
  `Unistyles: Could not find shadow node for one of your components of type ${handle?.constructor?.name ?? 'unknown'}`,
213
138
  )
@@ -221,12 +146,15 @@ HybridShadowRegistry.add = (handle, styles, scope) => {
221
146
  }
222
147
 
223
148
  HybridShadowRegistry.link(node, filteredStyles)
149
+ owners.link(host)
150
+
151
+ if (!handle.__internalInstanceHandle) {
152
+ linkedHosts.set(handle, host)
153
+ }
224
154
 
225
155
  if (scope) {
226
156
  HybridShadowRegistry.setScopedTheme(previousScopedTheme)
227
157
  }
228
-
229
- trackHandle(handle)
230
158
  }
231
159
  }
232
160
 
@@ -235,20 +163,30 @@ HybridShadowRegistry.remove = (handle) => {
235
163
  return
236
164
  }
237
165
 
238
- const maybeNode = findShadowNodeForHandle(handle)
166
+ const linkedHost = handle.__internalInstanceHandle ? undefined : linkedHosts.get(handle)
167
+ const host = linkedHost ?? getHostFor(handle)
168
+ const maybeNode = host && getShadowNode(host)
239
169
 
240
- if (maybeNode) {
241
- const fiber = findFiberForHandle(handle)
170
+ if (linkedHost) {
171
+ linkedHosts.delete(handle)
172
+ }
242
173
 
243
- if (fiber && isInsideSuspendedBoundary(fiber)) {
174
+ if (host && maybeNode) {
175
+ if (isHidden(host)) {
244
176
  HybridShadowRegistry.suspend(maybeNode)
245
177
  } else {
246
178
  HybridShadowRegistry.unlink(maybeNode)
247
- untrackHandle(handle)
248
179
  }
249
180
  }
250
181
  }
251
182
 
252
- type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink' | 'suspend' | 'takeCommittedTags' | 'refreshReactNodes'
183
+ type PrivateMethods =
184
+ | 'add'
185
+ | 'remove'
186
+ | 'link'
187
+ | 'unlink'
188
+ | 'suspend'
189
+ | 'takeCommittedInstanceHandles'
190
+ | 'refreshReactNodes'
253
191
 
254
192
  export const UnistylesShadowRegistry = HybridShadowRegistry as Omit<ShadowRegistry, PrivateMethods>
@@ -0,0 +1,78 @@
1
+ import type { Scope } from '../../components/ScopedThemeContext'
2
+ import type { StyleSource } from '../../unifiber/src'
3
+
4
+ import { ScopedThemeContext } from '../../components/ScopedThemeContext'
5
+
6
+ type ScopedThemeAccess = {
7
+ get(): string | undefined
8
+ set(name: string | undefined): void
9
+ }
10
+
11
+ export const createUnistylesStyleSource = (scopedTheme: ScopedThemeAccess) => {
12
+ let epoch = 0
13
+ let warned = false
14
+
15
+ const source: StyleSource = {
16
+ name: 'unistyles',
17
+ epoch: () => epoch,
18
+ contexts: [ScopedThemeContext],
19
+ contextKey: (_context, scope) => (scope as Scope | null)?.name,
20
+ resolve: (props, read) => {
21
+ try {
22
+ return resolveFresh(props, read(ScopedThemeContext))
23
+ } catch (error) {
24
+ if (!warned) {
25
+ warned = true
26
+ console.warn(`Unistyles: Could not refresh styles for a CSS transition. ${String(error)}`)
27
+ }
28
+
29
+ return undefined
30
+ }
31
+ },
32
+ }
33
+
34
+ const resolveFresh = (props: Record<string, any>, scope: Scope | null | undefined) => {
35
+ const styles = [props.style].flat(Infinity)
36
+ const fresh: Record<string, unknown> = {}
37
+ let hasUnistyles = false
38
+
39
+ for (const style of styles) {
40
+ if (!style || typeof style !== 'object') {
41
+ continue
42
+ }
43
+
44
+ Object.assign(fresh, style)
45
+
46
+ for (const key in style) {
47
+ if (!key.startsWith('unistyles_') || !Object.prototype.hasOwnProperty.call(style, key)) {
48
+ continue
49
+ }
50
+
51
+ hasUnistyles = true
52
+
53
+ const previousScopedTheme = scope ? scopedTheme.get() : undefined
54
+
55
+ if (scope) {
56
+ scopedTheme.set(scope.name)
57
+ }
58
+
59
+ try {
60
+ Object.assign(fresh, style[key]?.uni__getStyles?.())
61
+ } finally {
62
+ if (scope) {
63
+ scopedTheme.set(previousScopedTheme)
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ return hasUnistyles ? fresh : undefined
70
+ }
71
+
72
+ return {
73
+ source,
74
+ bumpEpoch: () => {
75
+ epoch++
76
+ },
77
+ }
78
+ }
@@ -1,48 +1,8 @@
1
- export type StateNode = {
2
- node?: ShadowNode
3
- canonical?: {
4
- nativeTag?: number
5
- }
6
- }
7
-
8
- export type ShadowNode = {
9
- __hostObjectShadowNodeWrapper: any
10
- }
1
+ export type { ShadowNode } from '../../unifiber/src'
11
2
 
12
3
  export type ViewHandle = {
13
- __internalInstanceHandle?: {
14
- stateNode?: StateNode
15
- elementType?: string
16
- }
17
- getScrollResponder?: () => {
18
- getNativeScrollRef?: () => {
19
- __internalInstanceHandle?: {
20
- stateNode?: StateNode
21
- }
22
- }
23
- }
24
- getNativeScrollRef?: () => {
25
- __internalInstanceHandle?: {
26
- stateNode?: StateNode
27
- }
28
- }
29
- _viewRef?: {
30
- __internalInstanceHandle?: {
31
- stateNode?: StateNode
32
- }
33
- }
34
- viewRef?: {
35
- current?: {
36
- __internalInstanceHandle?: {
37
- stateNode?: StateNode
38
- }
39
- }
40
- }
41
- _nativeRef?: {
42
- __internalInstanceHandle?: {
43
- stateNode?: StateNode
44
- }
45
- }
4
+ __internalInstanceHandle?: unknown
5
+ constructor?: { name?: string }
46
6
  }
47
7
 
48
8
  export type Unistyle = {