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.
- package/README.md +14 -2
- package/android/src/main/cxx/NativeUnistylesModule.cpp +1 -1
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -2
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +4 -0
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +2 -1
- package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -4
- package/components/native/Animated/package.json +5 -0
- package/components/native/NativeText/package.json +5 -0
- package/components/native/NativeView/package.json +5 -0
- package/cxx/core/Unistyle.h +4 -0
- package/cxx/core/UnistylesRegistry.cpp +24 -3
- package/cxx/core/UnistylesRegistry.h +3 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +7 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +27 -2
- package/cxx/parser/Parser.cpp +10 -4
- package/ios/NativePlatform+ios.swift +16 -4
- package/lib/commonjs/components/native/Animated.js +23 -0
- package/lib/commonjs/components/native/Animated.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +3 -1
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/NativeText.js +13 -0
- package/lib/commonjs/components/native/NativeText.js.map +1 -0
- package/lib/commonjs/components/native/NativeText.native.js +18 -0
- package/lib/commonjs/components/native/NativeText.native.js.map +1 -0
- package/lib/commonjs/components/native/NativeView.js +9 -0
- package/lib/commonjs/components/native/NativeView.js.map +1 -0
- package/lib/commonjs/components/native/NativeView.native.js +20 -0
- package/lib/commonjs/components/native/NativeView.native.js.map +1 -0
- package/lib/commonjs/components/native/Pressable.native.js +15 -2
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +26 -22
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +25 -21
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +34 -30
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/utils.js +16 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +5 -1
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/native/Animated.js +19 -0
- package/lib/module/components/native/Animated.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +3 -1
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/NativeText.js +4 -0
- package/lib/module/components/native/NativeText.js.map +1 -0
- package/lib/module/components/native/NativeText.native.js +15 -0
- package/lib/module/components/native/NativeText.native.js.map +1 -0
- package/lib/module/components/native/NativeView.js +5 -0
- package/lib/module/components/native/NativeView.js.map +1 -0
- package/lib/module/components/native/NativeView.native.js +17 -0
- package/lib/module/components/native/NativeView.native.js.map +1 -0
- package/lib/module/components/native/Pressable.native.js +15 -2
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +26 -22
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +25 -21
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +34 -30
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/utils.js +14 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +5 -1
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts +1 -3
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Animated.d.ts +39 -0
- package/lib/typescript/src/components/native/Animated.d.ts.map +1 -0
- package/lib/typescript/src/components/native/FlatList.d.ts +1 -3
- package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.d.ts +1 -3
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.d.ts +1 -8
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.native.d.ts +1 -2
- package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +1 -3
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/NativeText.d.ts +2 -0
- package/lib/typescript/src/components/native/NativeText.d.ts.map +1 -0
- package/lib/typescript/src/components/native/NativeText.native.d.ts +2 -0
- package/lib/typescript/src/components/native/NativeText.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/NativeView.d.ts +3 -0
- package/lib/typescript/src/components/native/NativeView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/NativeView.native.d.ts +3 -0
- package/lib/typescript/src/components/native/NativeView.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/RefreshControl.d.ts +1 -3
- package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ScrollView.d.ts +1 -3
- package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/SectionList.d.ts +1 -3
- package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Switch.d.ts +1 -3
- package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Text.d.ts +1 -3
- package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TextInput.d.ts +1 -3
- package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts +1 -3
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts +1 -3
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
- package/lib/typescript/src/components/native/View.d.ts +1 -3
- package/lib/typescript/src/components/native/View.d.ts.map +1 -1
- package/lib/typescript/src/components/native/VirtualizedList.d.ts +1 -3
- package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts +1 -7
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts +1 -2
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +2 -3
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +1 -0
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +1 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/package.json +9 -7
- package/plugin/consts.js +63 -0
- package/plugin/exotic.js +54 -0
- package/plugin/index.d.ts +79 -33
- package/plugin/index.js +23 -31
- package/plugin/stylesheet.js +12 -1
- package/plugin/variants.js +1 -1
- package/src/components/native/Animated.tsx +17 -0
- package/src/components/native/ImageBackground.tsx +4 -1
- package/src/components/native/NativeText.native.tsx +12 -0
- package/src/components/native/NativeText.tsx +1 -0
- package/src/components/native/NativeView.native.tsx +13 -0
- package/src/components/native/NativeView.tsx +3 -0
- package/src/components/native/Pressable.native.tsx +20 -2
- package/src/core/createUnistylesElement.native.tsx +28 -23
- package/src/core/createUnistylesElement.tsx +34 -29
- package/src/core/createUnistylesImageBackground.tsx +38 -33
- package/src/specs/StyleSheet/index.ts +2 -1
- package/src/utils.ts +17 -0
- package/src/web/utils/unistyle.ts +7 -1
package/plugin/consts.js
ADDED
@@ -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
|
+
}
|
package/plugin/exotic.js
ADDED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
-
|
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
|
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 &&
|
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
|
})
|
package/plugin/stylesheet.js
CHANGED
@@ -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
|
}
|
package/plugin/variants.js
CHANGED
@@ -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
|
-
|
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
|
-
|
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)
|
@@ -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
|
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) =>
|
20
|
-
const
|
20
|
+
export const createUnistylesElement = (Component: any) => {
|
21
|
+
const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
|
22
|
+
const storedRef = useRef<unknown>(null)
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
return (
|
34
|
+
<Component
|
35
|
+
{...props}
|
36
|
+
ref={(ref: unknown) => {
|
37
|
+
if (ref) {
|
38
|
+
storedRef.current = getNativeRef(Component, ref)
|
39
|
+
}
|
38
40
|
|
39
|
-
|
41
|
+
passForwardedRef(props, ref, forwardedRef)
|
40
42
|
|
41
|
-
|
42
|
-
|
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) =>
|
13
|
-
|
14
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
+
}
|