react-native-unistyles 3.0.0-nightly-20250127 → 3.0.0-nightly-20250131

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 (140) hide show
  1. package/README.md +14 -2
  2. package/android/src/main/cxx/NativeUnistylesModule.cpp +1 -1
  3. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -2
  4. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +4 -0
  5. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +2 -1
  6. package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -4
  7. package/components/native/Animated/package.json +5 -0
  8. package/components/native/NativeText/package.json +5 -0
  9. package/components/native/NativeView/package.json +5 -0
  10. package/cxx/core/Unistyle.h +4 -0
  11. package/cxx/core/UnistylesRegistry.cpp +24 -3
  12. package/cxx/core/UnistylesRegistry.h +3 -0
  13. package/cxx/hybridObjects/HybridShadowRegistry.cpp +7 -0
  14. package/cxx/hybridObjects/HybridStyleSheet.cpp +27 -2
  15. package/cxx/parser/Parser.cpp +10 -4
  16. package/ios/NativePlatform+ios.swift +16 -4
  17. package/lib/commonjs/components/native/Animated.js +23 -0
  18. package/lib/commonjs/components/native/Animated.js.map +1 -0
  19. package/lib/commonjs/components/native/ImageBackground.js +3 -1
  20. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  21. package/lib/commonjs/components/native/NativeText.js +13 -0
  22. package/lib/commonjs/components/native/NativeText.js.map +1 -0
  23. package/lib/commonjs/components/native/NativeText.native.js +18 -0
  24. package/lib/commonjs/components/native/NativeText.native.js.map +1 -0
  25. package/lib/commonjs/components/native/NativeView.js +9 -0
  26. package/lib/commonjs/components/native/NativeView.js.map +1 -0
  27. package/lib/commonjs/components/native/NativeView.native.js +20 -0
  28. package/lib/commonjs/components/native/NativeView.native.js.map +1 -0
  29. package/lib/commonjs/components/native/Pressable.native.js +15 -2
  30. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  31. package/lib/commonjs/core/createUnistylesElement.js +26 -22
  32. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  33. package/lib/commonjs/core/createUnistylesElement.native.js +25 -21
  34. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  35. package/lib/commonjs/core/createUnistylesImageBackground.js +34 -30
  36. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  37. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  38. package/lib/commonjs/utils.js +16 -1
  39. package/lib/commonjs/utils.js.map +1 -1
  40. package/lib/commonjs/web/utils/unistyle.js +5 -1
  41. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  42. package/lib/module/components/native/Animated.js +19 -0
  43. package/lib/module/components/native/Animated.js.map +1 -0
  44. package/lib/module/components/native/ImageBackground.js +3 -1
  45. package/lib/module/components/native/ImageBackground.js.map +1 -1
  46. package/lib/module/components/native/NativeText.js +4 -0
  47. package/lib/module/components/native/NativeText.js.map +1 -0
  48. package/lib/module/components/native/NativeText.native.js +15 -0
  49. package/lib/module/components/native/NativeText.native.js.map +1 -0
  50. package/lib/module/components/native/NativeView.js +5 -0
  51. package/lib/module/components/native/NativeView.js.map +1 -0
  52. package/lib/module/components/native/NativeView.native.js +17 -0
  53. package/lib/module/components/native/NativeView.native.js.map +1 -0
  54. package/lib/module/components/native/Pressable.native.js +15 -2
  55. package/lib/module/components/native/Pressable.native.js.map +1 -1
  56. package/lib/module/core/createUnistylesElement.js +26 -22
  57. package/lib/module/core/createUnistylesElement.js.map +1 -1
  58. package/lib/module/core/createUnistylesElement.native.js +25 -21
  59. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  60. package/lib/module/core/createUnistylesImageBackground.js +34 -30
  61. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  62. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  63. package/lib/module/utils.js +14 -0
  64. package/lib/module/utils.js.map +1 -1
  65. package/lib/module/web/utils/unistyle.js +5 -1
  66. package/lib/module/web/utils/unistyle.js.map +1 -1
  67. package/lib/typescript/src/components/native/ActivityIndicator.d.ts +1 -3
  68. package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
  69. package/lib/typescript/src/components/native/Animated.d.ts +39 -0
  70. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -0
  71. package/lib/typescript/src/components/native/FlatList.d.ts +1 -3
  72. package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
  73. package/lib/typescript/src/components/native/Image.d.ts +1 -3
  74. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  75. package/lib/typescript/src/components/native/ImageBackground.d.ts +1 -8
  76. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  77. package/lib/typescript/src/components/native/ImageBackground.native.d.ts +1 -2
  78. package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -1
  79. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +1 -3
  80. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
  81. package/lib/typescript/src/components/native/NativeText.d.ts +2 -0
  82. package/lib/typescript/src/components/native/NativeText.d.ts.map +1 -0
  83. package/lib/typescript/src/components/native/NativeText.native.d.ts +2 -0
  84. package/lib/typescript/src/components/native/NativeText.native.d.ts.map +1 -0
  85. package/lib/typescript/src/components/native/NativeView.d.ts +3 -0
  86. package/lib/typescript/src/components/native/NativeView.d.ts.map +1 -0
  87. package/lib/typescript/src/components/native/NativeView.native.d.ts +3 -0
  88. package/lib/typescript/src/components/native/NativeView.native.d.ts.map +1 -0
  89. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  90. package/lib/typescript/src/components/native/RefreshControl.d.ts +1 -3
  91. package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
  92. package/lib/typescript/src/components/native/ScrollView.d.ts +1 -3
  93. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
  94. package/lib/typescript/src/components/native/SectionList.d.ts +1 -3
  95. package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
  96. package/lib/typescript/src/components/native/Switch.d.ts +1 -3
  97. package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
  98. package/lib/typescript/src/components/native/Text.d.ts +1 -3
  99. package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
  100. package/lib/typescript/src/components/native/TextInput.d.ts +1 -3
  101. package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
  102. package/lib/typescript/src/components/native/TouchableHighlight.d.ts +1 -3
  103. package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
  104. package/lib/typescript/src/components/native/TouchableOpacity.d.ts +1 -3
  105. package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
  106. package/lib/typescript/src/components/native/View.d.ts +1 -3
  107. package/lib/typescript/src/components/native/View.d.ts.map +1 -1
  108. package/lib/typescript/src/components/native/VirtualizedList.d.ts +1 -3
  109. package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
  110. package/lib/typescript/src/core/createUnistylesElement.d.ts +1 -7
  111. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  112. package/lib/typescript/src/core/createUnistylesElement.native.d.ts +1 -2
  113. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  114. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +2 -3
  115. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  116. package/lib/typescript/src/specs/StyleSheet/index.d.ts +1 -0
  117. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  118. package/lib/typescript/src/utils.d.ts +1 -0
  119. package/lib/typescript/src/utils.d.ts.map +1 -1
  120. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  121. package/package.json +9 -7
  122. package/plugin/consts.js +63 -0
  123. package/plugin/exotic.js +54 -0
  124. package/plugin/index.d.ts +79 -33
  125. package/plugin/index.js +23 -31
  126. package/plugin/stylesheet.js +12 -1
  127. package/plugin/variants.js +1 -1
  128. package/src/components/native/Animated.tsx +17 -0
  129. package/src/components/native/ImageBackground.tsx +4 -1
  130. package/src/components/native/NativeText.native.tsx +12 -0
  131. package/src/components/native/NativeText.tsx +1 -0
  132. package/src/components/native/NativeView.native.tsx +13 -0
  133. package/src/components/native/NativeView.tsx +3 -0
  134. package/src/components/native/Pressable.native.tsx +20 -2
  135. package/src/core/createUnistylesElement.native.tsx +28 -23
  136. package/src/core/createUnistylesElement.tsx +34 -29
  137. package/src/core/createUnistylesImageBackground.tsx +38 -33
  138. package/src/specs/StyleSheet/index.ts +2 -1
  139. package/src/utils.ts +17 -0
  140. package/src/web/utils/unistyle.ts +7 -1
@@ -0,0 +1,63 @@
1
+ const REACT_NATIVE_COMPONENT_NAMES = [
2
+ 'ActivityIndicator',
3
+ 'View',
4
+ 'Text',
5
+ 'Image',
6
+ 'ImageBackground',
7
+ 'KeyboardAvoidingView',
8
+ 'Pressable',
9
+ 'ScrollView',
10
+ 'FlatList',
11
+ 'SectionList',
12
+ 'Switch',
13
+ 'TextInput',
14
+ 'RefreshControl',
15
+ 'TouchableHighlight',
16
+ 'TouchableOpacity',
17
+ 'VirtualizedList',
18
+ 'Animated'
19
+ // Modal - there is no exposed native handle
20
+ // TouchableWithoutFeedback - can't accept a ref
21
+ ]
22
+
23
+ // auto replace RN imports to Unistyles imports under these paths
24
+ // our implementation simply borrows 'ref' to register it in ShadowRegistry
25
+ // so we won't affect anyone's implementation
26
+ const REPLACE_WITH_UNISTYLES_PATHS = [
27
+ 'react-native-reanimated/src/component',
28
+ 'react-native-gesture-handler/src/components'
29
+ ]
30
+
31
+ // this is more powerful API as it allows to convert unmatched imports to Unistyles
32
+ // { path: string, imports: Array<{ name: string, isDefault: boolean, path: string, mapTo: string }> }
33
+ // path => node_modules path
34
+ // imports:
35
+ // name? <- target import name if isDefault is false
36
+ // isDefault <- is the import default?
37
+ // path <- path to the target import
38
+ // mapTo <- name of the Unistyles component
39
+ const REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = []
40
+
41
+ // this list will additionally detect React Native direct imports
42
+ const NATIVE_COMPONENTS_PATHS = {
43
+ imports: [
44
+ {
45
+ name: 'NativeText',
46
+ isDefault: false,
47
+ path: 'react-native/Libraries/Text/TextNativeComponent',
48
+ mapTo: 'NativeText'
49
+ },
50
+ {
51
+ isDefault: true,
52
+ path: 'react-native/Libraries/Components/View/ViewNativeComponent',
53
+ mapTo: 'NativeView'
54
+ }
55
+ ]
56
+ }
57
+
58
+ module.exports = {
59
+ NATIVE_COMPONENTS_PATHS,
60
+ REACT_NATIVE_COMPONENT_NAMES,
61
+ REPLACE_WITH_UNISTYLES_PATHS,
62
+ REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
63
+ }
@@ -0,0 +1,54 @@
1
+ function handleExoticImport(t, path, state, exoticImport) {
2
+ const specifiers = path.node.specifiers
3
+ const source = path.node.source
4
+
5
+ if (path.node.importKind !== 'value') {
6
+ return
7
+ }
8
+
9
+ specifiers.forEach(specifier => {
10
+ for (const rule of exoticImport.imports) {
11
+ const hasMatchingImportType = (!rule.isDefault && t.isImportSpecifier(specifier)) || (rule.isDefault && t.isImportDefaultSpecifier(specifier))
12
+ const hasMatchingImportName = rule.isDefault || (!rule.isDefault && rule.name === specifier.local.name)
13
+ const hasMatchingPath = rule.path === source.value
14
+
15
+ if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
16
+ continue
17
+ }
18
+
19
+ if (t.isImportDefaultSpecifier(specifier)) {
20
+ const newImport = t.importDeclaration(
21
+ [t.importDefaultSpecifier(t.identifier(specifier.local.name))],
22
+ t.stringLiteral(state.opts.isLocal
23
+ ? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
24
+ : `react-native-unistyles/components/native/${rule.mapTo}`
25
+ )
26
+ )
27
+
28
+ path.replaceWith(newImport)
29
+ } else {
30
+ const newImport = t.importDeclaration(
31
+ [t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
32
+ t.stringLiteral(state.opts.isLocal
33
+ ? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${rule.mapTo}`)
34
+ : `react-native-unistyles/components/native/${rule.mapTo}`
35
+ )
36
+ )
37
+
38
+ path.node.specifiers = specifiers.filter(s => s !== specifier)
39
+
40
+ if (path.node.specifiers.length === 0) {
41
+ path.replaceWith(newImport)
42
+ } else {
43
+ path.insertBefore(newImport)
44
+ }
45
+ }
46
+
47
+ return
48
+ }
49
+ })
50
+ }
51
+
52
+ module.exports = {
53
+ handleExoticImport
54
+ }
package/plugin/index.d.ts CHANGED
@@ -1,43 +1,89 @@
1
+ type RemapImport = {
2
+ name?: string,
3
+ isDefault: boolean,
4
+ path: string,
5
+ mapTo: string
6
+ }
7
+
8
+ type RemapConfig = {
9
+ path: string,
10
+ imports: Array<RemapImport>
11
+ }
12
+
1
13
  export interface UnistylesPluginOptions {
2
14
  /**
3
15
  * Example: "src" or "apps/mobile"
4
16
  * Add this option if some of your components don't have `react-native-unistyles` import.
5
17
  * Babel plugin will automatically process all files under this root.
6
18
  */
7
- autoProcessRoot?: string
8
-
9
- /**
10
- * Example: ['@codemask/styles']
11
- * Enable this option if you want to process only files containing specific imports.
12
- */
13
- autoProcessImports?: string[]
14
-
15
- /**
16
- * Example: ['external-library/components']
17
- * Enable this option to process some 3rd party components under `node_modules`.
18
- * Under these paths we will replace `react-native` imports with `react-native-unistyles` factories that will borrow components refs [read more](https://www.unistyl.es/v3/other/babel-plugin#3-component-factory-borrowing-ref).
19
- *
20
- * Defaults to:
21
- *
22
- * ```ts
23
- * ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
24
- * ```
25
- */
26
- autoProcessPaths?: string[];
27
-
28
- /**
29
- * In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
30
- * It will `console.log` name of the file and component with Unistyles dependencies.
31
- */
32
- debug?: boolean;
33
-
34
- /**
35
- * Only applicable for Unistyles monorepo for
36
- * path resolution, don't use it!
37
- */
38
- isLocal?: boolean;
19
+ autoProcessRoot?: string,
20
+
21
+ /**
22
+ * Example: ['@codemask/styles']
23
+ * Enable this option if you want to process only files containing specific imports.
24
+ */
25
+ autoProcessImports?: Array<string>,
26
+
27
+ /**
28
+ * Example: [{
29
+ * path: "node_modules/custom-library/components",
30
+ * imports: [
31
+ * {
32
+ * name: "NativeText",
33
+ * isDefault: false,
34
+ * path: "react-native/Libraries/Text/TextNativeComponent",
35
+ * mapTo: "NativeText"
36
+ * },
37
+ * {
38
+ * isDefault: true,
39
+ * path: "react-native/Libraries/Components/View/ViewNativeComponent",
40
+ * mapTo: "NativeView"
41
+ * }
42
+ * ]
43
+ * }]
44
+ *
45
+ * Will map:
46
+ * import { NativeText } from "react-native/Libraries/Text/TextNativeComponent"
47
+ * to Unistyles "NativeText"
48
+ *
49
+ * import View from "react-native/Libraries/Components/View/ViewNativeComponent"
50
+ * to Unistyles "NativeView"
51
+ *
52
+ * This is the most powerful way of remapping imports. If 3rd party library uses imports different from `react-native` we can remap them to `react-native-unistyles` factories.
53
+ * Internally we do that for raw RCTView and RCTText components.
54
+ *
55
+ * path -> must be within node_modules folder
56
+ * imports.name is Optional if library used export default
57
+ * imports.mapTo - name of the component from react-native-unistyles/src/components/native
58
+ */
59
+ autoRemapImports?: Array<RemapConfig>,
60
+
61
+ /**
62
+ * Example: ['external-library/components']
63
+ * Enable this option to process some 3rd party components under `node_modules`.
64
+ * Under these paths we will replace `react-native` imports with `react-native-unistyles` factories that will borrow components refs [read more](https://www.unistyl.es/v3/other/babel-plugin#3-component-factory-borrowing-ref).
65
+ *
66
+ * Defaults to:
67
+ *
68
+ * ```ts
69
+ * ['react-native-reanimated/src/component', 'react-native-gesture-handler/src/components']
70
+ * ```
71
+ */
72
+ autoProcessPaths?: Array<string>,
73
+
74
+ /**
75
+ * In order to list detected dependencies by the Babel plugin you can enable the `debug` flag.
76
+ * It will `console.log` name of the file and component with Unistyles dependencies.
77
+ */
78
+ debug?: boolean,
79
+
80
+ /**
81
+ * Only applicable for Unistyles monorepo for
82
+ * path resolution, don't use it!
83
+ */
84
+ isLocal?: boolean
39
85
  }
40
86
 
41
87
  export interface UnistylesPluginPass {
42
- opts: UnistylesPluginOptions;
88
+ opts: UnistylesPluginOptions
43
89
  }
package/plugin/index.js CHANGED
@@ -1,36 +1,9 @@
1
1
  const { addUnistylesImport, isInsideNodeModules } = require('./import')
2
2
  const { hasStringRef } = require('./ref')
3
- const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet } = require('./stylesheet')
3
+ const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyles, isKindOfStyleSheet, addThemeDependencyToMemberExpression } = require('./stylesheet')
4
4
  const { extractVariants } = require('./variants')
5
-
6
- const reactNativeComponentNames = [
7
- 'ActivityIndicator',
8
- 'View',
9
- 'Text',
10
- 'Image',
11
- 'ImageBackground',
12
- 'KeyboardAvoidingView',
13
- 'Pressable',
14
- 'ScrollView',
15
- 'FlatList',
16
- 'SectionList',
17
- 'Switch',
18
- 'TextInput',
19
- 'RefreshControl',
20
- 'TouchableHighlight',
21
- 'TouchableOpacity',
22
- 'VirtualizedList',
23
- // Modal - there is no exposed native handle
24
- // TouchableWithoutFeedback - can't accept a ref
25
- ]
26
-
27
- // auto replace RN imports to Unistyles imports under these paths
28
- // our implementation simply borrows 'ref' to register it in ShadowRegistry
29
- // so we won't affect anyone's implementation
30
- const REPLACE_WITH_UNISTYLES_PATHS = [
31
- 'react-native-reanimated/src/component',
32
- 'react-native-gesture-handler/src/components'
33
- ]
5
+ const { REACT_NATIVE_COMPONENT_NAMES, REPLACE_WITH_UNISTYLES_PATHS, REPLACE_WITH_UNISTYLES_EXOTIC_PATHS, NATIVE_COMPONENTS_PATHS } = require('./consts')
6
+ const { handleExoticImport } = require('./exotic')
34
7
 
35
8
  module.exports = function ({ types: t }) {
36
9
  return {
@@ -107,6 +80,14 @@ module.exports = function ({ types: t }) {
107
80
  },
108
81
  /** @param {import('./index').UnistylesPluginPass} state */
109
82
  ImportDeclaration(path, state) {
83
+ const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
84
+ .concat(state.opts.autoRemapImports ?? [])
85
+ .find(exotic => state.filename.includes(exotic.path))
86
+
87
+ if (exoticImport) {
88
+ return handleExoticImport(t, path, state, exoticImport)
89
+ }
90
+
110
91
  if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
111
92
  return
112
93
  }
@@ -123,12 +104,16 @@ module.exports = function ({ types: t }) {
123
104
 
124
105
  if (importSource === 'react-native') {
125
106
  path.node.specifiers.forEach(specifier => {
126
- if (specifier.imported && reactNativeComponentNames.includes(specifier.imported.name)) {
107
+ if (specifier.imported && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
127
108
  state.reactNativeImports[specifier.local.name] = specifier.imported.name
128
109
  }
129
110
  })
130
111
  }
131
112
 
113
+ if (importSource.includes('react-native/Libraries')) {
114
+ handleExoticImport(t, path, state, NATIVE_COMPONENTS_PATHS)
115
+ }
116
+
132
117
  if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
133
118
  state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource)
134
119
  }
@@ -198,6 +183,13 @@ module.exports = function ({ types: t }) {
198
183
  if (t.isObjectProperty(property)) {
199
184
  const propertyValues = getUnistyles(t, property)
200
185
 
186
+ // maybe user used inlined theme? ({ container: theme.components.container })
187
+ if (propertyValues.length === 0 && t.isMemberExpression(property.value)) {
188
+ if (property.value.object.object.name === themeLocalName) {
189
+ addThemeDependencyToMemberExpression(t, property)
190
+ }
191
+ }
192
+
201
193
  propertyValues.forEach(propertyValue => {
202
194
  analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
203
195
  })
@@ -219,10 +219,21 @@ function getUnistyles(t, property) {
219
219
  return []
220
220
  }
221
221
 
222
+ function addThemeDependencyToMemberExpression(t, path) {
223
+ path.value = t.objectExpression([
224
+ t.spreadElement(path.value),
225
+ t.objectProperty(
226
+ t.identifier('uni__dependencies'),
227
+ t.arrayExpression([t.numericLiteral(UnistyleDependency.Theme)])
228
+ )
229
+ ])
230
+ }
231
+
222
232
  module.exports = {
223
233
  isUnistylesStyleSheet,
224
234
  analyzeDependencies,
225
235
  addStyleSheetTag,
226
236
  getUnistyles,
227
- isKindOfStyleSheet
237
+ isKindOfStyleSheet,
238
+ addThemeDependencyToMemberExpression
228
239
  }
@@ -15,7 +15,7 @@ function extractVariants(t, path, state) {
15
15
  return (
16
16
  t.isIdentifier(variant.expression.callee.object, { name: calleeName }) &&
17
17
  t.isIdentifier(variant.expression.callee.property, { name: 'useVariants' }) &&
18
- t.isObjectExpression(variant.expression.arguments[0])
18
+ variant.expression.arguments.length === 1
19
19
  )
20
20
  })
21
21
 
@@ -0,0 +1,17 @@
1
+ import { Animated as RNAnimated } from 'react-native'
2
+ import { View } from './View'
3
+ import { Text } from './Text'
4
+ import { FlatList } from './FlatList'
5
+ import { Image } from './Image'
6
+ import { ScrollView } from './ScrollView'
7
+ import { SectionList } from './SectionList'
8
+
9
+ export const Animated = {
10
+ ...RNAnimated,
11
+ View: RNAnimated.createAnimatedComponent(View),
12
+ Text: RNAnimated.createAnimatedComponent(Text),
13
+ FlatList: RNAnimated.createAnimatedComponent(FlatList),
14
+ Image: RNAnimated.createAnimatedComponent(Image),
15
+ ScrollView: RNAnimated.createAnimatedComponent(ScrollView),
16
+ SectionList: RNAnimated.createAnimatedComponent(SectionList)
17
+ }
@@ -5,13 +5,14 @@ import type { UnistylesValues } from '../../types'
5
5
  import { getClassName } from '../../core'
6
6
  import { isServer } from '../../web/utils'
7
7
  import { UnistylesShadowRegistry } from '../../web'
8
+ import { copyComponentProperties } from '../../utils'
8
9
 
9
10
  type Props = {
10
11
  style?: UnistylesValues
11
12
  imageStyle?: UnistylesValues
12
13
  }
13
14
 
14
- export const ImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
15
+ const UnistylesImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
15
16
  let storedRef: NativeImageBackground | null = null
16
17
  let storedImageRef: NativeImageBackground | null = null
17
18
  const styleClassNames = getClassName(props.style)
@@ -54,3 +55,5 @@ export const ImageBackground = forwardRef<unknown, Props>((props, forwardedRef)
54
55
  />
55
56
  )
56
57
  })
58
+
59
+ export const ImageBackground = copyComponentProperties(NativeImageBackground, UnistylesImageBackground)
@@ -0,0 +1,12 @@
1
+ import type { TextProps } from 'react-native'
2
+ import { type ComponentType, createElement, forwardRef } from 'react'
3
+ import { createUnistylesElement } from '../../core'
4
+
5
+ // credits to @hirbod
6
+ const LeanText = forwardRef((props, ref) => {
7
+ return createElement('RCTText', { ...props, ref })
8
+ }) as ComponentType<TextProps>
9
+
10
+ LeanText.displayName = 'RCTText'
11
+
12
+ export const NativeText = createUnistylesElement(LeanText)
@@ -0,0 +1 @@
1
+ export { Text } from './Text'
@@ -0,0 +1,13 @@
1
+ import type { ViewProps } from 'react-native'
2
+ import { type ComponentType, createElement, forwardRef } from 'react'
3
+ import { createUnistylesElement } from '../../core'
4
+
5
+ // credits to @hirbod
6
+ const LeanView = forwardRef((props, ref) => {
7
+ return createElement('RCTView', { ...props, ref })
8
+ }) as ComponentType<ViewProps>
9
+
10
+ LeanView.displayName = 'RCTView'
11
+
12
+ // this will match default export from react-native
13
+ export default createUnistylesElement(LeanView)
@@ -0,0 +1,3 @@
1
+ import { View } from './View'
2
+
3
+ export default View
@@ -8,6 +8,22 @@ type PressableProps = Props & {
8
8
  variants?: Record<string, string | boolean>
9
9
  }
10
10
 
11
+ const getStyles = (styleProps: Record<string, any> = {}) => {
12
+ const unistyleKey = Object
13
+ .keys(styleProps)
14
+ .find(key => key.startsWith('unistyles-'))
15
+
16
+ if (!unistyleKey) {
17
+ return styleProps
18
+ }
19
+
20
+ return {
21
+ // styles without C++ state
22
+ ...styleProps[unistyleKey].uni__getStyles(),
23
+ [unistyleKey]: styleProps[unistyleKey].uni__getStyles()
24
+ }
25
+ }
26
+
11
27
  export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, forwardedRef) => {
12
28
  const storedRef = useRef<View | null>()
13
29
 
@@ -28,7 +44,7 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
28
44
  ? style({ pressed: false })
29
45
  : style
30
46
 
31
- // @ts-expect-error web types are not compatible with RN styles
47
+ // @ts-expect-error - this is hidden from TS
32
48
  UnistylesShadowRegistry.add(ref, unistyles)
33
49
 
34
50
  if (ref) {
@@ -40,12 +56,14 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
40
56
  style={state => {
41
57
  const unistyles = typeof style === 'function'
42
58
  ? style(state)
43
- : style
59
+ : getStyles(style as unknown as Record<string, any>)
44
60
 
45
61
  if (!storedRef.current) {
46
62
  return unistyles
47
63
  }
48
64
 
65
+ // @ts-expect-error - this is hidden from TS
66
+ UnistylesShadowRegistry.remove(storedRef.current)
49
67
  // @ts-expect-error - this is hidden from TS
50
68
  UnistylesShadowRegistry.add(storedRef.current, unistyles)
51
69
 
@@ -2,6 +2,7 @@ import React, { useLayoutEffect, useRef } from 'react'
2
2
  import { UnistylesShadowRegistry } from '../specs'
3
3
  import { passForwardedRef } from './passForwardRef'
4
4
  import { maybeWarnAboutMultipleUnistyles } from './warn'
5
+ import { copyComponentProperties } from '../utils'
5
6
 
6
7
  const getNativeRef = (Component: any, ref: any) => {
7
8
  switch (Component.name) {
@@ -16,31 +17,35 @@ const getNativeRef = (Component: any, ref: any) => {
16
17
  }
17
18
  }
18
19
 
19
- export const createUnistylesElement = (Component: any) => React.forwardRef((props, forwardedRef) => {
20
- const storedRef = useRef<unknown>(null)
20
+ export const createUnistylesElement = (Component: any) => {
21
+ const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
22
+ const storedRef = useRef<unknown>(null)
21
23
 
22
- useLayoutEffect(() => {
23
- return () => {
24
- if (storedRef.current) {
25
- // @ts-ignore
26
- UnistylesShadowRegistry.remove(storedRef.current)
24
+ useLayoutEffect(() => {
25
+ return () => {
26
+ if (storedRef.current) {
27
+ // @ts-ignore
28
+ UnistylesShadowRegistry.remove(storedRef.current)
29
+ }
27
30
  }
28
- }
29
- }, [])
31
+ }, [])
30
32
 
31
- return (
32
- <Component
33
- {...props}
34
- ref={(ref: unknown) => {
35
- if (ref) {
36
- storedRef.current = getNativeRef(Component, ref)
37
- }
33
+ return (
34
+ <Component
35
+ {...props}
36
+ ref={(ref: unknown) => {
37
+ if (ref) {
38
+ storedRef.current = getNativeRef(Component, ref)
39
+ }
38
40
 
39
- passForwardedRef(props, ref, forwardedRef)
41
+ passForwardedRef(props, ref, forwardedRef)
40
42
 
41
- // @ts-ignore we don't know the type of the component
42
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
43
- }}
44
- />
45
- )
46
- })
43
+ // @ts-ignore we don't know the type of the component
44
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
45
+ }}
46
+ />
47
+ )
48
+ })
49
+
50
+ return copyComponentProperties(Component, UnistylesComponent)
51
+ }
@@ -4,40 +4,45 @@ import { getClassName } from './getClassname'
4
4
  import { isServer } from '../web/utils'
5
5
  import { UnistylesShadowRegistry } from '../web'
6
6
  import { maybeWarnAboutMultipleUnistyles } from './warn'
7
+ import { copyComponentProperties } from '../utils'
7
8
 
8
9
  type ComponentProps = {
9
10
  style?: UnistylesValues | Array<UnistylesValues>
10
11
  }
11
12
 
12
- export const createUnistylesElement = (Component: any) => React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
13
- let storedRef: HTMLElement | null = null
14
- const classNames = getClassName(props.style)
13
+ export const createUnistylesElement = (Component: any) => {
14
+ const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
15
+ let storedRef: HTMLElement | null = null
16
+ const classNames = getClassName(props.style)
15
17
 
16
- return (
17
- <Component
18
- {...props}
19
- style={classNames}
20
- ref={isServer() ? undefined : (ref: HTMLElement | null) => {
21
- // @ts-ignore we don't know the type of the component
22
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
18
+ return (
19
+ <Component
20
+ {...props}
21
+ style={classNames}
22
+ ref={isServer() ? undefined : (ref: HTMLElement | null) => {
23
+ // @ts-ignore we don't know the type of the component
24
+ maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
23
25
 
24
- if (!ref) {
26
+ if (!ref) {
27
+ // @ts-expect-error hidden from TS
28
+ UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
29
+ }
30
+
31
+ storedRef = ref
25
32
  // @ts-expect-error hidden from TS
26
- UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
27
- }
28
-
29
- storedRef = ref
30
- // @ts-expect-error hidden from TS
31
- UnistylesShadowRegistry.add(ref, classNames?.hash)
32
-
33
- if (typeof forwardedRef === 'function') {
34
- return forwardedRef(ref)
35
- }
36
-
37
- if (forwardedRef) {
38
- forwardedRef.current = ref
39
- }
40
- }}
41
- />
42
- )
43
- })
33
+ UnistylesShadowRegistry.add(ref, classNames?.hash)
34
+
35
+ if (typeof forwardedRef === 'function') {
36
+ return forwardedRef(ref)
37
+ }
38
+
39
+ if (forwardedRef) {
40
+ forwardedRef.current = ref
41
+ }
42
+ }}
43
+ />
44
+ )
45
+ })
46
+
47
+ return copyComponentProperties(Component, UnistylesComponent)
48
+ }