react-native-unistyles 3.0.0-rc.2 → 3.0.0-rc.4
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 +17 -17
- package/Unistyles.podspec +1 -0
- package/components/native/ActivityIndicator/package.json +1 -0
- package/components/native/Animated/package.json +1 -0
- package/components/native/FlatList/package.json +1 -0
- package/components/native/Image/package.json +1 -0
- package/components/native/ImageBackground/package.json +1 -0
- package/components/native/KeyboardAvoidingView/package.json +1 -0
- package/components/native/NativeText/package.json +1 -0
- package/components/native/NativeView/package.json +1 -0
- package/components/native/Pressable/package.json +1 -0
- package/components/native/RefreshControl/package.json +1 -0
- package/components/native/ScrollView/package.json +1 -0
- package/components/native/SectionList/package.json +1 -0
- package/components/native/Switch/package.json +1 -0
- package/components/native/Text/package.json +1 -0
- package/components/native/TextInput/package.json +1 -0
- package/components/native/TouchableHighlight/package.json +1 -0
- package/components/native/TouchableOpacity/package.json +1 -0
- package/components/native/View/package.json +1 -0
- package/components/native/VirtualizedList/package.json +1 -0
- package/cxx/core/UnistylesCommitHook.cpp +8 -1
- package/cxx/core/UnistylesMountHook.cpp +1 -3
- package/ios/NativePlatform+ios.swift +1 -1
- package/ios/NativePlatformListener+ios.swift +12 -7
- package/lib/commonjs/components/native/Image.js +4 -3
- package/lib/commonjs/components/native/Image.js.map +1 -1
- package/lib/commonjs/components/native/ImageBackground.js +3 -2
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +17 -5
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/getClassname.js +10 -4
- package/lib/commonjs/core/getClassname.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +2 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.js +4 -4
- package/lib/commonjs/hooks/useMedia.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.native.js +4 -4
- package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
- package/lib/commonjs/mocks.js +203 -0
- package/lib/commonjs/mocks.js.map +1 -0
- package/lib/commonjs/mq.js +1 -23
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/reanimated/index.js +13 -0
- package/lib/commonjs/reanimated/index.js.map +1 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
- package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
- package/lib/commonjs/server/getServerUnistyles.js +5 -3
- package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
- package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/commonjs/server/resetServerUnistyles.js +4 -2
- package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
- package/lib/commonjs/utils.js +23 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/web/convert/index.js +4 -7
- package/lib/commonjs/web/convert/index.js.map +1 -1
- package/lib/commonjs/web/convert/object/filter.js +7 -8
- package/lib/commonjs/web/convert/object/filter.js.map +1 -1
- package/lib/commonjs/web/create.js +6 -4
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/state.js +1 -1
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/index.js +7 -12
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/services.js +7 -2
- package/lib/commonjs/web/services.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +18 -4
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/types.js +2 -0
- package/lib/commonjs/web/types.js.map +1 -1
- package/lib/commonjs/web/utils/createUnistylesRef.js +7 -4
- package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
- package/lib/commonjs/web/utils/index.js +0 -11
- package/lib/commonjs/web/utils/index.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +40 -12
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web-only/getWebProps.js +19 -0
- package/lib/commonjs/web-only/getWebProps.js.map +1 -0
- package/lib/commonjs/web-only/index.js +13 -0
- package/lib/commonjs/web-only/index.js.map +1 -0
- package/lib/module/components/native/Image.js +4 -3
- package/lib/module/components/native/Image.js.map +1 -1
- package/lib/module/components/native/ImageBackground.js +2 -1
- package/lib/module/components/native/ImageBackground.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +18 -6
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/getClassname.js +8 -4
- package/lib/module/core/getClassname.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
- package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.js +2 -1
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
- package/lib/module/hooks/useMedia.js +1 -1
- package/lib/module/hooks/useMedia.js.map +1 -1
- package/lib/module/hooks/useMedia.native.js +1 -1
- package/lib/module/hooks/useMedia.native.js.map +1 -1
- package/lib/module/mocks.js +201 -0
- package/lib/module/mocks.js.map +1 -0
- package/lib/module/mq.js +0 -19
- package/lib/module/mq.js.map +1 -1
- package/lib/module/reanimated/index.js +4 -0
- package/lib/module/reanimated/index.js.map +1 -0
- package/lib/module/reanimated/useAnimatedTheme.js +17 -0
- package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
- package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
- package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
- package/lib/module/server/getServerUnistyles.js +3 -3
- package/lib/module/server/getServerUnistyles.js.map +1 -1
- package/lib/module/server/hydrateServerUnistyles.js +2 -2
- package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
- package/lib/module/server/resetServerUnistyles.js +2 -2
- package/lib/module/server/resetServerUnistyles.js.map +1 -1
- package/lib/module/utils.js +19 -0
- package/lib/module/utils.js.map +1 -1
- package/lib/module/web/convert/index.js +4 -7
- package/lib/module/web/convert/index.js.map +1 -1
- package/lib/module/web/convert/object/filter.js +3 -4
- package/lib/module/web/convert/object/filter.js.map +1 -1
- package/lib/module/web/create.js +4 -4
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/state.js +1 -1
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/index.js +4 -10
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/services.js +7 -1
- package/lib/module/web/services.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +18 -4
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/types.js +1 -1
- package/lib/module/web/types.js.map +1 -1
- package/lib/module/web/utils/createUnistylesRef.js +5 -4
- package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
- package/lib/module/web/utils/index.js +0 -1
- package/lib/module/web/utils/index.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +32 -9
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web-only/getWebProps.js +14 -0
- package/lib/module/web-only/getWebProps.js.map +1 -0
- package/lib/module/web-only/index.js +4 -0
- package/lib/module/web-only/index.js.map +1 -0
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/getClassname.d.ts +5 -5
- package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/mocks.d.ts +2 -0
- package/lib/typescript/src/mocks.d.ts.map +1 -0
- package/lib/typescript/src/mq.d.ts +0 -8
- package/lib/typescript/src/mq.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/index.d.ts +2 -0
- package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
- package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
- package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +8 -0
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/index.d.ts +2 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
- package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +0 -5
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/services.d.ts +6 -1
- package/lib/typescript/src/web/services.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +3 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +8 -5
- package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/index.d.ts +0 -1
- package/lib/typescript/src/web/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
- package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
- package/lib/typescript/src/web-only/index.d.ts +2 -0
- package/lib/typescript/src/web-only/index.d.ts.map +1 -0
- package/package.json +43 -7
- package/plugin/index.js +24 -17
- package/reanimated/package.json +6 -0
- package/src/components/native/Image.tsx +4 -3
- package/src/components/native/ImageBackground.tsx +2 -1
- package/src/core/createUnistylesElement.tsx +26 -9
- package/src/core/getClassname.ts +14 -4
- package/src/core/useProxifiedUnistyles/listener.ts +3 -3
- package/src/core/withUnistyles/withUnistyles.tsx +2 -1
- package/src/hooks/useMedia.native.ts +1 -1
- package/src/hooks/useMedia.ts +1 -1
- package/src/mocks.ts +217 -0
- package/src/mq.ts +0 -24
- package/src/reanimated/index.ts +1 -0
- package/src/reanimated/useAnimatedTheme.native.ts +21 -0
- package/src/reanimated/useAnimatedTheme.ts +19 -0
- package/src/server/getServerUnistyles.tsx +3 -3
- package/src/server/hydrateServerUnistyles.ts +3 -2
- package/src/server/resetServerUnistyles.ts +4 -3
- package/src/utils.ts +25 -0
- package/src/web/convert/index.ts +5 -7
- package/src/web/convert/object/filter.ts +4 -4
- package/src/web/create.ts +4 -4
- package/src/web/css/state.ts +1 -1
- package/src/web/index.ts +4 -16
- package/src/web/services.ts +14 -1
- package/src/web/shadowRegistry.ts +20 -5
- package/src/web/types.ts +9 -4
- package/src/web/utils/createUnistylesRef.ts +12 -8
- package/src/web/utils/index.ts +0 -1
- package/src/web/utils/unistyle.ts +47 -13
- package/src/web-only/getWebProps.ts +18 -0
- package/src/web-only/index.ts +2 -0
- package/web-only/package.json +6 -0
package/src/web/services.ts
CHANGED
@@ -3,8 +3,9 @@ import { UnistylesRegistry } from './registry'
|
|
3
3
|
import { UnistylesRuntime } from './runtime'
|
4
4
|
import { UnistylesShadowRegistry } from './shadowRegistry'
|
5
5
|
import { UnistylesState } from './state'
|
6
|
+
import { isServer } from './utils'
|
6
7
|
|
7
|
-
|
8
|
+
class UnistylesServices {
|
8
9
|
runtime: UnistylesRuntime
|
9
10
|
registry: UnistylesRegistry
|
10
11
|
shadowRegistry: UnistylesShadowRegistry
|
@@ -26,3 +27,15 @@ export class UnistylesServices {
|
|
26
27
|
this.services.listener = this.listener
|
27
28
|
}
|
28
29
|
}
|
30
|
+
|
31
|
+
declare global {
|
32
|
+
// @ts-ignore
|
33
|
+
var __unistyles__: UnistylesServices
|
34
|
+
}
|
35
|
+
|
36
|
+
if (isServer() && !globalThis.__unistyles__) {
|
37
|
+
// @ts-ignore
|
38
|
+
globalThis.__unistyles__ = new UnistylesServices()
|
39
|
+
}
|
40
|
+
|
41
|
+
export const services = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { UnistyleDependency } from '../specs'
|
1
|
+
import { UnistyleDependency } from '../specs/NativePlatform/NativePlatform.nitro'
|
2
2
|
import type { UnistylesTheme, UnistylesValues } from '../types'
|
3
3
|
import { deepMergeObjects } from '../utils'
|
4
|
-
import type { UnistylesServices } from './types'
|
5
|
-
import { extractSecrets, extractUnistyleDependencies } from './utils'
|
4
|
+
import type { UniGeneratedStyle, UnistylesServices } from './types'
|
5
|
+
import { extractSecrets, extractUnistyleDependencies, isGeneratedUnistyle, isServer } from './utils'
|
6
6
|
import { getVariants } from './variants'
|
7
7
|
|
8
8
|
export class UnistylesShadowRegistry {
|
@@ -28,6 +28,13 @@ export class UnistylesShadowRegistry {
|
|
28
28
|
}
|
29
29
|
|
30
30
|
addStyles = (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
|
31
|
+
const [firstStyle] = unistyles
|
32
|
+
|
33
|
+
// If it is already a generated style, return it
|
34
|
+
if (firstStyle && isGeneratedUnistyle(firstStyle)) {
|
35
|
+
return firstStyle as UniGeneratedStyle
|
36
|
+
}
|
37
|
+
|
31
38
|
const getParsedStyles = () => {
|
32
39
|
const allStyles = unistyles.map(unistyle => {
|
33
40
|
const secrets = extractSecrets(unistyle)
|
@@ -37,6 +44,11 @@ export class UnistylesShadowRegistry {
|
|
37
44
|
return unistyle
|
38
45
|
}
|
39
46
|
|
47
|
+
// Animated styles - shouldn't be processed
|
48
|
+
if (Object.keys(secrets).length === 0) {
|
49
|
+
return {}
|
50
|
+
}
|
51
|
+
|
40
52
|
const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
|
41
53
|
const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
|
42
54
|
const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
|
@@ -52,7 +64,10 @@ export class UnistylesShadowRegistry {
|
|
52
64
|
this.services.registry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
|
53
65
|
}
|
54
66
|
|
55
|
-
return
|
67
|
+
return {
|
68
|
+
...resultWithVariants,
|
69
|
+
...resultWithVariants._web
|
70
|
+
} as UnistylesValues
|
56
71
|
})
|
57
72
|
|
58
73
|
return deepMergeObjects(...allStyles)
|
@@ -89,7 +104,7 @@ export class UnistylesShadowRegistry {
|
|
89
104
|
getScopedTheme = () => this.scopedTheme
|
90
105
|
|
91
106
|
remove = (ref: any, hash?: string) => {
|
92
|
-
if (!(ref instanceof HTMLElement) || !hash) {
|
107
|
+
if (isServer() || !(ref instanceof HTMLElement) || !hash) {
|
93
108
|
return
|
94
109
|
}
|
95
110
|
|
package/src/web/types.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { UnistylesListener } from './listener'
|
2
|
-
import type{ UnistylesRegistry } from './registry'
|
3
|
-
import type{ UnistylesRuntime } from './runtime'
|
4
|
-
import type{ UnistylesShadowRegistry } from './shadowRegistry'
|
5
|
-
import type{ UnistylesState } from './state'
|
2
|
+
import type { UnistylesRegistry } from './registry'
|
3
|
+
import type { UnistylesRuntime } from './runtime'
|
4
|
+
import type { UnistylesShadowRegistry } from './shadowRegistry'
|
5
|
+
import type { UnistylesState } from './state'
|
6
6
|
|
7
7
|
export type UnistylesServices = {
|
8
8
|
runtime: UnistylesRuntime,
|
@@ -11,3 +11,8 @@ export type UnistylesServices = {
|
|
11
11
|
state: UnistylesState,
|
12
12
|
listener: UnistylesListener
|
13
13
|
}
|
14
|
+
|
15
|
+
export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
|
16
|
+
export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
|
17
|
+
|
18
|
+
export type UniGeneratedStyle = Record<UniGeneratedKey, string>
|
@@ -1,22 +1,26 @@
|
|
1
1
|
import type React from 'react'
|
2
|
-
import type { Nullable } from '../../types'
|
3
|
-
import
|
2
|
+
import type { Nullable, UnistylesValues } from '../../types'
|
3
|
+
import * as unistyles from '../services'
|
4
4
|
import { isServer } from './common'
|
5
5
|
|
6
|
-
type
|
7
|
-
|
8
|
-
|
6
|
+
type Styles = readonly [
|
7
|
+
{
|
8
|
+
hash: string
|
9
|
+
},
|
10
|
+
Array<UnistylesValues>
|
11
|
+
]
|
9
12
|
|
10
|
-
export const createUnistylesRef = <T>(
|
13
|
+
export const createUnistylesRef = <T>(styles?: Styles, forwardedRef?: React.ForwardedRef<T>) => {
|
11
14
|
const storedRef = { current: null as Nullable<T> }
|
15
|
+
const [classNames] = styles ?? []
|
12
16
|
|
13
17
|
return isServer() ? undefined : (ref: Nullable<T>) => {
|
14
18
|
if (!ref) {
|
15
|
-
|
19
|
+
unistyles.services.shadowRegistry.remove(storedRef, classNames?.hash)
|
16
20
|
}
|
17
21
|
|
18
22
|
storedRef.current = ref
|
19
|
-
|
23
|
+
unistyles.services.shadowRegistry.add(ref, classNames?.hash)
|
20
24
|
|
21
25
|
if (typeof forwardedRef === 'function') {
|
22
26
|
return forwardedRef(ref)
|
package/src/web/utils/index.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
import { Animated } from 'react-native'
|
1
2
|
import type { UnistylesBreakpoints } from '../../global'
|
2
|
-
import {
|
3
|
-
import type { UnistyleDependency } from '../../specs/NativePlatform'
|
3
|
+
import type { UnistyleDependency } from '../../specs/NativePlatform/NativePlatform.nitro'
|
4
4
|
import { ColorScheme, Orientation } from '../../specs/types'
|
5
5
|
import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
|
6
|
-
import {
|
6
|
+
import { isUnistylesMq, parseMq } from '../../utils'
|
7
|
+
import * as unistyles from '../services'
|
8
|
+
import { UNI_GENERATED_KEYS, type UniGeneratedKey, type UniGeneratedStyle } from '../types'
|
7
9
|
import { keyInObject, reduceObject } from './common'
|
8
10
|
|
9
11
|
export const schemeToTheme = (scheme: ColorScheme) => {
|
@@ -49,13 +51,7 @@ export const extractSecrets = (object: any) => {
|
|
49
51
|
return undefined
|
50
52
|
}
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
-
if (Object.keys(hiddenSecrets).length === 0) {
|
55
|
-
return undefined
|
56
|
-
}
|
57
|
-
|
58
|
-
return reduceObject(hiddenSecrets, secret => secret.value)
|
54
|
+
return reduceObject(Object.getOwnPropertyDescriptors(secrets), secret => secret.value)
|
59
55
|
}
|
60
56
|
|
61
57
|
export const removeInlineStyles = (values: UnistylesValues) => {
|
@@ -87,10 +83,10 @@ export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
|
|
87
83
|
return `@media ${queries}`
|
88
84
|
}
|
89
85
|
|
90
|
-
const breakpointValue =
|
86
|
+
const breakpointValue = unistyles.services.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
|
91
87
|
const nextBreakpoint = allBreakpoints
|
92
|
-
.filter((b): b is keyof UnistylesBreakpoints => b in
|
93
|
-
.map(b =>
|
88
|
+
.filter((b): b is keyof UnistylesBreakpoints => b in unistyles.services.runtime.breakpoints)
|
89
|
+
.map(b => unistyles.services.runtime.breakpoints[b] as number)
|
94
90
|
.sort((a, b) => a - b)
|
95
91
|
.find(b => b > breakpointValue)
|
96
92
|
const queries = [
|
@@ -110,3 +106,41 @@ export const extractUnistyleDependencies = (value: any) => {
|
|
110
106
|
|
111
107
|
return Array.isArray(dependencies) ? dependencies : []
|
112
108
|
}
|
109
|
+
|
110
|
+
export const checkForProp = (value: any, prop: string): boolean => {
|
111
|
+
if (Array.isArray(value)) {
|
112
|
+
return value.some(nestedValue => checkForProp(nestedValue, prop))
|
113
|
+
}
|
114
|
+
|
115
|
+
if (typeof value === 'object' && value !== null) {
|
116
|
+
return keyInObject(value, prop)
|
117
|
+
? true
|
118
|
+
: keyInObject(value, '_web')
|
119
|
+
? checkForProp(value._web, prop)
|
120
|
+
: false
|
121
|
+
}
|
122
|
+
|
123
|
+
return false
|
124
|
+
}
|
125
|
+
|
126
|
+
export const checkForAnimated = (value: any): boolean => {
|
127
|
+
if (Array.isArray(value)) {
|
128
|
+
return value.some(checkForAnimated)
|
129
|
+
}
|
130
|
+
|
131
|
+
if (typeof value === 'object' && value !== null) {
|
132
|
+
const objectValues = Object.values(value)
|
133
|
+
const secrets = extractSecrets(value)
|
134
|
+
|
135
|
+
// @ts-expect-error React Native Web exports Animated.AnimatedNode as Animated.Node
|
136
|
+
return value instanceof Animated.Node ||
|
137
|
+
objectValues.length > 0 && objectValues.some(checkForAnimated) ||
|
138
|
+
secrets && Object.keys(secrets).length === 0
|
139
|
+
}
|
140
|
+
|
141
|
+
return false
|
142
|
+
}
|
143
|
+
|
144
|
+
export const isGeneratedUnistyle = (value: Record<string, any>): value is UniGeneratedStyle => {
|
145
|
+
return Object.keys(value).every(key => UNI_GENERATED_KEYS.includes(key as UniGeneratedKey))
|
146
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { StyleProp } from 'react-native'
|
2
|
+
import { getClassName } from '../core'
|
3
|
+
import type { RNStyle, UnistylesValues } from '../types'
|
4
|
+
import { createUnistylesRef } from '../web/utils/createUnistylesRef'
|
5
|
+
|
6
|
+
export const getWebProps = <T>(style: StyleProp<RNStyle>) => {
|
7
|
+
const styles = getClassName(style as UnistylesValues)
|
8
|
+
const ref = createUnistylesRef<T>(styles)
|
9
|
+
const [generatedStyles] = styles ?? []
|
10
|
+
|
11
|
+
return {
|
12
|
+
className: [
|
13
|
+
generatedStyles?.hash,
|
14
|
+
generatedStyles?.injectedClassName,
|
15
|
+
].filter(Boolean).join(' '),
|
16
|
+
ref
|
17
|
+
}
|
18
|
+
}
|