react-native-unistyles 3.0.0-nightly-20250210 → 3.0.0-nightly-20250214
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 +3 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +16 -1
- package/cxx/core/HostUnistyle.cpp +15 -5
- package/cxx/core/HostUnistyle.h +1 -0
- package/cxx/core/UnistylesCommitHook.cpp +20 -17
- package/cxx/core/UnistylesRegistry.cpp +8 -6
- package/cxx/shadowTree/ShadowTrafficController.h +10 -4
- package/cxx/shadowTree/ShadowTreeManager.cpp +38 -35
- package/lib/commonjs/components/native/Pressable.native.js +7 -0
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +3 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +7 -0
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +4 -2
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +2 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/package.json +19 -9
- package/plugin/index.d.ts +51 -18
- package/plugin/index.js +785 -178
- package/src/components/native/Pressable.native.tsx +8 -0
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +2 -2
- package/src/core/withUnistyles/withUnistyles.native.tsx +5 -3
- package/src/types/stylesheet.ts +1 -1
- package/plugin/consts.js +0 -63
- package/plugin/exotic.js +0 -54
- package/plugin/import.js +0 -51
- package/plugin/ref.js +0 -11
- package/plugin/stylesheet.js +0 -565
- package/plugin/variants.js +0 -66
@@ -40,10 +40,18 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
40
40
|
<NativePressableReactNative
|
41
41
|
{...props}
|
42
42
|
ref={ref => {
|
43
|
+
const isPropStyleAFunction = typeof style === 'function'
|
44
|
+
const unistyles = isPropStyleAFunction
|
45
|
+
? style.call(style, { pressed: false })
|
46
|
+
: getStyles(style as unknown as Record<string, any>)
|
47
|
+
|
43
48
|
if (ref) {
|
44
49
|
storedRef.current = ref
|
45
50
|
}
|
46
51
|
|
52
|
+
// @ts-expect-error - this is hidden from TS
|
53
|
+
UnistylesShadowRegistry.add(storedRef.current, unistyles)
|
54
|
+
|
47
55
|
return passForwardedRef(props, ref, forwardedRef)
|
48
56
|
}}
|
49
57
|
style={state => {
|
@@ -26,8 +26,8 @@ const RTDependencyMap = {
|
|
26
26
|
themeName: UnistyleDependency.ThemeName,
|
27
27
|
} satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
|
28
28
|
|
29
|
-
export const useProxifiedUnistyles = () => {
|
30
|
-
const scopedTheme = UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
|
29
|
+
export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
|
30
|
+
const scopedTheme = forcedTheme ?? UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
|
31
31
|
const [dependencies] = useState(() => new Set<number>())
|
32
32
|
const [theme, setTheme] = useState(UnistylesRuntime.getTheme(scopedTheme))
|
33
33
|
const [_, runtimeChanged] = useReducer(() => ({}), {})
|
@@ -1,5 +1,6 @@
|
|
1
|
-
import React, { forwardRef, useEffect, type ComponentType } from 'react'
|
2
|
-
import type
|
1
|
+
import React, { forwardRef, useEffect, type ComponentType, useRef } from 'react'
|
2
|
+
import { type UnistyleDependency, UnistylesShadowRegistry } from '../../specs'
|
3
|
+
import type { UnistylesTheme } from '../../types'
|
3
4
|
import type { PartialBy } from '../../types/common'
|
4
5
|
import { deepMergeObjects } from '../../utils'
|
5
6
|
import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
|
@@ -38,7 +39,8 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
38
39
|
// @ts-ignore we don't know the type of the component
|
39
40
|
maybeWarnAboutMultipleUnistyles(narrowedProps.contentContainerStyle, `withUnistyles(${Component.displayName ?? Component.name ?? 'Unknown'})`)
|
40
41
|
|
41
|
-
const
|
42
|
+
const scopedTheme = useRef(UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme)
|
43
|
+
const { proxifiedRuntime, proxifiedTheme, addDependencies } = useProxifiedUnistyles(scopedTheme.current)
|
42
44
|
|
43
45
|
useEffect(() => {
|
44
46
|
const styleSecrets = getSecrets(narrowedProps.style)
|
package/src/types/stylesheet.ts
CHANGED
@@ -62,7 +62,7 @@ export type UnistylesValues = FlatUnistylesValues & {
|
|
62
62
|
} & VariantsAndCompoundVariants & {
|
63
63
|
[propName in NestedKeys]?: UnistyleNestedStyles[propName]
|
64
64
|
} & {
|
65
|
-
_web?: CSSProperties & CustomClassName & {
|
65
|
+
_web?: ToDeepUnistyles<CSSProperties> & CustomClassName & {
|
66
66
|
[propName in Pseudo]?: ToDeepUnistyles<CSSProperties>
|
67
67
|
}
|
68
68
|
}
|
package/plugin/consts.js
DELETED
@@ -1,63 +0,0 @@
|
|
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
DELETED
@@ -1,54 +0,0 @@
|
|
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/import.js
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
/** @param {import('./index').UnistylesPluginPass} state */
|
2
|
-
function addUnistylesImport(t, path, state) {
|
3
|
-
const localNames = Object.keys(state.reactNativeImports)
|
4
|
-
const names = Object.values(state.reactNativeImports)
|
5
|
-
const pairs = Object.entries(state.reactNativeImports)
|
6
|
-
const nodesToRemove = []
|
7
|
-
|
8
|
-
// remove rn-imports
|
9
|
-
path.node.body.forEach(node => {
|
10
|
-
// user might have multiple imports like import type, import
|
11
|
-
if (t.isImportDeclaration(node) && node.source.value === 'react-native') {
|
12
|
-
node.specifiers = node.specifiers.filter(specifier => !localNames.some(name => name === specifier.local.name))
|
13
|
-
|
14
|
-
if (node.specifiers.length === 0) {
|
15
|
-
nodesToRemove.push(node)
|
16
|
-
}
|
17
|
-
}
|
18
|
-
})
|
19
|
-
|
20
|
-
// remove RNWeb imports
|
21
|
-
names.forEach(name => {
|
22
|
-
const rnWebImport = path.node.body.find(node => t.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`)
|
23
|
-
|
24
|
-
if (rnWebImport) {
|
25
|
-
rnWebImport.specifiers = []
|
26
|
-
}
|
27
|
-
})
|
28
|
-
|
29
|
-
// import components from react-native-unistyles
|
30
|
-
pairs.forEach(([localName, name]) => {
|
31
|
-
const newImport = t.importDeclaration(
|
32
|
-
[t.importSpecifier(t.identifier(localName), t.identifier(name))],
|
33
|
-
t.stringLiteral(state.opts.isLocal
|
34
|
-
? state.file.opts.filename.split('react-native-unistyles').at(0).concat(`react-native-unistyles/components/native/${name}`)
|
35
|
-
: `react-native-unistyles/components/native/${name}`
|
36
|
-
)
|
37
|
-
)
|
38
|
-
|
39
|
-
path.node.body.unshift(newImport)
|
40
|
-
})
|
41
|
-
|
42
|
-
// cleanup
|
43
|
-
nodesToRemove.forEach(node => path.node.body.splice(path.node.body.indexOf(node), 1))
|
44
|
-
}
|
45
|
-
|
46
|
-
const isInsideNodeModules = state => state.file.opts.filename.includes('node_modules')
|
47
|
-
|
48
|
-
module.exports = {
|
49
|
-
isInsideNodeModules,
|
50
|
-
addUnistylesImport
|
51
|
-
}
|
package/plugin/ref.js
DELETED