react-native-unistyles 3.0.0-beta.5 → 3.0.0-beta.6
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/android/src/main/java/com/unistyles/UnistylesPackage.kt +6 -6
- 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 +9 -3
- package/ios/NativePlatform+ios.swift +16 -4
- package/ios/UnistylesModuleOnLoad.h +4 -4
- package/ios/UnistylesModuleOnLoad.mm +4 -8
- 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 +16 -3
- 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 +37 -23
- 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/core/getClassname.js +1 -3
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/server/getServerUnistyles.js +3 -1
- package/lib/commonjs/server/getServerUnistyles.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 +17 -4
- 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 +38 -24
- package/lib/module/core/createUnistylesElement.native.js.map +1 -1
- package/lib/module/core/createUnistylesImageBackground.js +35 -31
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
- package/lib/module/core/getClassname.js +2 -4
- package/lib/module/core/getClassname.js.map +1 -1
- package/lib/module/server/getServerUnistyles.js +3 -1
- package/lib/module/server/getServerUnistyles.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/core/getClassname.d.ts +2 -2
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
- package/lib/typescript/src/server/getServerUnistyles.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 +11 -9
- package/plugin/consts.js +63 -0
- package/plugin/exotic.js +54 -0
- package/plugin/index.d.ts +84 -36
- package/plugin/index.js +27 -33
- 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 +22 -4
- package/src/core/createUnistylesElement.native.tsx +42 -27
- package/src/core/createUnistylesElement.tsx +34 -29
- package/src/core/createUnistylesImageBackground.tsx +39 -34
- package/src/core/getClassname.ts +5 -4
- package/src/server/getServerUnistyles.tsx +2 -1
- package/src/specs/StyleSheet/index.ts +2 -1
- package/src/utils.ts +17 -0
- package/src/web/utils/unistyle.ts +7 -1
@@ -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)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { forwardRef,
|
1
|
+
import React, { forwardRef, useLayoutEffect, useRef } from 'react'
|
2
2
|
import { Pressable as NativePressableReactNative } from 'react-native'
|
3
3
|
import type { PressableProps as Props, View } from 'react-native'
|
4
4
|
import { UnistylesShadowRegistry } from '../../specs'
|
@@ -8,10 +8,26 @@ 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
|
|
14
|
-
|
30
|
+
useLayoutEffect(() => {
|
15
31
|
return () => {
|
16
32
|
if (storedRef.current) {
|
17
33
|
// @ts-expect-error - this is hidden from TS
|
@@ -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
|
|
@@ -1,36 +1,51 @@
|
|
1
|
-
import React, {
|
1
|
+
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
|
-
|
7
|
+
const getNativeRef = (Component: any, ref: any) => {
|
8
|
+
switch (Component.name) {
|
9
|
+
case 'KeyboardAvoidingView':
|
10
|
+
return ref.viewRef?.current
|
11
|
+
case 'FlatList':
|
12
|
+
return ref.getNativeScrollRef?.()
|
13
|
+
case 'VirtualizedList':
|
14
|
+
return ref.getScrollRef?.()
|
15
|
+
default:
|
16
|
+
return ref
|
17
|
+
}
|
18
|
+
}
|
8
19
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
// @ts-ignore
|
13
|
-
UnistylesShadowRegistry.remove(storedRef.current)
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}, [])
|
20
|
+
export const createUnistylesElement = (Component: any) => {
|
21
|
+
const UnistylesComponent = React.forwardRef((props, forwardedRef) => {
|
22
|
+
const storedRef = useRef<unknown>(null)
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
storedRef.current = Component.name === 'KeyboardAvoidingView'
|
24
|
-
// @ts-ignore this is special case for KeyboardAvoidingView
|
25
|
-
? ref.viewRef.current
|
26
|
-
: ref
|
24
|
+
useLayoutEffect(() => {
|
25
|
+
return () => {
|
26
|
+
if (storedRef.current) {
|
27
|
+
// @ts-ignore
|
28
|
+
UnistylesShadowRegistry.remove(storedRef.current)
|
27
29
|
}
|
30
|
+
}
|
31
|
+
}, [])
|
32
|
+
|
33
|
+
return (
|
34
|
+
<Component
|
35
|
+
{...props}
|
36
|
+
ref={(ref: unknown) => {
|
37
|
+
if (ref) {
|
38
|
+
storedRef.current = getNativeRef(Component, ref)
|
39
|
+
}
|
40
|
+
|
41
|
+
passForwardedRef(props, ref, forwardedRef)
|
28
42
|
|
29
|
-
|
43
|
+
// @ts-ignore we don't know the type of the component
|
44
|
+
maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
|
45
|
+
}}
|
46
|
+
/>
|
47
|
+
)
|
48
|
+
})
|
30
49
|
|
31
|
-
|
32
|
-
|
33
|
-
}}
|
34
|
-
/>
|
35
|
-
)
|
36
|
-
})
|
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
|
+
}
|
@@ -1,45 +1,50 @@
|
|
1
|
-
import React, {
|
1
|
+
import React, { useLayoutEffect, useRef } from 'react'
|
2
2
|
import type { Image, ImageBackground, ImageBackgroundProps } from 'react-native'
|
3
3
|
import { UnistylesShadowRegistry } from '../specs'
|
4
4
|
import { passForwardedRef } from './passForwardRef'
|
5
5
|
import { maybeWarnAboutMultipleUnistyles } from './warn'
|
6
|
+
import { copyComponentProperties } from '../utils'
|
6
7
|
|
7
|
-
export const createUnistylesImageBackground = (Component: typeof ImageBackground) =>
|
8
|
-
const
|
8
|
+
export const createUnistylesImageBackground = (Component: typeof ImageBackground) => {
|
9
|
+
const UnistylesImageBackground = React.forwardRef<ImageBackground, ImageBackgroundProps>((props, forwardedRef) => {
|
10
|
+
const storedImageRef = useRef<Image | null>(null)
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
useLayoutEffect(() => {
|
13
|
+
return () => {
|
14
|
+
if (storedImageRef.current) {
|
15
|
+
// @ts-ignore
|
16
|
+
UnistylesShadowRegistry.remove(storedImageRef.current)
|
17
|
+
}
|
15
18
|
}
|
16
|
-
}
|
17
|
-
}, [])
|
19
|
+
}, [])
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
// @ts-expect-error we don't know the type of the component
|
22
|
+
maybeWarnAboutMultipleUnistyles(props.style, 'ImageBackground')
|
23
|
+
// @ts-ignore we don't know the type of the component
|
24
|
+
maybeWarnAboutMultipleUnistyles(props.imageStyle, 'ImageBackground')
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
return (
|
27
|
+
<Component
|
28
|
+
{...props}
|
29
|
+
ref={ref => {
|
30
|
+
passForwardedRef(props, ref, forwardedRef)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
return () => {
|
33
|
+
// @ts-ignore
|
34
|
+
UnistylesShadowRegistry.remove(ref)
|
35
|
+
}
|
36
|
+
}}
|
37
|
+
imageRef={ref => {
|
38
|
+
if (ref) {
|
39
|
+
storedImageRef.current = ref
|
40
|
+
}
|
41
|
+
|
42
|
+
// @ts-expect-error web types are not compatible with RN styles
|
43
|
+
UnistylesShadowRegistry.add(ref, props.imageStyle)
|
44
|
+
}}
|
45
|
+
/>
|
46
|
+
)
|
47
|
+
})
|
39
48
|
|
40
|
-
|
41
|
-
|
42
|
-
}}
|
43
|
-
/>
|
44
|
-
)
|
45
|
-
})
|
49
|
+
return copyComponentProperties(Component, UnistylesImageBackground)
|
50
|
+
}
|
package/src/core/getClassname.ts
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
import type { UnistylesValues } from '../types'
|
2
|
-
import {
|
1
|
+
import type { UnistylesValues } from '../types'
|
2
|
+
import { UnistylesWeb } from '../web'
|
3
3
|
|
4
4
|
export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>) => {
|
5
5
|
if (!unistyle) {
|
6
6
|
return undefined
|
7
7
|
}
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
const { hash, injectedClassName } = UnistylesWeb.shadowRegistry.addStyles(
|
10
|
+
Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
|
11
|
+
)
|
11
12
|
|
12
13
|
return hash ? { $$css: true, hash, injectedClassName } : undefined
|
13
14
|
}
|
@@ -15,6 +15,7 @@ export const getServerUnistyles = ({ includeRNWStyles = true }: ServerUnistylesS
|
|
15
15
|
return <>
|
16
16
|
{rnwStyle && <style id='rnw-style'>{rnwStyle}</style>}
|
17
17
|
<style id='unistyles-web'>{css}</style>
|
18
|
-
|
18
|
+
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: Needs the json quotes to be unescaped */}
|
19
|
+
<script id='unistyles-script' dangerouslySetInnerHTML={{ __html: `window.__UNISTYLES_STATE__ = ${JSON.stringify(state)}`}} />
|
19
20
|
</>
|
20
21
|
}
|
package/src/utils.ts
CHANGED
@@ -24,3 +24,20 @@ export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources:
|
|
24
24
|
|
25
25
|
return target
|
26
26
|
}
|
27
|
+
|
28
|
+
export const copyComponentProperties = (Component: any, UnistylesComponent: any) => {
|
29
|
+
Object.entries(Component).forEach(([key, value]) => {
|
30
|
+
// Filter out the keys we don't want to copy
|
31
|
+
if (['$$typeof', 'render'].includes(key)) {
|
32
|
+
return
|
33
|
+
}
|
34
|
+
|
35
|
+
UnistylesComponent[key] = value
|
36
|
+
})
|
37
|
+
|
38
|
+
// Those are not enumerable, so we need to copy them manually
|
39
|
+
UnistylesComponent.displayName = Component.displayName
|
40
|
+
UnistylesComponent.name = Component.name
|
41
|
+
|
42
|
+
return UnistylesComponent
|
43
|
+
}
|
@@ -49,7 +49,13 @@ export const extractSecrets = (object: any) => {
|
|
49
49
|
return undefined
|
50
50
|
}
|
51
51
|
|
52
|
-
|
52
|
+
const hiddenSecrets = Object.getOwnPropertyDescriptors(secrets)
|
53
|
+
|
54
|
+
if (Object.keys(hiddenSecrets).length === 0) {
|
55
|
+
return undefined
|
56
|
+
}
|
57
|
+
|
58
|
+
return reduceObject(hiddenSecrets, secret => secret.value)
|
53
59
|
}
|
54
60
|
|
55
61
|
export const removeInlineStyles = (values: UnistylesValues) => {
|