react-native-unistyles 3.0.0-alpha.38 → 3.0.0-alpha.39
Sign up to get free protection for your applications and to get access to all the features.
- package/android/build.gradle +4 -4
- package/android/src/main/java/com/unistyles/NativePlatform+android.kt +13 -30
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +22 -18
- package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +10 -5
- package/cxx/core/UnistyleWrapper.h +27 -10
- package/cxx/core/UnistylesRegistry.cpp +34 -10
- package/cxx/core/UnistylesRegistry.h +2 -2
- package/cxx/hybridObjects/HybridNavigationBar.cpp +0 -4
- package/cxx/hybridObjects/HybridNavigationBar.h +0 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +7 -3
- package/cxx/hybridObjects/HybridStatusBar.cpp +0 -4
- package/cxx/hybridObjects/HybridStatusBar.h +0 -1
- package/cxx/hybridObjects/HybridStyleSheet.cpp +59 -28
- package/cxx/hybridObjects/HybridStyleSheet.h +7 -3
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +37 -6
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +7 -3
- package/cxx/parser/Parser.cpp +7 -7
- package/cxx/parser/Parser.h +2 -2
- package/ios/NativePlatform+ios.swift +2 -4
- package/ios/NativePlatform+keyboard.swift +1 -1
- package/ios/NativePlatformListener+ios.swift +6 -6
- package/ios/UnistylesModuleOnLoad.h +1 -6
- package/lib/commonjs/core/createUnistylesComponent.js +27 -20
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
- package/lib/commonjs/core/createUnistylesComponent.native.js +14 -17
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +0 -15
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +5 -7
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +0 -5
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -2
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/utils.js +26 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +1 -1
- package/lib/commonjs/web/convert/object/boxShadow.js +2 -1
- package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
- package/lib/commonjs/web/convert/object/objectStyle.js +3 -2
- package/lib/commonjs/web/convert/object/objectStyle.js.map +1 -1
- package/lib/commonjs/web/convert/shadow/boxShadow.js +1 -1
- package/lib/commonjs/web/convert/shadow/textShadow.js +1 -1
- package/lib/commonjs/web/create.js +2 -1
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/index.js +1 -1
- package/lib/commonjs/web/listener.js +18 -2
- package/lib/commonjs/web/listener.js.map +1 -1
- package/lib/commonjs/web/mock.js +1 -2
- package/lib/commonjs/web/mock.js.map +1 -1
- package/lib/commonjs/web/runtime.js +5 -2
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +53 -73
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/utils/common.js +1 -24
- package/lib/commonjs/web/utils/common.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/commonjs/web/variants/getVariants.js +1 -1
- package/lib/module/core/createUnistylesComponent.js +28 -21
- package/lib/module/core/createUnistylesComponent.js.map +1 -1
- package/lib/module/core/createUnistylesComponent.native.js +15 -18
- package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
- package/lib/module/specs/NavigtionBar/index.js +0 -10
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +5 -7
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -6
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +0 -2
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/utils.js +21 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/module/web/convert/index.js +1 -1
- package/lib/module/web/convert/index.js.map +1 -1
- package/lib/module/web/convert/object/boxShadow.js +2 -1
- package/lib/module/web/convert/object/boxShadow.js.map +1 -1
- package/lib/module/web/convert/object/objectStyle.js +2 -1
- package/lib/module/web/convert/object/objectStyle.js.map +1 -1
- package/lib/module/web/convert/shadow/boxShadow.js +1 -1
- package/lib/module/web/convert/shadow/boxShadow.js.map +1 -1
- package/lib/module/web/convert/shadow/textShadow.js +1 -1
- package/lib/module/web/convert/shadow/textShadow.js.map +1 -1
- package/lib/module/web/create.js +2 -1
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/index.js +1 -1
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/listener.js +18 -2
- package/lib/module/web/listener.js.map +1 -1
- package/lib/module/web/mock.js +1 -2
- package/lib/module/web/mock.js.map +1 -1
- package/lib/module/web/runtime.js +6 -3
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +51 -71
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/utils/common.js +0 -22
- package/lib/module/web/utils/common.js.map +1 -1
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web/variants/getVariants.js +1 -1
- package/lib/module/web/variants/getVariants.js.map +1 -1
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +1 -1
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +1 -1
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -4
- package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts +0 -1
- package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts +1 -15
- package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts +0 -1
- package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts.map +1 -1
- package/lib/typescript/src/specs/StatusBar/index.d.ts +2 -9
- package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +2 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/listener.d.ts.map +1 -1
- package/lib/typescript/src/web/mock.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +1 -3
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/common.d.ts +0 -4
- package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +57 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +69 -0
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +8 -16
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +2 -4
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/{Func_void_std__vector_UnistyleDependency_.kt → Func_void_UnistylesNativeMiniRuntime.kt} +5 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/{Func_void.kt → Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt} +5 -5
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +4 -12
- package/nitrogen/generated/android/unistylesOnLoad.cpp +4 -4
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +43 -30
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +2 -8
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +2 -4
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +10 -32
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +0 -2
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +2 -4
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +0 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +0 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +0 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +0 -1
- package/package.json +4 -2
- package/plugin/common.js +12 -1
- package/plugin/index.js +12 -10
- package/plugin/ref.js +80 -15
- package/plugin/style.js +113 -18
- package/src/core/createUnistylesComponent.native.tsx +15 -22
- package/src/core/createUnistylesComponent.tsx +29 -23
- package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -4
- package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.ts +0 -1
- package/src/specs/NavigtionBar/index.ts +1 -30
- package/src/specs/ShadowRegistry/index.ts +8 -11
- package/src/specs/StatusBar/UnistylesStatusBar.nitro.ts +0 -1
- package/src/specs/StatusBar/index.ts +2 -17
- package/src/specs/UnistylesRuntime/index.ts +1 -2
- package/src/utils.ts +22 -0
- package/src/web/convert/index.ts +1 -1
- package/src/web/convert/object/boxShadow.ts +2 -1
- package/src/web/convert/object/objectStyle.ts +2 -1
- package/src/web/convert/shadow/boxShadow.ts +1 -1
- package/src/web/convert/shadow/textShadow.ts +1 -1
- package/src/web/create.ts +2 -1
- package/src/web/index.ts +1 -1
- package/src/web/listener.ts +22 -2
- package/src/web/mock.ts +1 -2
- package/src/web/runtime.ts +7 -3
- package/src/web/shadowRegistry.ts +55 -70
- package/src/web/utils/common.ts +0 -26
- package/src/web/utils/unistyle.ts +1 -1
- package/src/web/variants/getVariants.ts +1 -1
- package/nitrogen/generated/android/c++/JFunc_void.hpp +0 -48
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency_.hpp +0 -60
@@ -1,4 +1,4 @@
|
|
1
|
-
import React, { useEffect, useState, type ComponentType } from 'react'
|
1
|
+
import React, { useEffect, useState, type ComponentType, forwardRef, useRef, useMemo } from 'react'
|
2
2
|
import type { UnistylesTheme } from '../types'
|
3
3
|
import { UnistylesRuntime } from '../specs'
|
4
4
|
import { UnistyleDependency } from '../specs/NativePlatform'
|
@@ -6,6 +6,7 @@ import type { PartialBy } from '../types/common'
|
|
6
6
|
import { UnistylesListener } from '../web/listener'
|
7
7
|
import { UnistylesShadowRegistry } from '../web'
|
8
8
|
import { equal } from '../web/utils'
|
9
|
+
import { deepMergeObjects } from '../utils'
|
9
10
|
|
10
11
|
const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'] as const
|
11
12
|
const ALL_DEPENDENCIES = Object.values(UnistyleDependency).filter((dependency): dependency is UnistyleDependency => typeof dependency === 'number')
|
@@ -13,34 +14,40 @@ const ALL_DEPENDENCIES = Object.values(UnistyleDependency).filter((dependency):
|
|
13
14
|
type SupportedStyleProps = typeof SUPPORTED_STYLE_PROPS[number]
|
14
15
|
|
15
16
|
const useShadowRegistry = (style?: Record<string, any>) => {
|
16
|
-
const [classNames, setClassNames] = useState<Array<string>>([])
|
17
17
|
const [ref] = useState(document.createElement('div'))
|
18
|
+
const oldClassNames = useRef<Array<string>>([])
|
19
|
+
const classNames = useMemo(() => {
|
20
|
+
if (!style) {
|
21
|
+
return []
|
22
|
+
}
|
18
23
|
|
19
|
-
|
20
|
-
UnistylesShadowRegistry
|
21
|
-
.add(ref, style)
|
22
|
-
.then(newClassNames => {
|
23
|
-
if (equal(classNames, newClassNames)) {
|
24
|
-
return
|
25
|
-
}
|
24
|
+
const newClassNames = UnistylesShadowRegistry.add(ref, [style], undefined, []) ?? []
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if (equal(oldClassNames.current, newClassNames)) {
|
27
|
+
return oldClassNames.current
|
28
|
+
}
|
29
|
+
|
30
|
+
oldClassNames.current = newClassNames
|
31
|
+
|
32
|
+
return newClassNames
|
33
|
+
}, [style])
|
30
34
|
|
31
35
|
useEffect(() => () => {
|
32
36
|
// Remove styles on unmount
|
33
|
-
|
37
|
+
if (style) {
|
38
|
+
UnistylesShadowRegistry.add(null, [style], undefined, [])
|
39
|
+
}
|
34
40
|
})
|
35
41
|
|
36
42
|
return classNames
|
37
43
|
}
|
38
44
|
|
39
45
|
export const createUnistylesComponent = <TProps extends Record<string, any>, TMappings extends Partial<Omit<TProps, SupportedStyleProps>>>(Component: ComponentType<TProps>, mappings?: (theme: UnistylesTheme) => TMappings) => {
|
40
|
-
return
|
46
|
+
return forwardRef<unknown, PartialBy<TProps, keyof TMappings | SupportedStyleProps>>((props, ref) => {
|
47
|
+
const narrowedProps = props as PartialBy<TProps, keyof TMappings | SupportedStyleProps>
|
41
48
|
const [mappingsProps, setMappingsProps] = useState(mappings?.(UnistylesRuntime.getTheme()))
|
42
|
-
const styleClassNames = useShadowRegistry(
|
43
|
-
const contentContainerStyleClassNames = useShadowRegistry(
|
49
|
+
const styleClassNames = useShadowRegistry(narrowedProps.style)
|
50
|
+
const contentContainerStyleClassNames = useShadowRegistry(narrowedProps.contentContainerStyle)
|
44
51
|
|
45
52
|
useEffect(() => {
|
46
53
|
const disposeMappings = UnistylesListener.addListeners(ALL_DEPENDENCIES, () => {
|
@@ -54,18 +61,17 @@ export const createUnistylesComponent = <TProps extends Record<string, any>, TMa
|
|
54
61
|
})
|
55
62
|
|
56
63
|
return () => disposeMappings()
|
57
|
-
}, [mappingsProps,
|
64
|
+
}, [mappingsProps, narrowedProps.style])
|
58
65
|
|
59
66
|
const combinedProps = {
|
60
|
-
...mappingsProps,
|
61
|
-
...
|
62
|
-
...props.style ? {
|
67
|
+
...deepMergeObjects(props, (mappingsProps ?? {}) as object),
|
68
|
+
...narrowedProps.style ? {
|
63
69
|
style: {
|
64
70
|
$$css: true,
|
65
71
|
'unistyles': styleClassNames.join(' ')
|
66
72
|
},
|
67
73
|
} : {},
|
68
|
-
...
|
74
|
+
...narrowedProps.contentContainerStyle ? {
|
69
75
|
style: {
|
70
76
|
$$css: true,
|
71
77
|
'unistyles': contentContainerStyleClassNames.join(' ')
|
@@ -73,6 +79,6 @@ export const createUnistylesComponent = <TProps extends Record<string, any>, TMa
|
|
73
79
|
} : {},
|
74
80
|
} as unknown as TProps
|
75
81
|
|
76
|
-
return <Component {...combinedProps} />
|
77
|
-
}
|
82
|
+
return <Component {...combinedProps} ref={ref} />
|
83
|
+
})
|
78
84
|
}
|
@@ -51,15 +51,13 @@ export interface NativePlatform extends HybridObject<{ ios: 'swift', android: 'k
|
|
51
51
|
getPrefersRtlDirection(): boolean,
|
52
52
|
|
53
53
|
setRootViewBackgroundColor(color: number): void,
|
54
|
-
setNavigationBarBackgroundColor?(color: number): void,
|
55
54
|
setNavigationBarHidden?(isHidden: boolean): void,
|
56
55
|
setStatusBarHidden(isHidden: boolean): void,
|
57
|
-
setStatusBarBackgroundColor?(color: number): void,
|
58
56
|
setImmersiveMode(isEnabled: boolean): void,
|
59
57
|
|
60
58
|
// private
|
61
59
|
getMiniRuntime(): UnistylesNativeMiniRuntime,
|
62
|
-
registerPlatformListener(callback: (dependencies: Array<UnistyleDependency
|
63
|
-
registerImeListener(callback: () => void): void,
|
60
|
+
registerPlatformListener(callback: (dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) => void): void,
|
61
|
+
registerImeListener(callback: (miniRuntime: UnistylesNativeMiniRuntime) => void): void,
|
64
62
|
unregisterPlatformListeners(): void
|
65
63
|
}
|
@@ -1,30 +1 @@
|
|
1
|
-
|
2
|
-
import type { UnistylesNavigationBar as UnistylesNavigationBarSpec } from './UnistylesNavigationBar.nitro'
|
3
|
-
import type { Color } from '../types'
|
4
|
-
|
5
|
-
interface PrivateUnistylesNavigationBar extends Omit<UnistylesNavigationBarSpec, 'setBackgroundColor'> {
|
6
|
-
/**
|
7
|
-
* Apps targeting Android SDK 35
|
8
|
-
* This API is deprecated but continues to affect 3-button navigation
|
9
|
-
* @deprecated
|
10
|
-
*/
|
11
|
-
setBackgroundColor(color?: string): void,
|
12
|
-
_setBackgroundColor(color?: Color): void
|
13
|
-
}
|
14
|
-
|
15
|
-
export const attachNavigationBarJSMethods = (hybridObject: UnistylesNavigationBar) => {
|
16
|
-
const privateHybrid = hybridObject as PrivateUnistylesNavigationBar
|
17
|
-
|
18
|
-
privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
|
19
|
-
hybridObject.setBackgroundColor = (color?: string) => {
|
20
|
-
const parsedColor = processColor(color) ?? 0
|
21
|
-
|
22
|
-
privateHybrid._setBackgroundColor(parsedColor as number)
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
type PrivateMethods =
|
27
|
-
| '_setBackgroundColor'
|
28
|
-
| 'dispose'
|
29
|
-
|
30
|
-
export type UnistylesNavigationBar = Omit<PrivateUnistylesNavigationBar, PrivateMethods>
|
1
|
+
export type { UnistylesNavigationBar } from './UnistylesNavigationBar.nitro'
|
@@ -4,10 +4,10 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
|
|
4
4
|
|
5
5
|
interface ShadowRegistry extends UnistylesShadowRegistrySpec {
|
6
6
|
// Babel API
|
7
|
-
add(handle?: ViewHandle,
|
8
|
-
remove(handle?: ViewHandle
|
7
|
+
add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>): void,
|
8
|
+
remove(handle?: ViewHandle): void,
|
9
9
|
// JSI
|
10
|
-
link(node: ShadowNode,
|
10
|
+
link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>): void,
|
11
11
|
unlink(node: ShadowNode): void
|
12
12
|
}
|
13
13
|
|
@@ -26,18 +26,15 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
|
|
26
26
|
return node
|
27
27
|
}
|
28
28
|
|
29
|
-
HybridShadowRegistry.add = (handle,
|
29
|
+
HybridShadowRegistry.add = (handle, styles, variants, args) => {
|
30
30
|
// virtualized nodes can be null
|
31
|
-
if (!handle || !
|
31
|
+
if (!handle || !styles || !Array.isArray(styles)) {
|
32
32
|
return
|
33
33
|
}
|
34
34
|
|
35
|
-
//
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? [])
|
35
|
+
// filter Reanimated styles
|
36
|
+
const filteredStyles = styles.filter(style => !style?.initial?.updater)
|
37
|
+
HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [])
|
41
38
|
}
|
42
39
|
|
43
40
|
HybridShadowRegistry.remove = handle => {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { StatusBar as NativeStatusBar } from 'react-native'
|
2
2
|
import type { UnistylesStatusBar as UnistylesStatusBarSpec } from './UnistylesStatusBar.nitro'
|
3
|
-
import {
|
3
|
+
import { StatusBarStyle } from '../types'
|
4
4
|
|
5
5
|
export type StatusBarHiddenAnimation = 'none' | 'fade' | 'slide'
|
6
6
|
|
@@ -8,13 +8,6 @@ interface PrivateUnistylesStatusBar extends Omit<UnistylesStatusBarSpec, 'setBac
|
|
8
8
|
setStyle(style: StatusBarStyle, animated?: boolean): void,
|
9
9
|
setHidden(isHidden: boolean, animation?: StatusBarHiddenAnimation): void,
|
10
10
|
_setHidden(isHidden: boolean, animation?: StatusBarHiddenAnimation): void,
|
11
|
-
/**
|
12
|
-
* Apps targeting Android SDK 35
|
13
|
-
* This API is deprecated as status bar background color is always transparent
|
14
|
-
* @deprecated
|
15
|
-
*/
|
16
|
-
setBackgroundColor(color?: string): void,
|
17
|
-
_setBackgroundColor(color?: Color): void
|
18
11
|
}
|
19
12
|
|
20
13
|
export const attachStatusBarJSMethods = (hybridObject: UnistylesStatusBar) => {
|
@@ -36,17 +29,9 @@ export const attachStatusBarJSMethods = (hybridObject: UnistylesStatusBar) => {
|
|
36
29
|
NativeStatusBar.setHidden(isHidden, animation)
|
37
30
|
privateHybrid._setHidden(isHidden)
|
38
31
|
}
|
39
|
-
|
40
|
-
privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
|
41
|
-
hybridObject.setBackgroundColor = (color?: string) => {
|
42
|
-
const parsedColor = processColor(color) ?? 0
|
43
|
-
|
44
|
-
privateHybrid._setBackgroundColor(parsedColor as number)
|
45
|
-
}
|
46
32
|
}
|
47
33
|
|
48
34
|
type PrivateMethods =
|
49
|
-
| '_setBackgroundColor'
|
50
35
|
| '_setHidden'
|
51
36
|
| 'dispose'
|
52
37
|
|
@@ -3,7 +3,7 @@ import { NitroModules } from 'react-native-nitro-modules'
|
|
3
3
|
import type { UnistylesRuntime as UnistylesRuntimeSpec, UnistylesMiniRuntime } from './UnistylesRuntime.nitro'
|
4
4
|
import type { AppBreakpoint, AppTheme, AppThemeName, Color, ColorScheme, Orientation } from '../types'
|
5
5
|
import { attachStatusBarJSMethods, type UnistylesStatusBar } from '../StatusBar'
|
6
|
-
import {
|
6
|
+
import { type UnistylesNavigationBar } from '../NavigtionBar'
|
7
7
|
import type { AndroidContentSizeCategory, IOSContentSizeCategory, UnistylesTheme } from '../../types'
|
8
8
|
import { isIOS } from '../../common'
|
9
9
|
import type { UnistylesThemes } from '../../global'
|
@@ -57,7 +57,6 @@ if (isIOS) {
|
|
57
57
|
}
|
58
58
|
|
59
59
|
attachStatusBarJSMethods(HybridUnistylesRuntime.statusBar)
|
60
|
-
attachNavigationBarJSMethods(HybridUnistylesRuntime.navigationBar)
|
61
60
|
|
62
61
|
export const Runtime = HybridUnistylesRuntime as UnistylesRuntime
|
63
62
|
|
package/src/utils.ts
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources: Array<T>) => {
|
2
|
+
const target = {} as T
|
3
|
+
|
4
|
+
sources.forEach(source => {
|
5
|
+
Object.keys(source).forEach(key => {
|
6
|
+
const sourceValue = source[key]
|
7
|
+
const targetValue = target[key]
|
8
|
+
|
9
|
+
if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
|
10
|
+
// @ts-expect-error - can't assign to generic
|
11
|
+
target[key] = deepMergeObjects(targetValue, sourceValue)
|
12
|
+
|
13
|
+
return
|
14
|
+
}
|
15
|
+
|
16
|
+
// @ts-expect-error - can't assign to generic
|
17
|
+
target[key] = sourceValue
|
18
|
+
})
|
19
|
+
})
|
20
|
+
|
21
|
+
return target
|
22
|
+
}
|
package/src/web/convert/index.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { UnistylesValues } from '../../types'
|
2
2
|
import { isPseudo } from './pseudo'
|
3
3
|
import { getStyle } from './style'
|
4
|
-
import { deepMergeObjects } from '
|
4
|
+
import { deepMergeObjects } from '../../utils'
|
5
5
|
import { getTransformStyle, getBoxShadow, getFilterStyle } from './object'
|
6
6
|
import { isShadow, isFilter, isTextShadow, isTransform, isBoxShadow } from './utils'
|
7
7
|
import { getTextShadowStyle, getBoxShadowStyle } from './shadow'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { BoxShadowValue } from 'react-native'
|
2
2
|
import { normalizeNumericValue } from '../utils'
|
3
|
-
import {
|
3
|
+
import { keyInObject } from '../../utils'
|
4
|
+
import { deepMergeObjects } from '../../../utils'
|
4
5
|
|
5
6
|
const createBoxShadowValue = (style: BoxShadowValue) => {
|
6
7
|
const { offsetX, offsetY, blurRadius = 0, spreadDistance = 0, color = '#000', inset } = style
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { deepMergeObjects
|
1
|
+
import { deepMergeObjects } from '../../../utils'
|
2
|
+
import { keyInObject } from '../../utils'
|
2
3
|
|
3
4
|
type Styles = Record<string, any>
|
4
5
|
type Normalize<TStyles extends Styles> = (key: keyof TStyles, value: TStyles[keyof TStyles]) => any
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { deepMergeObjects } from '
|
1
|
+
import { deepMergeObjects } from '../../../utils'
|
2
2
|
import { BOX_SHADOW_STYLES, type BoxShadow } from '../types'
|
3
3
|
import { extractShadowValue, normalizeColor, normalizeNumericValue } from '../utils'
|
4
4
|
import { getShadowBreakpoints } from './getShadowBreakpoints'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { deepMergeObjects } from '
|
1
|
+
import { deepMergeObjects } from '../../../utils'
|
2
2
|
import { TEXT_SHADOW_STYLES, type TextShadow } from '../types'
|
3
3
|
import { extractShadowValue, normalizeColor, normalizeNumericValue } from '../utils'
|
4
4
|
import { getShadowBreakpoints } from './getShadowBreakpoints'
|
package/src/web/create.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import type { ReactNativeStyleSheet } from '../types'
|
2
2
|
import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
|
3
|
-
import { assignSecrets, reduceObject, getStyles
|
3
|
+
import { assignSecrets, reduceObject, getStyles } from './utils'
|
4
|
+
import { deepMergeObjects } from '../utils'
|
4
5
|
import { UnistylesRuntime } from './runtime'
|
5
6
|
import { createUseVariants, getVariants } from './variants'
|
6
7
|
|
package/src/web/index.ts
CHANGED
package/src/web/listener.ts
CHANGED
@@ -17,8 +17,28 @@ class UnistylesListenerBuilder {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
this.isInitialized = true
|
20
|
-
UnistylesRuntime.darkMedia?.addEventListener('change',
|
21
|
-
|
20
|
+
UnistylesRuntime.darkMedia?.addEventListener('change', event => {
|
21
|
+
if (!event.matches) {
|
22
|
+
return
|
23
|
+
}
|
24
|
+
|
25
|
+
this.emitChange(UnistyleDependency.ColorScheme)
|
26
|
+
|
27
|
+
if (UnistylesRuntime.hasAdaptiveThemes) {
|
28
|
+
this.emitChange(UnistyleDependency.Theme)
|
29
|
+
}
|
30
|
+
})
|
31
|
+
UnistylesRuntime.lightMedia?.addEventListener('change', event => {
|
32
|
+
if (!event.matches) {
|
33
|
+
return
|
34
|
+
}
|
35
|
+
|
36
|
+
this.emitChange(UnistyleDependency.ColorScheme)
|
37
|
+
|
38
|
+
if (UnistylesRuntime.hasAdaptiveThemes) {
|
39
|
+
this.emitChange(UnistyleDependency.Theme)
|
40
|
+
}
|
41
|
+
})
|
22
42
|
window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
|
23
43
|
window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
|
24
44
|
}
|
package/src/web/mock.ts
CHANGED
@@ -6,7 +6,6 @@ export const StatusBar: StatusBarSpec = {
|
|
6
6
|
height: 0,
|
7
7
|
setStyle: () => {},
|
8
8
|
setHidden: () => {},
|
9
|
-
setBackgroundColor: () => {},
|
10
9
|
equals: () => true,
|
11
10
|
toString: () => 'StatusBar',
|
12
11
|
__type: 'web',
|
@@ -17,8 +16,8 @@ export const NavigationBar: NavigationBarSpec = {
|
|
17
16
|
width: 0,
|
18
17
|
height: 0,
|
19
18
|
setHidden: () => {},
|
20
|
-
setBackgroundColor: () => {},
|
21
19
|
equals: () => true,
|
20
|
+
dispose: () => {},
|
22
21
|
toString: () => 'NavigationBar',
|
23
22
|
__type: 'web',
|
24
23
|
name: 'NavigationBar'
|
package/src/web/runtime.ts
CHANGED
@@ -5,7 +5,7 @@ import { WebContentSizeCategory } from '../types'
|
|
5
5
|
import { UnistylesListener } from './listener'
|
6
6
|
import { NavigationBar, StatusBar } from './mock'
|
7
7
|
import { UnistylesState } from './state'
|
8
|
-
import {
|
8
|
+
import { isServer, schemeToTheme } from './utils'
|
9
9
|
|
10
10
|
class UnistylesRuntimeBuilder {
|
11
11
|
lightMedia = this.getLightMedia()
|
@@ -47,6 +47,10 @@ class UnistylesRuntimeBuilder {
|
|
47
47
|
}
|
48
48
|
|
49
49
|
get themeName() {
|
50
|
+
if (UnistylesState.hasAdaptiveThemes) {
|
51
|
+
return schemeToTheme(this.colorScheme) as AppThemeName
|
52
|
+
}
|
53
|
+
|
50
54
|
return UnistylesState.themeName
|
51
55
|
}
|
52
56
|
|
@@ -167,12 +171,12 @@ class UnistylesRuntimeBuilder {
|
|
167
171
|
this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName)
|
168
172
|
}
|
169
173
|
|
170
|
-
setRootViewBackgroundColor = (
|
174
|
+
setRootViewBackgroundColor = (color: string) => {
|
171
175
|
if (isServer()) {
|
172
176
|
return
|
173
177
|
}
|
174
178
|
|
175
|
-
document.documentElement.style.backgroundColor =
|
179
|
+
document.documentElement.style.backgroundColor = color
|
176
180
|
}
|
177
181
|
|
178
182
|
setImmersiveMode = () => {}
|
@@ -2,7 +2,8 @@ import type { UnistylesValues } from '../types'
|
|
2
2
|
import { convertUnistyles } from './convert'
|
3
3
|
import { UnistylesListener } from './listener'
|
4
4
|
import { UnistylesRegistry } from './registry'
|
5
|
-
import { deepMergeObjects
|
5
|
+
import { deepMergeObjects } from '../utils'
|
6
|
+
import { equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
|
6
7
|
import { getVariants } from './variants'
|
7
8
|
|
8
9
|
type Style = UnistylesValues | ((...args: Array<any>) => UnistylesValues)
|
@@ -19,27 +20,13 @@ class UnistylesShadowRegistryBuilder {
|
|
19
20
|
private resultsMap = new Map<HTMLElement, UnistylesValues>()
|
20
21
|
private hashMap = new Map<HTMLElement, string>()
|
21
22
|
private classNamesMap = new Map<HTMLElement, Array<string>>()
|
22
|
-
private timeoutMap = new Map<HTMLElement, NodeJS.Timeout>()
|
23
|
-
private queuedResultMap = new Map<HTMLElement, Record<string, any>>()
|
24
23
|
|
25
|
-
add = (ref: any, _style
|
24
|
+
add = (ref: any, _style: Array<Style>, _variants: Record<string, any> | undefined, _args: Array<Array<any>>) => {
|
26
25
|
// Style is not provided
|
27
26
|
if (!_style) {
|
28
27
|
return
|
29
28
|
}
|
30
29
|
|
31
|
-
// Array of styles
|
32
|
-
if (Array.isArray(_style)) {
|
33
|
-
_style.forEach(style => this.add(ref, style, _variants, _args))
|
34
|
-
|
35
|
-
return
|
36
|
-
}
|
37
|
-
|
38
|
-
// Not a unistyle
|
39
|
-
if (!Object.keys(_style).some(key => key.startsWith('__uni__'))) {
|
40
|
-
return
|
41
|
-
}
|
42
|
-
|
43
30
|
// Ref is unmounted, remove style tags from the document
|
44
31
|
if (ref === null) {
|
45
32
|
const secrets = extractSecrets(_style)
|
@@ -68,70 +55,34 @@ class UnistylesShadowRegistryBuilder {
|
|
68
55
|
return
|
69
56
|
}
|
70
57
|
|
71
|
-
|
58
|
+
const styles = _style.filter(style => Object.keys(style ?? {}).some(key => key.startsWith('__uni__')))
|
59
|
+
|
60
|
+
// No unistyles
|
61
|
+
if (styles.length === 0) {
|
62
|
+
return
|
63
|
+
}
|
64
|
+
|
65
|
+
const parsedStyles = styles.flatMap((style, styleIndex) => extractSecrets(style).map(secret => {
|
72
66
|
const { __uni__key, __uni__stylesheet, __uni__variants, __uni__args = [], __uni__refs } = secret
|
73
67
|
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
|
74
68
|
const style = newComputedStylesheet[__uni__key]!
|
75
|
-
const args = _args ?? __uni__args
|
76
69
|
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
|
70
|
+
const args = _args[styleIndex] ? _args[styleIndex] : __uni__args
|
77
71
|
const result = typeof style === 'function'
|
78
72
|
? style(...args)
|
79
73
|
: style
|
80
74
|
const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
|
81
75
|
const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
|
76
|
+
const dependencies = extractUnistyleDependencies(resultWithVariants)
|
82
77
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
const timeout = this.timeoutMap.get(ref)
|
88
|
-
|
89
|
-
// Add callback to the queue and remove old one
|
90
|
-
this.queuedResultMap.set(ref, newResult)
|
91
|
-
clearTimeout(timeout)
|
92
|
-
this.timeoutMap.set(ref, setTimeout(() => {
|
93
|
-
const oldResult = this.resultsMap.get(ref)
|
94
|
-
|
95
|
-
// If results are the same do nothing
|
96
|
-
if (equal(oldResult, newResult)) {
|
97
|
-
return
|
98
|
-
}
|
99
|
-
|
100
|
-
const oldClassNames = this.classNamesMap.get(ref)
|
101
|
-
|
102
|
-
// Remove old styles
|
103
|
-
if (oldResult) {
|
104
|
-
UnistylesRegistry.remove(oldResult)
|
105
|
-
}
|
106
|
-
|
107
|
-
// Remove old classnames from the ref
|
108
|
-
oldClassNames?.forEach(className => ref.classList.remove(className))
|
109
|
-
this.resultsMap.set(ref, newResult)
|
78
|
+
if (typeof __uni__stylesheet === 'function') {
|
79
|
+
// Add dependencies from dynamic styles to stylesheet
|
80
|
+
UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
|
81
|
+
}
|
110
82
|
|
111
|
-
|
112
|
-
const injectedClassNames: Array<string> = newResult?._web?._classNames ?? []
|
113
|
-
const newClassNames = injectedClassNames.concat(hash)
|
114
|
-
const dependencies = extractUnistyleDependencies(newResult)
|
83
|
+
__uni__refs.add(ref)
|
115
84
|
|
116
|
-
|
117
|
-
// Add dependencies from dynamic styles to stylesheet
|
118
|
-
UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
|
119
|
-
}
|
120
|
-
|
121
|
-
__uni__refs.add(ref)
|
122
|
-
this.classNamesMap.set(ref, newClassNames)
|
123
|
-
// Add new classnames to the ref
|
124
|
-
ref.classList.add(...newClassNames)
|
125
|
-
resolve(newClassNames)
|
126
|
-
|
127
|
-
// If it is new hash add it to the map to use for the listener
|
128
|
-
if (!existingHash) {
|
129
|
-
this.hashMap.set(ref, hash)
|
130
|
-
}
|
131
|
-
}, 0))
|
132
|
-
|
133
|
-
// Listen for theme / runtime changes
|
134
|
-
const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(newResult), () => {
|
85
|
+
const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(resultWithVariants), () => {
|
135
86
|
const hash = this.hashMap.get(ref)
|
136
87
|
|
137
88
|
// Dispose listener if there is no hash
|
@@ -151,8 +102,42 @@ class UnistylesShadowRegistryBuilder {
|
|
151
102
|
|
152
103
|
UnistylesRegistry.applyStyles(hash, convertUnistyles(resultWithVariants))
|
153
104
|
})
|
154
|
-
|
155
|
-
|
105
|
+
|
106
|
+
return resultWithVariants as UnistylesValues
|
107
|
+
}))
|
108
|
+
const combinedStyles = deepMergeObjects(...parsedStyles)
|
109
|
+
const oldStyles = this.resultsMap.get(ref)
|
110
|
+
|
111
|
+
if (equal(combinedStyles, oldStyles)) {
|
112
|
+
return
|
113
|
+
}
|
114
|
+
|
115
|
+
const oldClassNames = this.classNamesMap.get(ref)
|
116
|
+
|
117
|
+
// Remove old styles
|
118
|
+
if (oldStyles) {
|
119
|
+
UnistylesRegistry.remove(oldStyles)
|
120
|
+
}
|
121
|
+
|
122
|
+
// Remove old classnames from the ref
|
123
|
+
oldClassNames?.forEach(className => ref.classList.remove(className))
|
124
|
+
this.resultsMap.set(ref, combinedStyles)
|
125
|
+
|
126
|
+
const { hash, existingHash } = UnistylesRegistry.add(combinedStyles)
|
127
|
+
const injectedClassNames = combinedStyles?._web?._classNames ?? []
|
128
|
+
const newClassNames = (Array.isArray(injectedClassNames) ? injectedClassNames : [injectedClassNames]).concat(hash)
|
129
|
+
|
130
|
+
this.classNamesMap.set(ref, newClassNames)
|
131
|
+
// Add new classnames to the ref
|
132
|
+
ref.classList.add(...newClassNames)
|
133
|
+
|
134
|
+
// If it is new hash add it to the map to use for the listener
|
135
|
+
if (!existingHash) {
|
136
|
+
this.hashMap.set(ref, hash)
|
137
|
+
}
|
138
|
+
|
139
|
+
return newClassNames
|
140
|
+
}
|
156
141
|
|
157
142
|
remove = () => {}
|
158
143
|
}
|
package/src/web/utils/common.ts
CHANGED
@@ -7,32 +7,6 @@ export const keyInObject = <T extends Record<string, any>>(obj: T, key: Property
|
|
7
7
|
|
8
8
|
export const isServer = () => typeof window === 'undefined'
|
9
9
|
|
10
|
-
/**
|
11
|
-
* Deeply merges properties of passed object
|
12
|
-
*/
|
13
|
-
export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources: Array<T>) => {
|
14
|
-
const target = {} as T
|
15
|
-
|
16
|
-
sources.forEach(source => {
|
17
|
-
Object.keys(source).forEach(key => {
|
18
|
-
const sourceValue = source[key]
|
19
|
-
const targetValue = target[key]
|
20
|
-
|
21
|
-
if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
|
22
|
-
// @ts-expect-error - can't assign to generic
|
23
|
-
target[key] = deepMergeObjects(targetValue, sourceValue)
|
24
|
-
|
25
|
-
return
|
26
|
-
}
|
27
|
-
|
28
|
-
// @ts-expect-error - can't assign to generic
|
29
|
-
target[key] = sourceValue
|
30
|
-
})
|
31
|
-
})
|
32
|
-
|
33
|
-
return target
|
34
|
-
}
|
35
|
-
|
36
10
|
export const warn = (message: string) => console.warn(`🦄 [react-native-unistyles] ${message}`)
|
37
11
|
|
38
12
|
export const equal = <T>(a: T, b: T) => {
|
@@ -5,7 +5,7 @@ import { isUnistylesMq, parseMq } from '../../mq'
|
|
5
5
|
import { UnistylesState } from '../state'
|
6
6
|
import { keyInObject, reduceObject } from './common'
|
7
7
|
|
8
|
-
export const schemeToTheme = (scheme: ColorScheme)
|
8
|
+
export const schemeToTheme = (scheme: ColorScheme) => {
|
9
9
|
switch (scheme) {
|
10
10
|
case ColorScheme.Dark:
|
11
11
|
return 'dark'
|