react-native-unistyles 3.0.0-nightly-20250329 → 3.0.0-rc.1
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 +1 -1
- package/cxx/core/UnistylesCommitHook.cpp +2 -2
- package/cxx/core/UnistylesRegistry.cpp +24 -20
- package/cxx/hybridObjects/HybridStyleSheet.cpp +15 -11
- package/cxx/parser/Parser.cpp +11 -8
- package/cxx/shadowTree/ShadowTrafficController.h +7 -9
- package/lib/commonjs/components/native/Image.js +26 -1
- package/lib/commonjs/components/native/Image.js.map +1 -1
- package/lib/commonjs/components/native/Image.native.js +10 -0
- package/lib/commonjs/components/native/Image.native.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +16 -28
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +7 -4
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +3 -19
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.native.js +6 -4
- package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
- package/lib/commonjs/core/createUnistylesImageBackground.js +7 -5
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +3 -5
- package/lib/commonjs/core/passForwardRef.js.map +1 -1
- package/lib/commonjs/server/serialize.js +1 -1
- package/lib/commonjs/server/serialize.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +28 -0
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
- package/lib/commonjs/web/utils/index.js +11 -0
- package/lib/commonjs/web/utils/index.js.map +1 -1
- package/lib/module/components/native/Image.js +25 -2
- package/lib/module/components/native/Image.js.map +1 -1
- package/lib/module/components/native/Image.native.js +6 -0
- package/lib/module/components/native/Image.native.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +17 -29
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +7 -4
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +4 -20
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesElement.native.js +6 -4
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +7 -5
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/passForwardRef.js +3 -5
- package/lib/module/core/passForwardRef.js.map +1 -1
- package/lib/module/server/serialize.js +1 -1
- package/lib/module/server/serialize.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/web/utils/createUnistylesRef.js +23 -0
- package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
- package/lib/module/web/utils/index.js +1 -0
- package/lib/module/web/utils/index.js.map +1 -1
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
- package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +8 -0
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
- package/lib/typescript/src/web/utils/index.d.ts +1 -0
- package/lib/typescript/src/web/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/native/Image.native.tsx +4 -0
- package/src/components/native/Image.tsx +35 -3
- package/src/components/native/ImageBackground.tsx +17 -33
- package/src/components/native/Pressable.native.tsx +12 -4
- package/src/core/createUnistylesElement.native.tsx +12 -6
- package/src/core/createUnistylesElement.tsx +6 -24
- package/src/core/createUnistylesImageBackground.tsx +16 -10
- package/src/core/passForwardRef.ts +5 -5
- package/src/server/serialize.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +1 -2
- package/src/web/utils/createUnistylesRef.ts +29 -0
- package/src/web/utils/index.ts +1 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/web/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,sBAAsB,CAAA"}
|
package/package.json
CHANGED
@@ -1,4 +1,36 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import React, { type ComponentProps, forwardRef } from 'react'
|
2
|
+
import { type ImageStyle, Image as NativeImage, type StyleProp, type ViewStyle } from 'react-native'
|
3
|
+
import { getClassName } from '../../core'
|
4
|
+
import { maybeWarnAboutMultipleUnistyles } from '../../core/warn'
|
5
|
+
import type { UnistylesValues } from '../../types'
|
6
|
+
import { copyComponentProperties } from '../../utils'
|
7
|
+
import { createUnistylesRef, keyInObject } from '../../web/utils'
|
3
8
|
|
4
|
-
|
9
|
+
type Props = ComponentProps<typeof NativeImage> & {
|
10
|
+
style?: UnistylesValues
|
11
|
+
imageStyle?: UnistylesValues
|
12
|
+
}
|
13
|
+
|
14
|
+
const UnistylesImage = forwardRef<unknown, Props>((props, forwardedRef) => {
|
15
|
+
const classNames = getClassName(props.style)
|
16
|
+
const ref = createUnistylesRef(classNames, forwardedRef)
|
17
|
+
const hasWidthStyle = typeof props.style === 'object' && keyInObject(props.style, 'width')
|
18
|
+
const hasHeightStyle = typeof props.style === 'object' && keyInObject(props.style, 'height')
|
19
|
+
|
20
|
+
maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, 'Image')
|
21
|
+
|
22
|
+
return (
|
23
|
+
<NativeImage
|
24
|
+
{...props}
|
25
|
+
style={[
|
26
|
+
classNames,
|
27
|
+
// Clear inline width and height extracted from source
|
28
|
+
hasWidthStyle && { width: '' },
|
29
|
+
hasHeightStyle && { height: '' }
|
30
|
+
] as StyleProp<ImageStyle>}
|
31
|
+
ref={ref}
|
32
|
+
/>
|
33
|
+
)
|
34
|
+
})
|
35
|
+
|
36
|
+
export const Image = copyComponentProperties(NativeImage, UnistylesImage)
|
@@ -2,10 +2,10 @@ import React from 'react'
|
|
2
2
|
import { forwardRef } from 'react'
|
3
3
|
import { type ImageStyle, ImageBackground as NativeImageBackground, type StyleProp, type ViewStyle } from 'react-native'
|
4
4
|
import { getClassName } from '../../core'
|
5
|
+
import { maybeWarnAboutMultipleUnistyles } from '../../core/warn'
|
5
6
|
import type { UnistylesValues } from '../../types'
|
6
7
|
import { copyComponentProperties } from '../../utils'
|
7
|
-
import {
|
8
|
-
import { isServer } from '../../web/utils'
|
8
|
+
import { createUnistylesRef, keyInObject } from '../../web/utils'
|
9
9
|
|
10
10
|
type Props = {
|
11
11
|
style?: UnistylesValues
|
@@ -13,44 +13,28 @@ type Props = {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
const UnistylesImageBackground = forwardRef<unknown, Props>((props, forwardedRef) => {
|
16
|
-
let storedRef: NativeImageBackground | null = null
|
17
|
-
let storedImageRef: NativeImageBackground | null = null
|
18
16
|
const styleClassNames = getClassName(props.style)
|
19
17
|
const imageClassNames = getClassName(props.imageStyle)
|
18
|
+
const ref = createUnistylesRef(styleClassNames, forwardedRef)
|
19
|
+
const imageRef = createUnistylesRef(imageClassNames)
|
20
|
+
const hasWidthStyle = typeof props.imageStyle === 'object' && keyInObject(props.imageStyle, 'width')
|
21
|
+
const hasHeightStyle = typeof props.imageStyle === 'object' && keyInObject(props.imageStyle, 'height')
|
22
|
+
|
23
|
+
maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, 'ImageBackground')
|
24
|
+
maybeWarnAboutMultipleUnistyles(props.imageStyle as ViewStyle, 'ImageBackground')
|
20
25
|
|
21
26
|
return (
|
22
27
|
<NativeImageBackground
|
23
28
|
{...props}
|
24
29
|
style={styleClassNames as StyleProp<ViewStyle>}
|
25
|
-
imageStyle={
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// @ts-expect-error hidden from TS
|
34
|
-
UnistylesShadowRegistry.add(ref, styleClassNames?.hash)
|
35
|
-
|
36
|
-
if (typeof forwardedRef === 'function') {
|
37
|
-
return forwardedRef(ref)
|
38
|
-
}
|
39
|
-
|
40
|
-
if (forwardedRef) {
|
41
|
-
forwardedRef.current = ref
|
42
|
-
}
|
43
|
-
}}
|
44
|
-
imageRef={isServer() ? undefined : ref => {
|
45
|
-
if (!ref) {
|
46
|
-
// @ts-expect-error hidden from TS
|
47
|
-
UnistylesShadowRegistry.remove(storedImageRef, imageClassNames?.hash)
|
48
|
-
}
|
49
|
-
|
50
|
-
storedImageRef = ref
|
51
|
-
// @ts-expect-error hidden from TS
|
52
|
-
UnistylesShadowRegistry.add(ref, imageClassNames?.hash)
|
53
|
-
}}
|
30
|
+
imageStyle={[
|
31
|
+
imageClassNames,
|
32
|
+
// Clear inline width and height extracted from source
|
33
|
+
hasWidthStyle && { width: '' },
|
34
|
+
hasHeightStyle && { height: '' }
|
35
|
+
] as StyleProp<ImageStyle>}
|
36
|
+
ref={ref}
|
37
|
+
imageRef={imageRef}
|
54
38
|
/>
|
55
39
|
)
|
56
40
|
})
|
@@ -50,10 +50,18 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ..
|
|
50
50
|
storedRef.current = ref
|
51
51
|
}
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
return passForwardedRef(
|
54
|
+
ref,
|
55
|
+
forwardedRef,
|
56
|
+
() => {
|
57
|
+
// @ts-expect-error - this is hidden from TS
|
58
|
+
UnistylesShadowRegistry.add(ref, unistyles)
|
59
|
+
},
|
60
|
+
() => {
|
61
|
+
// @ts-expect-error - this is hidden from TS
|
62
|
+
UnistylesShadowRegistry.remove(ref)
|
63
|
+
}
|
64
|
+
)
|
57
65
|
}}
|
58
66
|
style={state => {
|
59
67
|
const isPropStyleAFunction = typeof style === 'function'
|
@@ -38,15 +38,21 @@ export const createUnistylesElement = (Component: any) => {
|
|
38
38
|
storedRef.current = getNativeRef(Component, ref)
|
39
39
|
}
|
40
40
|
|
41
|
-
passForwardedRef(props, ref, forwardedRef)
|
42
|
-
|
43
41
|
// @ts-ignore we don't know the type of the component
|
44
42
|
maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
|
45
43
|
|
46
|
-
return (
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
return passForwardedRef(
|
45
|
+
ref,
|
46
|
+
forwardedRef,
|
47
|
+
() => {
|
48
|
+
// @ts-ignore this is hidden from TS
|
49
|
+
UnistylesShadowRegistry.add(ref, props.style)
|
50
|
+
},
|
51
|
+
() => {
|
52
|
+
// @ts-ignore this is hidden from TS
|
53
|
+
UnistylesShadowRegistry.remove(ref)
|
54
|
+
}
|
55
|
+
)
|
50
56
|
}}
|
51
57
|
/>
|
52
58
|
)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import React from 'react'
|
2
|
+
import type { ViewStyle } from 'react-native'
|
2
3
|
import type { UnistylesValues } from '../types'
|
3
4
|
import { copyComponentProperties } from '../utils'
|
4
|
-
import {
|
5
|
-
import { isServer } from '../web/utils'
|
5
|
+
import { createUnistylesRef } from '../web/utils'
|
6
6
|
import { getClassName } from './getClassname'
|
7
7
|
import { maybeWarnAboutMultipleUnistyles } from './warn'
|
8
8
|
|
@@ -12,34 +12,16 @@ type ComponentProps = {
|
|
12
12
|
|
13
13
|
export const createUnistylesElement = (Component: any) => {
|
14
14
|
const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
|
15
|
-
let storedRef: HTMLElement | null = null
|
16
15
|
const classNames = getClassName(props.style)
|
16
|
+
const ref = createUnistylesRef(classNames, forwardedRef)
|
17
|
+
|
18
|
+
maybeWarnAboutMultipleUnistyles(props.style as ViewStyle, Component.displayName)
|
17
19
|
|
18
20
|
return (
|
19
21
|
<Component
|
20
22
|
{...props}
|
21
23
|
style={classNames}
|
22
|
-
ref={
|
23
|
-
// @ts-ignore we don't know the type of the component
|
24
|
-
maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
|
25
|
-
|
26
|
-
if (!ref) {
|
27
|
-
// @ts-expect-error hidden from TS
|
28
|
-
UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
|
29
|
-
}
|
30
|
-
|
31
|
-
storedRef = ref
|
32
|
-
// @ts-expect-error hidden from TS
|
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
|
-
}}
|
24
|
+
ref={ref}
|
43
25
|
/>
|
44
26
|
)
|
45
27
|
})
|
@@ -27,17 +27,23 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
|
|
27
27
|
<Component
|
28
28
|
{...props}
|
29
29
|
ref={ref => {
|
30
|
-
passForwardedRef(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
return passForwardedRef(
|
31
|
+
ref,
|
32
|
+
forwardedRef,
|
33
|
+
() => {
|
34
|
+
// @ts-expect-error - this is hidden from TS
|
35
|
+
UnistylesShadowRegistry.add(ref, props.style)
|
36
|
+
},
|
37
|
+
() => {
|
38
|
+
// @ts-expect-error - this is hidden from TS
|
39
|
+
UnistylesShadowRegistry.remove(ref)
|
40
|
+
|
41
|
+
if (storedImageRef.current) {
|
42
|
+
// @ts-expect-error - this is hidden from TS
|
43
|
+
UnistylesShadowRegistry.remove(storedImageRef.current)
|
44
|
+
}
|
39
45
|
}
|
40
|
-
|
46
|
+
)
|
41
47
|
}}
|
42
48
|
imageRef={ref => {
|
43
49
|
if (ref) {
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import React from 'react'
|
2
|
-
import { UnistylesShadowRegistry } from '../specs'
|
3
2
|
|
4
3
|
export const passForwardedRef = <T>(
|
5
|
-
props: any,
|
6
4
|
ref: T,
|
7
|
-
forwardedRef: React.ForwardedRef<T
|
5
|
+
forwardedRef: React.ForwardedRef<T>,
|
6
|
+
onMount?: () => void,
|
7
|
+
onUnmount?: () => void
|
8
8
|
) => {
|
9
9
|
const passForwardedRef = () => {
|
10
10
|
if (typeof forwardedRef === 'function') {
|
@@ -19,10 +19,10 @@ export const passForwardedRef = <T>(
|
|
19
19
|
}
|
20
20
|
const forwardedRefReturnFn = passForwardedRef()
|
21
21
|
|
22
|
-
|
23
|
-
UnistylesShadowRegistry.add(ref, props.style)
|
22
|
+
onMount?.()
|
24
23
|
|
25
24
|
return () => {
|
26
25
|
forwardedRefReturnFn?.()
|
26
|
+
onUnmount?.()
|
27
27
|
}
|
28
28
|
}
|
package/src/server/serialize.ts
CHANGED
@@ -12,7 +12,7 @@ export const serialize = (value: any): string => {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
return `{${Object.entries(value)
|
15
|
-
.map(([key, value]) =>
|
15
|
+
.map(([key, value]) => `'${key}':${serialize(value)}`)
|
16
16
|
.join(',')}}`
|
17
17
|
default:
|
18
18
|
return JSON.stringify(value)
|
@@ -40,9 +40,8 @@ HybridShadowRegistry.add = (handle, styles) => {
|
|
40
40
|
? styles.flat()
|
41
41
|
: [styles]
|
42
42
|
|
43
|
-
// filter
|
43
|
+
// filter styles that are undefined or with no keys
|
44
44
|
const filteredStyles = stylesArray
|
45
|
-
.filter(style => !style?.initial?.updater)
|
46
45
|
.filter(style => style && Object.keys(style).length > 0)
|
47
46
|
.flat()
|
48
47
|
.filter(Boolean)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import type React from 'react'
|
2
|
+
import type { Nullable } from '../../types'
|
3
|
+
import { UnistylesWeb } from '../index'
|
4
|
+
import { isServer } from './common'
|
5
|
+
|
6
|
+
type ClassNames = {
|
7
|
+
hash: string
|
8
|
+
}
|
9
|
+
|
10
|
+
export const createUnistylesRef = <T>(classNames?: ClassNames, forwardedRef?: React.ForwardedRef<T>) => {
|
11
|
+
const storedRef = { current: null as Nullable<T> }
|
12
|
+
|
13
|
+
return isServer() ? undefined : (ref: Nullable<T>) => {
|
14
|
+
if (!ref) {
|
15
|
+
UnistylesWeb.shadowRegistry.remove(storedRef, classNames?.hash)
|
16
|
+
}
|
17
|
+
|
18
|
+
storedRef.current = ref
|
19
|
+
UnistylesWeb.shadowRegistry.add(ref, classNames?.hash)
|
20
|
+
|
21
|
+
if (typeof forwardedRef === 'function') {
|
22
|
+
return forwardedRef(ref)
|
23
|
+
}
|
24
|
+
|
25
|
+
if (forwardedRef) {
|
26
|
+
forwardedRef.current = ref
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
package/src/web/utils/index.ts
CHANGED