react-native-unistyles 3.8.0 → 3.8.2
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/android/src/main/java/com/unistyles/NativePlatform+insets.kt +3 -10
- package/cxx/core/UnistylesRegistry.cpp +1 -1
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -2
- package/cxx/shadowTree/ShadowTreeManager.cpp +36 -0
- package/lib/commonjs/hooks/useMedia.js +6 -0
- package/lib/commonjs/hooks/useMedia.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +13 -4
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -1
- package/lib/commonjs/web/create.js +35 -6
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/css/sheet.js +11 -1
- package/lib/commonjs/web/css/sheet.js.map +1 -1
- package/lib/commonjs/web/css/state.js +6 -0
- package/lib/commonjs/web/css/state.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +3 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/types.js +3 -1
- package/lib/commonjs/web/types.js.map +1 -1
- package/lib/module/hooks/useMedia.js +6 -0
- package/lib/module/hooks/useMedia.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/reanimated/variant/useUpdateVariantColor.js +15 -5
- package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -1
- package/lib/module/web/create.js +35 -6
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/css/sheet.js +11 -1
- package/lib/module/web/css/sheet.js.map +1 -1
- package/lib/module/web/css/state.js +7 -1
- package/lib/module/web/css/state.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +3 -1
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/types.js +2 -0
- package/lib/module/web/types.js.map +1 -1
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/css/sheet.d.ts.map +1 -1
- package/lib/typescript/src/web/css/state.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/types.d.ts +1 -0
- package/lib/typescript/src/web/types.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
- package/nitrogen/generated/android/c++/JDimensions.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +1 -1
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JInsets.hpp +1 -1
- package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
- package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
- package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/unistylesOnLoad.kt +1 -1
- package/nitrogen/generated/android/unistyles+autolinking.cmake +1 -1
- package/nitrogen/generated/android/unistyles+autolinking.gradle +1 -1
- package/nitrogen/generated/android/unistylesOnLoad.cpp +1 -1
- package/nitrogen/generated/android/unistylesOnLoad.hpp +1 -1
- package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.cpp +1 -1
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/ColorScheme.swift +1 -1
- package/nitrogen/generated/ios/swift/Dimensions.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +1 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +3 -3
- package/nitrogen/generated/ios/swift/Insets.swift +1 -1
- package/nitrogen/generated/ios/swift/Orientation.swift +1 -1
- package/nitrogen/generated/ios/swift/UnistyleDependency.swift +1 -1
- package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +1 -1
- package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
- package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/Insets.hpp +1 -1
- package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -1
- package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -1
- package/package.json +3 -3
- package/src/hooks/useMedia.ts +6 -0
- package/src/index.ts +1 -0
- package/src/reanimated/variant/useUpdateVariantColor.ts +15 -5
- package/src/web/create.ts +45 -8
- package/src/web/css/sheet.ts +15 -1
- package/src/web/css/state.ts +9 -2
- package/src/web/shadowRegistry.ts +6 -1
- package/src/web/types.ts +3 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
///
|
|
2
2
|
/// Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
-
/// https://github.com/
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
///
|
|
2
2
|
/// HybridNativePlatformSpec_cxx.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
-
/// https://github.com/
|
|
4
|
+
/// https://github.com/margelo/nitro
|
|
5
5
|
/// Copyright © Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ open class HybridNativePlatformSpec_cxx {
|
|
|
27
27
|
/**
|
|
28
28
|
* Holds an instance of the `HybridNativePlatformSpec` Swift protocol.
|
|
29
29
|
*/
|
|
30
|
-
private
|
|
30
|
+
private let __implementation: any HybridNativePlatformSpec
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Holds a weak pointer to the C++ class that wraps the Swift class.
|
|
@@ -75,7 +75,7 @@ open class HybridNativePlatformSpec_cxx {
|
|
|
75
75
|
*/
|
|
76
76
|
public func getCxxPart() -> bridge.std__shared_ptr_HybridNativePlatformSpec_ {
|
|
77
77
|
let cachedCxxPart = self.__cxxPart.lock()
|
|
78
|
-
if
|
|
78
|
+
if cachedCxxPart.use_count() > 0 {
|
|
79
79
|
return cachedCxxPart
|
|
80
80
|
} else {
|
|
81
81
|
let newCxxPart = bridge.create_std__shared_ptr_HybridNativePlatformSpec_(self.toUnsafe())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-unistyles",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Level up your React Native StyleSheet",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "NODE_ENV=babel-test jest ./plugin ./metro ./codemods ./src/__tests__",
|
|
@@ -219,13 +219,13 @@
|
|
|
219
219
|
"jest": "30.5.2",
|
|
220
220
|
"jscodeshift": "17.4.0",
|
|
221
221
|
"jsdom": "26.1.0",
|
|
222
|
-
"nitrogen": "0.37.
|
|
222
|
+
"nitrogen": "0.37.2",
|
|
223
223
|
"oxfmt": "0.74.0",
|
|
224
224
|
"oxlint": "1.89.0",
|
|
225
225
|
"react": "19.3.0",
|
|
226
226
|
"react-native": "0.88.0",
|
|
227
227
|
"react-native-builder-bob": "0.43.2",
|
|
228
|
-
"react-native-nitro-modules": "0.37.
|
|
228
|
+
"react-native-nitro-modules": "0.37.2",
|
|
229
229
|
"react-native-reanimated": "4.7.1",
|
|
230
230
|
"react-native-web": "0.21.4",
|
|
231
231
|
"typescript": "6.0.3"
|
package/src/hooks/useMedia.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import { isUnistylesMq, isValidMq, parseMq } from '../utils'
|
|
4
|
+
import { isServer } from '../web/utils'
|
|
4
5
|
|
|
5
6
|
export const useMedia = (config: { mq: symbol }) => {
|
|
6
7
|
const disposeRef = useRef(() => {})
|
|
@@ -32,6 +33,11 @@ export const useMedia = (config: { mq: symbol }) => {
|
|
|
32
33
|
.filter(Boolean)
|
|
33
34
|
.join(' and ')
|
|
34
35
|
|
|
36
|
+
// No viewport on the server, the content is hidden until the browser renders it
|
|
37
|
+
if (isServer()) {
|
|
38
|
+
return false
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
const media = window.matchMedia(mediaQuery)
|
|
36
42
|
const handler = (event: MediaQueryListEvent) => setIsVisible(event.matches)
|
|
37
43
|
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { StyleSheet, UnistylesRuntime } from './specs'
|
|
|
10
10
|
export { UnistyleDependency } from './specs'
|
|
11
11
|
export type { UnistylesMiniRuntime } from './specs'
|
|
12
12
|
export { ColorScheme, Orientation, StatusBarStyle } from './specs/types'
|
|
13
|
+
export type { AppTheme, AppThemeName, AppBreakpoint } from './specs/types'
|
|
13
14
|
export { mq } from './mq'
|
|
14
15
|
export type { UnistylesThemes, UnistylesBreakpoints } from './global'
|
|
15
16
|
export { withUnistyles, useUnistyles, createUnistylesElement } from './core'
|
|
@@ -6,14 +6,23 @@ import type { UseUpdateVariantColorConfig } from './types'
|
|
|
6
6
|
|
|
7
7
|
import { UnistyleDependency } from '../../specs'
|
|
8
8
|
import { services } from '../../web/services'
|
|
9
|
-
import { getClosestBreakpointValue } from '../../web/utils'
|
|
9
|
+
import { getClosestBreakpointValue, isServer } from '../../web/utils'
|
|
10
|
+
|
|
11
|
+
// The first render paints this color on the server and in the browser, then the layout effect sets the real one.
|
|
12
|
+
// Matching the server lets the effect replace its HTML: Reanimated skips writing a value that didn't change
|
|
13
|
+
const INITIAL_COLOR = 'rgb(0, 0, 0)'
|
|
10
14
|
|
|
11
15
|
export const useUpdateVariantColor = <T extends Record<string, any>>({
|
|
12
16
|
animateCallback,
|
|
13
17
|
colorKey,
|
|
14
18
|
style,
|
|
15
19
|
}: UseUpdateVariantColorConfig<T>) => {
|
|
20
|
+
// Resolves CSS variables to colors, there is no document on the server
|
|
16
21
|
const [dummyDiv] = useState(() => {
|
|
22
|
+
if (isServer()) {
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
const div = document.createElement('div')
|
|
18
27
|
|
|
19
28
|
div.style.display = 'none'
|
|
@@ -35,7 +44,8 @@ export const useUpdateVariantColor = <T extends Record<string, any>>({
|
|
|
35
44
|
? currentColor
|
|
36
45
|
: (getClosestBreakpointValue<string>(services.runtime, currentColor) ?? 'rgb(0, 0, 0)')
|
|
37
46
|
|
|
38
|
-
|
|
47
|
+
// Called from effects only, which don't run on the server
|
|
48
|
+
if (currentColorVar.startsWith('var(--') && dummyDiv) {
|
|
39
49
|
dummyDiv.style.color = currentColorVar
|
|
40
50
|
|
|
41
51
|
return getComputedStyle(dummyDiv).color
|
|
@@ -43,8 +53,8 @@ export const useUpdateVariantColor = <T extends Record<string, any>>({
|
|
|
43
53
|
|
|
44
54
|
return currentColorVar
|
|
45
55
|
}, [style, colorKey])
|
|
46
|
-
const fromValue = useSharedValue<string>(
|
|
47
|
-
const toValue = useSharedValue<string>(
|
|
56
|
+
const fromValue = useSharedValue<string>(INITIAL_COLOR)
|
|
57
|
+
const toValue = useSharedValue<string>(INITIAL_COLOR)
|
|
48
58
|
|
|
49
59
|
useEffect(() => {
|
|
50
60
|
const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => {
|
|
@@ -72,7 +82,7 @@ export const useUpdateVariantColor = <T extends Record<string, any>>({
|
|
|
72
82
|
return () => dispose()
|
|
73
83
|
}, [style, colorKey])
|
|
74
84
|
|
|
75
|
-
useEffect(() => () => dummyDiv
|
|
85
|
+
useEffect(() => () => dummyDiv?.remove(), [])
|
|
76
86
|
|
|
77
87
|
return {
|
|
78
88
|
fromValue,
|
package/src/web/create.ts
CHANGED
|
@@ -5,14 +5,7 @@ import { assignSecrets, isServer, removeInlineStyles } from './utils'
|
|
|
5
5
|
|
|
6
6
|
type Variants = Record<string, string | boolean | undefined>
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
// For SSR
|
|
10
|
-
if (!unistyles.services.state.isInitialized && !isServer()) {
|
|
11
|
-
const config = window?.__UNISTYLES_STATE__?.config
|
|
12
|
-
|
|
13
|
-
config && unistyles.services.state.init(config)
|
|
14
|
-
}
|
|
15
|
-
|
|
8
|
+
const createStyleSheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
|
16
9
|
const computedStylesheet = unistyles.services.registry.getComputedStylesheet(stylesheet)
|
|
17
10
|
const addSecrets = (
|
|
18
11
|
value: any,
|
|
@@ -55,3 +48,47 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
|
|
55
48
|
|
|
56
49
|
return createStyleSheetStyles()
|
|
57
50
|
}
|
|
51
|
+
|
|
52
|
+
// On the server, a route can be loaded before StyleSheet.configure runs: Expo Router reads the matched route's
|
|
53
|
+
// metadata before rendering the document that imports the config. Such a StyleSheet is created on first use instead
|
|
54
|
+
const createOnFirstUse = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
|
55
|
+
const styles = {} as ReturnType<typeof createStyleSheet>
|
|
56
|
+
let isCreated = false
|
|
57
|
+
// The styles fill the proxy's own target, so it behaves like the object create returns (writes, freeze...)
|
|
58
|
+
const getStyles = () => {
|
|
59
|
+
if (!isCreated) {
|
|
60
|
+
Object.assign(styles, createStyleSheet(stylesheet))
|
|
61
|
+
isCreated = true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return styles
|
|
65
|
+
}
|
|
66
|
+
// Reflect has a method for every proxy trap
|
|
67
|
+
const traps = Object.getOwnPropertyNames(Reflect) as Array<keyof ProxyHandler<object>>
|
|
68
|
+
const handler = Object.fromEntries(
|
|
69
|
+
traps.map((trap) => [
|
|
70
|
+
trap,
|
|
71
|
+
(_: object, ...args: Array<any>) => (Reflect[trap] as Function)(getStyles(), ...args),
|
|
72
|
+
]),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return new Proxy(styles, handler)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
|
|
79
|
+
if (unistyles.services.state.isInitialized) {
|
|
80
|
+
return createStyleSheet(stylesheet)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// A plain object doesn't read the config, so it can be created right away
|
|
84
|
+
if (isServer()) {
|
|
85
|
+
return typeof stylesheet === 'function' ? createOnFirstUse(stylesheet) : createStyleSheet(stylesheet)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// For SSR
|
|
89
|
+
const config = window?.__UNISTYLES_STATE__?.config
|
|
90
|
+
|
|
91
|
+
config && unistyles.services.state.init(config)
|
|
92
|
+
|
|
93
|
+
return createStyleSheet(stylesheet)
|
|
94
|
+
}
|