react-native-unistyles 3.5.3 → 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 (283) hide show
  1. package/README.md +3 -0
  2. package/cxx/converters/BackgroundImageConverter.cpp +198 -11
  3. package/cxx/converters/BackgroundImageConverter.h +1 -0
  4. package/cxx/core/HostUnistyle.cpp +6 -0
  5. package/cxx/hybridObjects/HybridShadowRegistry.cpp +5 -0
  6. package/cxx/parser/Parser.cpp +29 -7
  7. package/ios/NativePlatform+ios.swift +22 -11
  8. package/ios/NativePlatformListener+ios.swift +9 -0
  9. package/lib/commonjs/components/native/deep/ActivityIndicator.js +19 -0
  10. package/lib/commonjs/components/native/deep/ActivityIndicator.js.map +1 -0
  11. package/lib/commonjs/components/native/deep/Animated.js +19 -0
  12. package/lib/commonjs/components/native/deep/Animated.js.map +1 -0
  13. package/lib/commonjs/components/native/deep/FlatList.js +19 -0
  14. package/lib/commonjs/components/native/deep/FlatList.js.map +1 -0
  15. package/lib/commonjs/components/native/deep/Image.js +19 -0
  16. package/lib/commonjs/components/native/deep/Image.js.map +1 -0
  17. package/lib/commonjs/components/native/deep/ImageBackground.js +19 -0
  18. package/lib/commonjs/components/native/deep/ImageBackground.js.map +1 -0
  19. package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js +19 -0
  20. package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js.map +1 -0
  21. package/lib/commonjs/components/native/deep/Pressable.js +19 -0
  22. package/lib/commonjs/components/native/deep/Pressable.js.map +1 -0
  23. package/lib/commonjs/components/native/deep/RefreshControl.js +19 -0
  24. package/lib/commonjs/components/native/deep/RefreshControl.js.map +1 -0
  25. package/lib/commonjs/components/native/deep/SafeAreaView.js +19 -0
  26. package/lib/commonjs/components/native/deep/SafeAreaView.js.map +1 -0
  27. package/lib/commonjs/components/native/deep/ScrollView.js +19 -0
  28. package/lib/commonjs/components/native/deep/ScrollView.js.map +1 -0
  29. package/lib/commonjs/components/native/deep/SectionList.js +19 -0
  30. package/lib/commonjs/components/native/deep/SectionList.js.map +1 -0
  31. package/lib/commonjs/components/native/deep/Switch.js +19 -0
  32. package/lib/commonjs/components/native/deep/Switch.js.map +1 -0
  33. package/lib/commonjs/components/native/deep/Text.js +19 -0
  34. package/lib/commonjs/components/native/deep/Text.js.map +1 -0
  35. package/lib/commonjs/components/native/deep/TextInput.js +19 -0
  36. package/lib/commonjs/components/native/deep/TextInput.js.map +1 -0
  37. package/lib/commonjs/components/native/deep/TextNativeComponent.js +28 -0
  38. package/lib/commonjs/components/native/deep/TextNativeComponent.js.map +1 -0
  39. package/lib/commonjs/components/native/deep/TouchableHighlight.js +19 -0
  40. package/lib/commonjs/components/native/deep/TouchableHighlight.js.map +1 -0
  41. package/lib/commonjs/components/native/deep/TouchableOpacity.js +19 -0
  42. package/lib/commonjs/components/native/deep/TouchableOpacity.js.map +1 -0
  43. package/lib/commonjs/components/native/deep/View.js +19 -0
  44. package/lib/commonjs/components/native/deep/View.js.map +1 -0
  45. package/lib/commonjs/components/native/deep/ViewNativeComponent.js +26 -0
  46. package/lib/commonjs/components/native/deep/ViewNativeComponent.js.map +1 -0
  47. package/lib/commonjs/components/native/deep/VirtualizedList.js +19 -0
  48. package/lib/commonjs/components/native/deep/VirtualizedList.js.map +1 -0
  49. package/lib/commonjs/components/native/index.js +43 -0
  50. package/lib/commonjs/components/native/index.js.map +1 -0
  51. package/lib/commonjs/core/createUnistylesActivityIndicator.js +13 -3
  52. package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -1
  53. package/lib/commonjs/core/createUnistylesElement.native.js +6 -0
  54. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  55. package/lib/commonjs/core/createUnistylesImageBackground.js +20 -17
  56. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  57. package/lib/commonjs/core/createUnistylesTouchableHighlight.js +6 -0
  58. package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -1
  59. package/lib/commonjs/core/getClassname.js +15 -0
  60. package/lib/commonjs/core/getClassname.js.map +1 -1
  61. package/lib/commonjs/core/hasUnistyles.js +26 -0
  62. package/lib/commonjs/core/hasUnistyles.js.map +1 -0
  63. package/lib/commonjs/specs/ShadowRegistry/index.js +57 -74
  64. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  65. package/lib/commonjs/specs/ShadowRegistry/styleSource.js +65 -0
  66. package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -0
  67. package/lib/commonjs/unifiber/src/adapters/reanimated.js +157 -0
  68. package/lib/commonjs/unifiber/src/adapters/reanimated.js.map +1 -0
  69. package/lib/commonjs/unifiber/src/adapters/registry.js +67 -0
  70. package/lib/commonjs/unifiber/src/adapters/registry.js.map +1 -0
  71. package/lib/commonjs/unifiber/src/diagnostics.js +59 -0
  72. package/lib/commonjs/unifiber/src/diagnostics.js.map +1 -0
  73. package/lib/commonjs/unifiber/src/fiber.js +199 -0
  74. package/lib/commonjs/unifiber/src/fiber.js.map +1 -0
  75. package/lib/commonjs/unifiber/src/host.js +214 -0
  76. package/lib/commonjs/unifiber/src/host.js.map +1 -0
  77. package/lib/commonjs/unifiber/src/index.js +38 -0
  78. package/lib/commonjs/unifiber/src/index.js.map +1 -0
  79. package/lib/commonjs/web/utils/unistyle.js +11 -3
  80. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  81. package/lib/module/components/native/deep/ActivityIndicator.js +5 -0
  82. package/lib/module/components/native/deep/ActivityIndicator.js.map +1 -0
  83. package/lib/module/components/native/deep/Animated.js +5 -0
  84. package/lib/module/components/native/deep/Animated.js.map +1 -0
  85. package/lib/module/components/native/deep/FlatList.js +5 -0
  86. package/lib/module/components/native/deep/FlatList.js.map +1 -0
  87. package/lib/module/components/native/deep/Image.js +5 -0
  88. package/lib/module/components/native/deep/Image.js.map +1 -0
  89. package/lib/module/components/native/deep/ImageBackground.js +5 -0
  90. package/lib/module/components/native/deep/ImageBackground.js.map +1 -0
  91. package/lib/module/components/native/deep/KeyboardAvoidingView.js +5 -0
  92. package/lib/module/components/native/deep/KeyboardAvoidingView.js.map +1 -0
  93. package/lib/module/components/native/deep/Pressable.js +5 -0
  94. package/lib/module/components/native/deep/Pressable.js.map +1 -0
  95. package/lib/module/components/native/deep/RefreshControl.js +5 -0
  96. package/lib/module/components/native/deep/RefreshControl.js.map +1 -0
  97. package/lib/module/components/native/deep/SafeAreaView.js +5 -0
  98. package/lib/module/components/native/deep/SafeAreaView.js.map +1 -0
  99. package/lib/module/components/native/deep/ScrollView.js +5 -0
  100. package/lib/module/components/native/deep/ScrollView.js.map +1 -0
  101. package/lib/module/components/native/deep/SectionList.js +5 -0
  102. package/lib/module/components/native/deep/SectionList.js.map +1 -0
  103. package/lib/module/components/native/deep/Switch.js +5 -0
  104. package/lib/module/components/native/deep/Switch.js.map +1 -0
  105. package/lib/module/components/native/deep/Text.js +5 -0
  106. package/lib/module/components/native/deep/Text.js.map +1 -0
  107. package/lib/module/components/native/deep/TextInput.js +5 -0
  108. package/lib/module/components/native/deep/TextInput.js.map +1 -0
  109. package/lib/module/components/native/deep/TextNativeComponent.js +8 -0
  110. package/lib/module/components/native/deep/TextNativeComponent.js.map +1 -0
  111. package/lib/module/components/native/deep/TouchableHighlight.js +5 -0
  112. package/lib/module/components/native/deep/TouchableHighlight.js.map +1 -0
  113. package/lib/module/components/native/deep/TouchableOpacity.js +5 -0
  114. package/lib/module/components/native/deep/TouchableOpacity.js.map +1 -0
  115. package/lib/module/components/native/deep/View.js +5 -0
  116. package/lib/module/components/native/deep/View.js.map +1 -0
  117. package/lib/module/components/native/deep/ViewNativeComponent.js +8 -0
  118. package/lib/module/components/native/deep/ViewNativeComponent.js.map +1 -0
  119. package/lib/module/components/native/deep/VirtualizedList.js +5 -0
  120. package/lib/module/components/native/deep/VirtualizedList.js.map +1 -0
  121. package/lib/module/components/native/index.js +43 -0
  122. package/lib/module/components/native/index.js.map +1 -0
  123. package/lib/module/core/createUnistylesActivityIndicator.js +13 -3
  124. package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -1
  125. package/lib/module/core/createUnistylesElement.native.js +6 -0
  126. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  127. package/lib/module/core/createUnistylesImageBackground.js +20 -17
  128. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  129. package/lib/module/core/createUnistylesTouchableHighlight.js +6 -0
  130. package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -1
  131. package/lib/module/core/getClassname.js +16 -1
  132. package/lib/module/core/getClassname.js.map +1 -1
  133. package/lib/module/core/hasUnistyles.js +21 -0
  134. package/lib/module/core/hasUnistyles.js.map +1 -0
  135. package/lib/module/specs/ShadowRegistry/index.js +57 -74
  136. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  137. package/lib/module/specs/ShadowRegistry/styleSource.js +60 -0
  138. package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -0
  139. package/lib/module/unifiber/src/adapters/reanimated.js +152 -0
  140. package/lib/module/unifiber/src/adapters/reanimated.js.map +1 -0
  141. package/lib/module/unifiber/src/adapters/registry.js +62 -0
  142. package/lib/module/unifiber/src/adapters/registry.js.map +1 -0
  143. package/lib/module/unifiber/src/diagnostics.js +52 -0
  144. package/lib/module/unifiber/src/diagnostics.js.map +1 -0
  145. package/lib/module/unifiber/src/fiber.js +183 -0
  146. package/lib/module/unifiber/src/fiber.js.map +1 -0
  147. package/lib/module/unifiber/src/host.js +191 -0
  148. package/lib/module/unifiber/src/host.js.map +1 -0
  149. package/lib/module/unifiber/src/index.js +33 -0
  150. package/lib/module/unifiber/src/index.js.map +1 -0
  151. package/lib/module/web/utils/unistyle.js +11 -3
  152. package/lib/module/web/utils/unistyle.js.map +1 -1
  153. package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts +2 -0
  154. package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts.map +1 -0
  155. package/lib/typescript/src/components/native/deep/Animated.d.ts +2 -0
  156. package/lib/typescript/src/components/native/deep/Animated.d.ts.map +1 -0
  157. package/lib/typescript/src/components/native/deep/FlatList.d.ts +2 -0
  158. package/lib/typescript/src/components/native/deep/FlatList.d.ts.map +1 -0
  159. package/lib/typescript/src/components/native/deep/Image.d.ts +2 -0
  160. package/lib/typescript/src/components/native/deep/Image.d.ts.map +1 -0
  161. package/lib/typescript/src/components/native/deep/ImageBackground.d.ts +2 -0
  162. package/lib/typescript/src/components/native/deep/ImageBackground.d.ts.map +1 -0
  163. package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts +2 -0
  164. package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts.map +1 -0
  165. package/lib/typescript/src/components/native/deep/Pressable.d.ts +2 -0
  166. package/lib/typescript/src/components/native/deep/Pressable.d.ts.map +1 -0
  167. package/lib/typescript/src/components/native/deep/RefreshControl.d.ts +2 -0
  168. package/lib/typescript/src/components/native/deep/RefreshControl.d.ts.map +1 -0
  169. package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts +2 -0
  170. package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts.map +1 -0
  171. package/lib/typescript/src/components/native/deep/ScrollView.d.ts +2 -0
  172. package/lib/typescript/src/components/native/deep/ScrollView.d.ts.map +1 -0
  173. package/lib/typescript/src/components/native/deep/SectionList.d.ts +2 -0
  174. package/lib/typescript/src/components/native/deep/SectionList.d.ts.map +1 -0
  175. package/lib/typescript/src/components/native/deep/Switch.d.ts +2 -0
  176. package/lib/typescript/src/components/native/deep/Switch.d.ts.map +1 -0
  177. package/lib/typescript/src/components/native/deep/Text.d.ts +2 -0
  178. package/lib/typescript/src/components/native/deep/Text.d.ts.map +1 -0
  179. package/lib/typescript/src/components/native/deep/TextInput.d.ts +2 -0
  180. package/lib/typescript/src/components/native/deep/TextInput.d.ts.map +1 -0
  181. package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts +3 -0
  182. package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts.map +1 -0
  183. package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts +2 -0
  184. package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts.map +1 -0
  185. package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts +2 -0
  186. package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts.map +1 -0
  187. package/lib/typescript/src/components/native/deep/View.d.ts +2 -0
  188. package/lib/typescript/src/components/native/deep/View.d.ts.map +1 -0
  189. package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts +3 -0
  190. package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts.map +1 -0
  191. package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts +2 -0
  192. package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts.map +1 -0
  193. package/lib/typescript/src/components/native/index.d.ts +4 -0
  194. package/lib/typescript/src/components/native/index.d.ts.map +1 -0
  195. package/lib/typescript/src/components/scopeChildren.d.ts +1 -1
  196. package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -1
  197. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  198. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  199. package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -1
  200. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  201. package/lib/typescript/src/core/hasUnistyles.d.ts +2 -0
  202. package/lib/typescript/src/core/hasUnistyles.d.ts.map +1 -0
  203. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  204. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts +11 -0
  205. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -0
  206. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +4 -41
  207. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  208. package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts +17 -0
  209. package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts.map +1 -0
  210. package/lib/typescript/src/unifiber/src/adapters/registry.d.ts +23 -0
  211. package/lib/typescript/src/unifiber/src/adapters/registry.d.ts.map +1 -0
  212. package/lib/typescript/src/unifiber/src/diagnostics.d.ts +10 -0
  213. package/lib/typescript/src/unifiber/src/diagnostics.d.ts.map +1 -0
  214. package/lib/typescript/src/unifiber/src/fiber.d.ts +48 -0
  215. package/lib/typescript/src/unifiber/src/fiber.d.ts.map +1 -0
  216. package/lib/typescript/src/unifiber/src/host.d.ts +32 -0
  217. package/lib/typescript/src/unifiber/src/host.d.ts.map +1 -0
  218. package/lib/typescript/src/unifiber/src/index.d.ts +49 -0
  219. package/lib/typescript/src/unifiber/src/index.d.ts.map +1 -0
  220. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  221. package/metro/babel-transformer.js +1040 -0
  222. package/metro/index.d.ts +31 -0
  223. package/metro/index.js +170 -0
  224. package/package.json +26 -8
  225. package/plugin/index.d.ts +7 -0
  226. package/plugin/index.js +36 -16
  227. package/src/components/native/deep/ActivityIndicator.ts +2 -0
  228. package/src/components/native/deep/Animated.ts +2 -0
  229. package/src/components/native/deep/FlatList.ts +2 -0
  230. package/src/components/native/deep/Image.ts +2 -0
  231. package/src/components/native/deep/ImageBackground.ts +2 -0
  232. package/src/components/native/deep/KeyboardAvoidingView.ts +2 -0
  233. package/src/components/native/deep/Pressable.ts +2 -0
  234. package/src/components/native/deep/RefreshControl.ts +2 -0
  235. package/src/components/native/deep/SafeAreaView.ts +2 -0
  236. package/src/components/native/deep/ScrollView.ts +2 -0
  237. package/src/components/native/deep/SectionList.ts +2 -0
  238. package/src/components/native/deep/Switch.ts +2 -0
  239. package/src/components/native/deep/Text.ts +2 -0
  240. package/src/components/native/deep/TextInput.ts +2 -0
  241. package/src/components/native/deep/TextNativeComponent.ts +5 -0
  242. package/src/components/native/deep/TouchableHighlight.ts +2 -0
  243. package/src/components/native/deep/TouchableOpacity.ts +2 -0
  244. package/src/components/native/deep/View.ts +2 -0
  245. package/src/components/native/deep/ViewNativeComponent.ts +5 -0
  246. package/src/components/native/deep/VirtualizedList.ts +2 -0
  247. package/src/components/native/index.ts +41 -0
  248. package/src/core/createUnistylesActivityIndicator.tsx +11 -4
  249. package/src/core/createUnistylesElement.native.tsx +5 -0
  250. package/src/core/createUnistylesImageBackground.tsx +27 -23
  251. package/src/core/createUnistylesTouchableHighlight.tsx +5 -0
  252. package/src/core/getClassname.ts +10 -1
  253. package/src/core/hasUnistyles.ts +20 -0
  254. package/src/specs/ShadowRegistry/index.ts +50 -102
  255. package/src/specs/ShadowRegistry/styleSource.ts +78 -0
  256. package/src/specs/ShadowRegistry/types.ts +3 -43
  257. package/src/unifiber/LICENSE +21 -0
  258. package/src/unifiber/README.md +92 -0
  259. package/src/unifiber/src/adapters/reanimated.ts +204 -0
  260. package/src/unifiber/src/adapters/registry.ts +102 -0
  261. package/src/unifiber/src/diagnostics.ts +55 -0
  262. package/src/unifiber/src/fiber.ts +262 -0
  263. package/src/unifiber/src/host.ts +236 -0
  264. package/src/unifiber/src/index.ts +43 -0
  265. package/src/web/utils/unistyle.ts +12 -3
  266. package/lib/typescript/src/__tests__/mocks.spec.d.ts +0 -2
  267. package/lib/typescript/src/__tests__/mocks.spec.d.ts.map +0 -1
  268. package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts +0 -2
  269. package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts.map +0 -1
  270. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts +0 -2
  271. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts.map +0 -1
  272. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts +0 -2
  273. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts.map +0 -1
  274. package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts +0 -2
  275. package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts.map +0 -1
  276. package/lib/typescript/src/__tests__/web-listener.spec.d.ts +0 -2
  277. package/lib/typescript/src/__tests__/web-listener.spec.d.ts.map +0 -1
  278. package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts +0 -2
  279. package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts.map +0 -1
  280. package/lib/typescript/src/__tests__/web-runtime.spec.d.ts +0 -2
  281. package/lib/typescript/src/__tests__/web-runtime.spec.d.ts.map +0 -1
  282. package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts +0 -2
  283. package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts.map +0 -1
@@ -0,0 +1,31 @@
1
+ type MetroConfig = {
2
+ transformer?: {
3
+ babelTransformerPath?: string
4
+ }
5
+ resolver?: {
6
+ resolveRequest?: ((...args: Array<any>) => any) | null
7
+ }
8
+ }
9
+
10
+ export interface UnistylesMetroOptions {
11
+ /**
12
+ * Logs the dependencies detected in every StyleSheet, same as the `debug` option of the Babel plugin
13
+ */
14
+ debug?: boolean
15
+ }
16
+
17
+ /**
18
+ * Experimental, replaces `react-native-unistyles/plugin` in babel.config.js
19
+ *
20
+ * Every `react-native` import (also from node_modules) resolves to Unistyles components
21
+ * and StyleSheets are processed by the Unistyles Babel plugin, run by Metro.
22
+ * There is nothing to configure: no `root`, `autoProcessImports`, `autoProcessPaths` or `autoRemapImports`.
23
+ *
24
+ * ```js
25
+ * const { getDefaultConfig } = require('expo/metro-config')
26
+ * const { withUnistylesConfig } = require('react-native-unistyles/metro')
27
+ *
28
+ * module.exports = withUnistylesConfig(getDefaultConfig(__dirname))
29
+ * ```
30
+ */
31
+ export declare const withUnistylesConfig: <T extends MetroConfig>(config: T, options?: UnistylesMetroOptions) => T
package/metro/index.js ADDED
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // metro/src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ withUnistylesConfig: () => withUnistylesConfig
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_node_fs = __toESM(require("node:fs"));
37
+ var import_node_path2 = __toESM(require("node:path"));
38
+
39
+ // plugin/src/consts.ts
40
+ var REACT_NATIVE_COMPONENT_NAMES = [
41
+ "ActivityIndicator",
42
+ "View",
43
+ "Text",
44
+ "Image",
45
+ "ImageBackground",
46
+ "KeyboardAvoidingView",
47
+ "Pressable",
48
+ "ScrollView",
49
+ "FlatList",
50
+ "SectionList",
51
+ "Switch",
52
+ "TextInput",
53
+ "RefreshControl",
54
+ "TouchableHighlight",
55
+ "TouchableOpacity",
56
+ "VirtualizedList",
57
+ "Animated",
58
+ "SafeAreaView"
59
+ // Modal - there is no exposed native handle
60
+ // TouchableWithoutFeedback - can't accept a ref
61
+ ];
62
+ var METRO_UPSTREAM_TRANSFORMER_ENV = "UNISTYLES_METRO_UPSTREAM_TRANSFORMER";
63
+ var METRO_OPTIONS_ENV = "UNISTYLES_METRO_OPTIONS";
64
+
65
+ // metro/src/resolver.ts
66
+ var import_node_path = __toESM(require("node:path"));
67
+ var DEEP_IMPORTS = [...REACT_NATIVE_COMPONENT_NAMES, "ViewNativeComponent", "TextNativeComponent"];
68
+ var PASSTHROUGH_PACKAGES = ["react-native", "@react-native", "react-native-web"];
69
+ var createResolveRequest = ({ unistylesRoot, upstream, path: path2 = import_node_path.default }) => {
70
+ const { sep } = path2;
71
+ const sourceDir = path2.join(unistylesRoot, "src");
72
+ const componentsDir = path2.join(sourceDir, "components", "native");
73
+ const componentsIndex = path2.join(componentsDir, "index.ts");
74
+ const builds = [path2.join(unistylesRoot, "lib", "module"), path2.join(unistylesRoot, "lib", "commonjs")];
75
+ const getSourcePath = (filePath) => {
76
+ const build = builds.find((buildDir) => filePath.startsWith(`${buildDir}${sep}`));
77
+ if (!build) {
78
+ return void 0;
79
+ }
80
+ const modulePath = filePath.slice(build.length + 1).replace(/\.js$/, "").replace(/\.(native|ios|android|web)$/, "");
81
+ return path2.join(sourceDir, modulePath);
82
+ };
83
+ const getPackageName = (filePath) => {
84
+ const parts = filePath.split(`${sep}node_modules${sep}`);
85
+ if (parts.length === 1) {
86
+ return void 0;
87
+ }
88
+ const segments = parts.at(-1).split(sep);
89
+ return segments[0]?.startsWith("@") ? `${segments[0]}${sep}${segments[1]}` : segments[0];
90
+ };
91
+ const shouldSwapFrom = (originModulePath) => {
92
+ if (originModulePath.startsWith(`${unistylesRoot}${sep}`)) {
93
+ return false;
94
+ }
95
+ const packageName = getPackageName(originModulePath);
96
+ return !PASSTHROUGH_PACKAGES.some((name) => packageName === name || packageName?.startsWith(`${name}${sep}`));
97
+ };
98
+ const getDeepImport = (filePath) => {
99
+ const segments = filePath.split(sep);
100
+ if (segments.at(-5) === "react-native-web" && segments.at(-4) === "dist" && segments.at(-3) === "exports") {
101
+ return segments.at(-2);
102
+ }
103
+ if (filePath.includes(`${sep}react-native${sep}Libraries${sep}`)) {
104
+ return segments.at(-1)?.split(".").at(0);
105
+ }
106
+ return void 0;
107
+ };
108
+ const getSwapTarget = (moduleName, filePath) => {
109
+ if (moduleName === "react-native" || filePath.endsWith(`${sep}react-native-web${sep}dist${sep}index.js`)) {
110
+ return componentsIndex;
111
+ }
112
+ const deepImport = getDeepImport(filePath);
113
+ return deepImport && DEEP_IMPORTS.includes(deepImport) ? path2.join(componentsDir, "deep", `${deepImport}.ts`) : void 0;
114
+ };
115
+ return (context, moduleName, platform) => {
116
+ const resolve = upstream ?? context.resolveRequest;
117
+ const resolution = resolve(context, moduleName, platform);
118
+ if (resolution.type !== "sourceFile" || !("filePath" in resolution)) {
119
+ return resolution;
120
+ }
121
+ const sourcePath = getSourcePath(resolution.filePath);
122
+ if (sourcePath) {
123
+ return resolve(context, sourcePath, platform);
124
+ }
125
+ if (!shouldSwapFrom(context.originModulePath)) {
126
+ return resolution;
127
+ }
128
+ const swapTarget = getSwapTarget(moduleName, resolution.filePath);
129
+ return swapTarget ? { type: "sourceFile", filePath: swapTarget } : resolution;
130
+ };
131
+ };
132
+
133
+ // metro/src/index.ts
134
+ var withUnistylesConfig = (config, options = {}) => {
135
+ const babelTransformerPath = import_node_path2.default.join(__dirname, "babel-transformer.js");
136
+ const upstreamBabelTransformerPath = config.transformer?.babelTransformerPath;
137
+ if (upstreamBabelTransformerPath === babelTransformerPath) {
138
+ throw new Error("Unistyles \u{1F984}: withUnistylesConfig was applied twice to the same Metro config");
139
+ }
140
+ if (!upstreamBabelTransformerPath) {
141
+ throw new Error(
142
+ "Unistyles \u{1F984}: Metro config has no babelTransformerPath, pass the config returned by getDefaultConfig to withUnistylesConfig"
143
+ );
144
+ }
145
+ const unistylesOptions = {
146
+ debug: options.debug ?? false
147
+ };
148
+ process.env[METRO_UPSTREAM_TRANSFORMER_ENV] = upstreamBabelTransformerPath;
149
+ process.env[METRO_OPTIONS_ENV] = JSON.stringify(unistylesOptions);
150
+ return {
151
+ ...config,
152
+ transformer: {
153
+ ...config.transformer,
154
+ babelTransformerPath,
155
+ // part of Metro's transform cache key
156
+ unistyles: unistylesOptions
157
+ },
158
+ resolver: {
159
+ ...config.resolver,
160
+ resolveRequest: createResolveRequest({
161
+ unistylesRoot: import_node_fs.default.realpathSync(import_node_path2.default.join(__dirname, "..")),
162
+ upstream: config.resolver?.resolveRequest
163
+ })
164
+ }
165
+ };
166
+ };
167
+ // Annotate the CommonJS export names for ESM import in node:
168
+ 0 && (module.exports = {
169
+ withUnistylesConfig
170
+ });
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.5.3",
3
+ "version": "3.6.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
- "test": "NODE_ENV=babel-test jest ./plugin ./src/__tests__",
6
+ "test": "NODE_ENV=babel-test jest ./plugin ./metro ./src/__tests__",
7
7
  "test:coverage": "NODE_ENV=babel-test jest --passWithNoTests --coverage",
8
8
  "tsc": "node_modules/typescript/bin/tsc --noEmit",
9
- "format": "oxfmt src plugin repack-plugin",
10
- "lint": "oxlint src plugin repack-plugin",
11
- "check": "oxfmt src plugin repack-plugin && oxlint --fix src plugin repack-plugin",
12
- "check:ci": "oxfmt --check src plugin repack-plugin && oxlint src plugin repack-plugin",
13
- "prepare": "bob build && bun run plugin:build && bun run repack:plugin:build",
9
+ "format": "oxfmt src plugin repack-plugin metro",
10
+ "lint": "oxlint src plugin repack-plugin metro",
11
+ "check": "oxfmt src plugin repack-plugin metro && oxlint --fix src plugin repack-plugin metro",
12
+ "check:ci": "oxfmt --check src plugin repack-plugin metro && oxlint src plugin repack-plugin metro",
13
+ "prepare": "bob build && bun run plugin:build && bun run repack:plugin:build && bun run metro:build",
14
14
  "precommit": "concurrently 'bun run tsc' 'bun run lint' 'bun run check' 'bun run test' 'bun run circular:check'",
15
15
  "plugin:build": "node plugin/esbuild.js",
16
16
  "repack:plugin:build": "node repack-plugin/esbuild.js",
17
+ "metro:build": "node metro/esbuild.js",
17
18
  "circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 src/**/*.ts",
18
19
  "components:build": "node build-components.js"
19
20
  },
@@ -53,6 +54,10 @@
53
54
  "types": "./repack-plugin/index.d.ts",
54
55
  "default": "./repack-plugin/index.js"
55
56
  },
57
+ "./metro": {
58
+ "types": "./metro/index.d.ts",
59
+ "default": "./metro/index.js"
60
+ },
56
61
  "./package.json": "./package.json",
57
62
  "./server": {
58
63
  "types": "./lib/typescript/src/server/index.d.ts",
@@ -100,6 +105,7 @@
100
105
  "react-native.config.js",
101
106
  "Unistyles.podspec",
102
107
  "repack-plugin",
108
+ "metro",
103
109
  "unistyles_get_rn_version.rb",
104
110
  "!repack-plugin/__tests__",
105
111
  "!repack-plugin/src",
@@ -107,6 +113,9 @@
107
113
  "!plugin/__tests__",
108
114
  "!plugin/src",
109
115
  "!plugin/esbuild.js",
116
+ "!metro/__tests__",
117
+ "!metro/src",
118
+ "!metro/esbuild.js",
110
119
  "!ios/build",
111
120
  "!android/build",
112
121
  "!android/gradle",
@@ -115,7 +124,13 @@
115
124
  "!android/local.properties",
116
125
  "!**/*.spec.ts",
117
126
  "!**/*.spec.tsx",
118
- "!**/.*"
127
+ "!**/__tests__",
128
+ "!**/.*",
129
+ "!src/unifiber/test",
130
+ "!src/unifiber/bench",
131
+ "!src/unifiber/package.json",
132
+ "!src/unifiber/tsconfig.json",
133
+ "!src/unifiber/bun.lock"
119
134
  ],
120
135
  "keywords": [
121
136
  "react-native",
@@ -151,10 +166,12 @@
151
166
  "dpdm": "4.3.0",
152
167
  "esbuild": "0.28.2",
153
168
  "jest": "30.5.2",
169
+ "@babel/core": "7.29.7",
154
170
  "@babel/plugin-syntax-jsx": "7.29.7",
155
171
  "@babel/runtime": "7.29.7",
156
172
  "@react-native/babel-preset": "0.87.1",
157
173
  "@react-native/jest-preset": "0.87.1",
174
+ "@react-native/metro-babel-transformer": "0.87.1",
158
175
  "nitrogen": "0.37.1",
159
176
  "oxfmt": "0.70.0",
160
177
  "oxlint": "1.85.0",
@@ -209,6 +226,7 @@
209
226
  "react-native-builder-bob": {
210
227
  "source": "src",
211
228
  "output": "lib",
229
+ "exclude": "{**/{__tests__,__fixtures__,__mocks__}/**,**/unifiber/{test,bench}/**,**/unifiber/*}",
212
230
  "targets": [
213
231
  "commonjs",
214
232
  "module",
package/plugin/index.d.ts CHANGED
@@ -44,6 +44,13 @@ export interface UnistylesPluginOptions {
44
44
  */
45
45
  root: string
46
46
 
47
+ /**
48
+ * Set by react-native-unistyles/metro, don't use it!
49
+ * Metro picks the files to process and swaps imports in its resolver,
50
+ * so `root`, `autoProcessImports`, `autoProcessPaths` and `autoRemapImports` are ignored
51
+ */
52
+ isMetro?: boolean
53
+
47
54
  /**
48
55
  * Example: ['@my-org/styles']
49
56
  * Enable this option if you want to process only files containing specific imports.
package/plugin/index.js CHANGED
@@ -91,6 +91,7 @@ var NATIVE_COMPONENTS_PATHS = {
91
91
  }
92
92
  ]
93
93
  };
94
+ var METRO_UPSTREAM_TRANSFORMER_ENV = "UNISTYLES_METRO_UPSTREAM_TRANSFORMER";
94
95
 
95
96
  // plugin/src/exotic.ts
96
97
  var t2 = __toESM(require("@babel/types"));
@@ -139,6 +140,9 @@ function addUnistylesImport(path2, state) {
139
140
  nodesToRemove.forEach((node) => path2.node.body.splice(path2.node.body.indexOf(node), 1));
140
141
  }
141
142
  function isInsideNodeModules(state) {
143
+ if (state.opts.isMetro) {
144
+ return false;
145
+ }
142
146
  return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
143
147
  }
144
148
  function addUnistylesRequire(path2, state) {
@@ -719,6 +723,7 @@ function addDependencies(state, styleName, unistyle, detectedDependencies) {
719
723
 
720
724
  // plugin/src/variants.ts
721
725
  var t5 = __toESM(require("@babel/types"));
726
+ var scopedVariants = /* @__PURE__ */ new WeakMap();
722
727
  function extractVariants(path2, state) {
723
728
  const maybeVariants = path2.node.body.filter(
724
729
  (node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee)
@@ -745,22 +750,29 @@ function extractVariants(path2, state) {
745
750
  return;
746
751
  }
747
752
  const calleeName = callee.object.name;
748
- const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
749
- const shadowDeclaration = t5.variableDeclaration("const", [
750
- t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
751
- ]);
753
+ const binding = path2.scope.getBinding(calleeName);
754
+ const existingShadowName = binding && t5.isVariableDeclarator(binding.path.node) ? scopedVariants.get(binding.path.node) : void 0;
755
+ const shadowName = existingShadowName ?? path2.scope.generateUidIdentifier(calleeName).name;
752
756
  const newCallExpression = t5.callExpression(
753
- t5.memberExpression(t5.identifier(newUniqueName.name), t5.identifier("useVariants")),
757
+ t5.memberExpression(t5.identifier(shadowName), t5.identifier("useVariants")),
754
758
  node.arguments
755
759
  );
756
- const finalDeclaration = t5.variableDeclaration("const", [
757
- t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
758
- ]);
760
+ const finalDeclarator = t5.variableDeclarator(t5.identifier(calleeName), newCallExpression);
761
+ const finalDeclaration = t5.variableDeclaration("const", [finalDeclarator]);
762
+ scopedVariants.set(finalDeclarator, shadowName);
759
763
  const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
760
764
  const rest = path2.node.body.slice(pathIndex + 1);
761
765
  const statement = t5.blockStatement([finalDeclaration, ...rest]);
762
- path2.node.body = [...path2.node.body.slice(0, pathIndex), shadowDeclaration, statement];
763
766
  state.file.hasVariants = true;
767
+ if (existingShadowName) {
768
+ path2.node.body = [...path2.node.body.slice(0, pathIndex), statement];
769
+ return;
770
+ }
771
+ const shadowDeclaration = t5.variableDeclaration("const", [
772
+ t5.variableDeclarator(t5.identifier(shadowName), t5.identifier(calleeName))
773
+ ]);
774
+ path2.node.body = [...path2.node.body.slice(0, pathIndex), shadowDeclaration, statement];
775
+ path2.scope.registerDeclaration(path2.get(`body.${pathIndex}`));
764
776
  }
765
777
 
766
778
  // plugin/src/index.ts
@@ -776,13 +788,18 @@ function index_default() {
776
788
  visitor: {
777
789
  Program: {
778
790
  enter(path2, state) {
779
- if (!state.opts.root) {
791
+ if (!state.opts.isMetro && process.env[METRO_UPSTREAM_TRANSFORMER_ENV]) {
792
+ throw new Error(
793
+ "Unistyles \u{1F984}: react-native-unistyles/metro is enabled in metro.config.js, remove react-native-unistyles/plugin from babel.config.js"
794
+ );
795
+ }
796
+ if (!state.opts.root && !state.opts.isMetro) {
780
797
  throw new Error(
781
798
  "Unistyles \u{1F984}: Babel plugin requires `root` option to be set. Please check https://www.unistyl.es/v3/other/babel-plugin#extra-configuration"
782
799
  );
783
800
  }
784
- const appRoot = toPlatformPath(import_node_path2.default.join(state.file.opts.root, state.opts.root));
785
- if (state.file.opts.root === appRoot) {
801
+ const appRoot = toPlatformPath(import_node_path2.default.join(state.file.opts.root, state.opts.root ?? ""));
802
+ if (!state.opts.isMetro && state.file.opts.root === appRoot) {
786
803
  throw new Error(
787
804
  "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"
788
805
  );
@@ -797,7 +814,7 @@ function index_default() {
797
814
  state.file.styleSheetLocalName = "";
798
815
  state.file.reactNativeCommonJSName = "";
799
816
  state.reactNativeImports = {};
800
- state.file.forceProcessing = state.filename?.includes(appRoot) ?? false;
817
+ state.file.forceProcessing = state.opts.isMetro || (state.filename?.includes(appRoot) ?? false);
801
818
  path2.traverse({
802
819
  BlockStatement(blockPath) {
803
820
  if (isInsideNodeModules(state)) {
@@ -808,7 +825,7 @@ function index_default() {
808
825
  });
809
826
  },
810
827
  exit(path2, state) {
811
- if (isInsideNodeModules(state)) {
828
+ if (state.opts.isMetro || isInsideNodeModules(state)) {
812
829
  return;
813
830
  }
814
831
  if (state.file.addUnistylesRequire) {
@@ -851,7 +868,7 @@ function index_default() {
851
868
  });
852
869
  },
853
870
  ImportDeclaration(path2, state) {
854
- const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find(
871
+ const exoticImport = state.opts.isMetro ? void 0 : REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find(
855
872
  (exotic) => state.filename?.includes(exotic.path)
856
873
  );
857
874
  if (exoticImport) {
@@ -869,6 +886,9 @@ function index_default() {
869
886
  }
870
887
  });
871
888
  }
889
+ if (state.opts.isMetro) {
890
+ return;
891
+ }
872
892
  if (importSource === "react-native") {
873
893
  path2.node.specifiers.forEach((specifier) => {
874
894
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
@@ -892,7 +912,7 @@ function index_default() {
892
912
  }
893
913
  },
894
914
  MemberExpression(path2, state) {
895
- if (isInsideNodeModules(state)) {
915
+ if (state.opts.isMetro || isInsideNodeModules(state)) {
896
916
  return;
897
917
  }
898
918
  if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.object)) {
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the ActivityIndicator module of react-native or react-native-web here
2
+ export { ActivityIndicator, ActivityIndicator as default } from '../ActivityIndicator'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the Animated module of react-native or react-native-web here
2
+ export { Animated, Animated as default } from '../Animated'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the FlatList module of react-native or react-native-web here
2
+ export { FlatList, FlatList as default } from '../FlatList'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the Image module of react-native or react-native-web here
2
+ export { Image, Image as default } from '../Image'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the ImageBackground module of react-native or react-native-web here
2
+ export { ImageBackground, ImageBackground as default } from '../ImageBackground'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the KeyboardAvoidingView module of react-native or react-native-web here
2
+ export { KeyboardAvoidingView, KeyboardAvoidingView as default } from '../KeyboardAvoidingView'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the Pressable module of react-native or react-native-web here
2
+ export { Pressable, Pressable as default } from '../Pressable'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the RefreshControl module of react-native or react-native-web here
2
+ export { RefreshControl, RefreshControl as default } from '../RefreshControl'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the SafeAreaView module of react-native or react-native-web here
2
+ export { SafeAreaView, SafeAreaView as default } from '../SafeAreaView'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the ScrollView module of react-native or react-native-web here
2
+ export { ScrollView, ScrollView as default } from '../ScrollView'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the SectionList module of react-native or react-native-web here
2
+ export { SectionList, SectionList as default } from '../SectionList'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the Switch module of react-native or react-native-web here
2
+ export { Switch, Switch as default } from '../Switch'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the Text module of react-native or react-native-web here
2
+ export { Text, Text as default } from '../Text'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the TextInput module of react-native or react-native-web here
2
+ export { TextInput, TextInput as default } from '../TextInput'
@@ -0,0 +1,5 @@
1
+ // react-native-unistyles/metro resolves direct imports of react-native/Libraries/Text/TextNativeComponent here,
2
+ // its other exports (eg. NativeVirtualText) stay untouched
3
+ // @ts-ignore deep imports are typed only by some React Native versions
4
+ export * from 'react-native/Libraries/Text/TextNativeComponent'
5
+ export { NativeText } from '../NativeText'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the TouchableHighlight module of react-native or react-native-web here
2
+ export { TouchableHighlight, TouchableHighlight as default } from '../TouchableHighlight'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the TouchableOpacity module of react-native or react-native-web here
2
+ export { TouchableOpacity, TouchableOpacity as default } from '../TouchableOpacity'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the View module of react-native or react-native-web here
2
+ export { View, View as default } from '../View'
@@ -0,0 +1,5 @@
1
+ // react-native-unistyles/metro resolves direct imports of react-native/Libraries/Components/View/ViewNativeComponent here,
2
+ // its other exports stay untouched
3
+ // @ts-ignore deep imports are typed only by some React Native versions
4
+ export * from 'react-native/Libraries/Components/View/ViewNativeComponent'
5
+ export { NativeView as default } from '../NativeView'
@@ -0,0 +1,2 @@
1
+ // react-native-unistyles/metro resolves direct imports of the VirtualizedList module of react-native or react-native-web here
2
+ export { VirtualizedList, VirtualizedList as default } from '../VirtualizedList'
@@ -0,0 +1,41 @@
1
+ // react-native-unistyles/metro resolves every `react-native` import (react-native-web on web) to this module,
2
+ // so it exposes every export of react-native and swaps the components Unistyles can update.
3
+ // Imports from this folder are Unistyles' own, they reach the real react-native
4
+ const ReactNative: Record<string, unknown> = require('react-native')
5
+
6
+ // lazy, like react-native's own exports
7
+ const UNISTYLES_COMPONENTS: Record<string, () => unknown> = {
8
+ ActivityIndicator: () => require('./ActivityIndicator').ActivityIndicator,
9
+ Animated: () => require('./Animated').Animated,
10
+ FlatList: () => require('./FlatList').FlatList,
11
+ Image: () => require('./Image').Image,
12
+ ImageBackground: () => require('./ImageBackground').ImageBackground,
13
+ KeyboardAvoidingView: () => require('./KeyboardAvoidingView').KeyboardAvoidingView,
14
+ Pressable: () => require('./Pressable').Pressable,
15
+ RefreshControl: () => require('./RefreshControl').RefreshControl,
16
+ SafeAreaView: () => require('./SafeAreaView').SafeAreaView,
17
+ ScrollView: () => require('./ScrollView').ScrollView,
18
+ SectionList: () => require('./SectionList').SectionList,
19
+ Switch: () => require('./Switch').Switch,
20
+ Text: () => require('./Text').Text,
21
+ TextInput: () => require('./TextInput').TextInput,
22
+ TouchableHighlight: () => require('./TouchableHighlight').TouchableHighlight,
23
+ TouchableOpacity: () => require('./TouchableOpacity').TouchableOpacity,
24
+ View: () => require('./View').View,
25
+ VirtualizedList: () => require('./VirtualizedList').VirtualizedList,
26
+ unstable_NativeText: () => require('./NativeText').NativeText,
27
+ unstable_NativeView: () => require('./NativeView').NativeView,
28
+ }
29
+
30
+ // Object.keys doesn't call react-native's getters. Unistyles components are added even if missing,
31
+ // react-native-web and React Native before 0.83 don't export unstable_NativeView / unstable_NativeText
32
+ const exportNames = new Set(Object.keys(ReactNative).concat(Object.keys(UNISTYLES_COMPONENTS)))
33
+
34
+ exportNames.forEach((name) => {
35
+ // CommonJS without the __esModule flag, like react-native, so a default import still gets every export
36
+ // @ts-ignore module is provided by Metro
37
+ Object.defineProperty(module.exports, name, {
38
+ enumerable: true,
39
+ get: UNISTYLES_COMPONENTS[name] ?? (() => ReactNative[name]),
40
+ })
41
+ })
@@ -2,18 +2,21 @@ import type { ActivityIndicator } from 'react-native'
2
2
 
3
3
  import React, { useContext } from 'react'
4
4
 
5
- import { isAndroid } from '../common'
6
5
  import { ScopedThemeContext } from '../components/ScopedThemeContext'
7
6
  import { UnistylesShadowRegistry } from '../specs'
7
+ import { Fiber } from '../unifiber/src'
8
8
  import { copyComponentProperties } from '../utils'
9
+ import { hasUnistyles } from './hasUnistyles'
9
10
  import { passForwardedRef } from './passForwardRef'
10
11
  import { maybeWarnAboutMultipleUnistyles } from './warn'
11
12
 
12
- const getWrapperHandle = (ref: any) => {
13
- const spinner = ref?.__internalInstanceHandle
13
+ const { getHostFor, getParentHost } = Fiber
14
+
15
+ const getWrapperHandle = (ref: unknown) => {
16
+ const spinner = getHostFor(ref)
14
17
 
15
18
  return {
16
- __internalInstanceHandle: isAndroid ? spinner?.return?.return : spinner?.return,
19
+ __internalInstanceHandle: spinner && getParentHost(spinner),
17
20
  }
18
21
  }
19
22
 
@@ -21,6 +24,10 @@ export const createUnistylesActivityIndicator = (Component: typeof ActivityIndic
21
24
  const UnistylesActivityIndicator = (props: any) => {
22
25
  const scope = useContext(ScopedThemeContext)
23
26
 
27
+ if (!hasUnistyles(props.style)) {
28
+ return <Component {...props} />
29
+ }
30
+
24
31
  return (
25
32
  <Component
26
33
  {...props}
@@ -5,6 +5,7 @@ import React, { useContext, useRef } 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
 
@@ -13,6 +14,10 @@ export const createUnistylesElement = (Component: any) => {
13
14
  const scrollViewRef = useRef<ScrollView>(null)
14
15
  const scope = useContext(ScopedThemeContext)
15
16
 
17
+ if (!hasUnistyles(props.style)) {
18
+ return <Component {...props} />
19
+ }
20
+
16
21
  return (
17
22
  <Component
18
23
  {...props}