react-native-unistyles 3.8.1 → 3.9.0
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 +3 -0
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +11 -12
- package/cxx/core/Unistyle.h +2 -0
- package/cxx/core/UnistyleWrapper.h +2 -1
- package/cxx/core/UnistylesRegistry.cpp +13 -1
- package/cxx/core/UnistylesRegistry.h +2 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +27 -3
- package/cxx/parser/Parser.cpp +9 -0
- package/cxx/shadowTree/NativeProps.h +47 -14
- package/lib/commonjs/components/ScopedTheme.js +22 -8
- package/lib/commonjs/components/ScopedTheme.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +4 -3
- package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +3 -7
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +7 -10
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/styleSource.js +3 -7
- package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -1
- package/lib/commonjs/web/registry.js +3 -3
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/module/components/ScopedTheme.js +21 -7
- package/lib/module/components/ScopedTheme.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/listener.native.js +4 -3
- package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +2 -2
- package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
- package/lib/module/core/withUnistyles/withUnistyles.native.js +3 -7
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +7 -10
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/styleSource.js +3 -7
- package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -1
- package/lib/module/web/registry.js +3 -3
- package/lib/module/web/registry.js.map +1 -1
- package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +1 -1
- package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -1
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.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/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -1
- package/metro/index.d.ts +1 -1
- package/metro/index.js +8 -4
- 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 +7 -6
- package/plugin/index.d.ts +20 -0
- package/plugin/index.js +33 -2
- package/repack-plugin/index.d.ts +41 -0
- package/repack-plugin/index.js +294 -9
- package/src/components/ScopedTheme.tsx +23 -7
- package/src/core/useProxifiedUnistyles/listener.native.ts +8 -3
- package/src/core/useProxifiedUnistyles/types.ts +1 -1
- package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +2 -2
- package/src/core/withUnistyles/withUnistyles.native.tsx +3 -7
- package/src/index.ts +1 -0
- package/src/specs/ShadowRegistry/index.ts +8 -11
- package/src/specs/ShadowRegistry/styleSource.ts +3 -7
- package/src/web/registry.ts +3 -3
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useContext } from 'react'
|
|
2
2
|
|
|
3
3
|
import type { UnistylesThemes } from '../global'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useUnistyles } from '../core'
|
|
6
6
|
import { AdaptiveTheme } from './AdaptiveTheme'
|
|
7
7
|
import { NamedTheme } from './NamedTheme'
|
|
8
|
+
import { ScopedThemeContext } from './ScopedThemeContext'
|
|
8
9
|
|
|
9
10
|
type ThemeProps =
|
|
10
11
|
| {
|
|
@@ -23,15 +24,30 @@ type ThemeProps =
|
|
|
23
24
|
reset: boolean
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
interface InvertedAdaptiveThemeProps extends React.PropsWithChildren {
|
|
28
|
+
previousScopedTheme?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const InvertedAdaptiveTheme: React.FunctionComponent<InvertedAdaptiveThemeProps> = ({
|
|
32
|
+
children,
|
|
33
|
+
previousScopedTheme,
|
|
34
|
+
}) => {
|
|
35
|
+
const { rt } = useUnistyles()
|
|
36
|
+
|
|
37
|
+
if (!rt.hasAdaptiveThemes) {
|
|
38
|
+
return children
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return <AdaptiveTheme previousScopedTheme={previousScopedTheme}>{children}</AdaptiveTheme>
|
|
42
|
+
}
|
|
43
|
+
|
|
26
44
|
export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeProps>> = ({
|
|
27
45
|
name,
|
|
28
46
|
children,
|
|
29
47
|
invertedAdaptive,
|
|
30
48
|
reset,
|
|
31
49
|
}) => {
|
|
32
|
-
const
|
|
33
|
-
const isAdaptiveTheme = invertedAdaptive && hasAdaptiveThemes
|
|
34
|
-
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
|
50
|
+
const previousScopedTheme = useContext(ScopedThemeContext)?.name
|
|
35
51
|
|
|
36
52
|
switch (true) {
|
|
37
53
|
case name !== undefined:
|
|
@@ -40,8 +56,8 @@ export const ScopedTheme: React.FunctionComponent<React.PropsWithChildren<ThemeP
|
|
|
40
56
|
{children}
|
|
41
57
|
</NamedTheme>
|
|
42
58
|
)
|
|
43
|
-
case
|
|
44
|
-
return <
|
|
59
|
+
case invertedAdaptive:
|
|
60
|
+
return <InvertedAdaptiveTheme previousScopedTheme={previousScopedTheme}>{children}</InvertedAdaptiveTheme>
|
|
45
61
|
case reset:
|
|
46
62
|
return (
|
|
47
63
|
<NamedTheme name={undefined} previousScopedTheme={previousScopedTheme}>
|
|
@@ -2,6 +2,9 @@ import type { ListenerProps } from './types'
|
|
|
2
2
|
|
|
3
3
|
import { StyleSheet, UnistyleDependency } from '../../specs'
|
|
4
4
|
|
|
5
|
+
const isThemeDependency = (dependency: UnistyleDependency) =>
|
|
6
|
+
dependency === UnistyleDependency.Theme || dependency === UnistyleDependency.ThemeName
|
|
7
|
+
|
|
5
8
|
export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
|
|
6
9
|
const listensToTheme = dependencies.includes(UnistyleDependency.Theme)
|
|
7
10
|
const dispose = StyleSheet.addChangeListener((changedDependencies) => {
|
|
@@ -9,10 +12,12 @@ export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerP
|
|
|
9
12
|
updateTheme()
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
const changedListenedDependencies = changedDependencies.filter((dependency: UnistyleDependency) =>
|
|
16
|
+
dependencies.includes(dependency),
|
|
17
|
+
)
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
if (changedListenedDependencies.length > 0) {
|
|
20
|
+
updateRuntime(changedListenedDependencies.every(isThemeDependency))
|
|
16
21
|
}
|
|
17
22
|
})
|
|
18
23
|
|
|
@@ -52,8 +52,8 @@ export const useProxifiedUnistyles = () => {
|
|
|
52
52
|
|
|
53
53
|
setTheme(UnistylesRuntime.getTheme(scopedTheme))
|
|
54
54
|
},
|
|
55
|
-
updateRuntime: (
|
|
56
|
-
if (
|
|
55
|
+
updateRuntime: (isThemeChangeOnly: boolean) => {
|
|
56
|
+
if (isThemeChangeOnly && scopedTheme) {
|
|
57
57
|
return
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -144,11 +144,9 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
|
144
144
|
const [, stylesChanged] = useReducer(() => ({}), {})
|
|
145
145
|
|
|
146
146
|
const getScopedSecrets = () => {
|
|
147
|
-
const previousScopedTheme =
|
|
147
|
+
const previousScopedTheme = UnistylesShadowRegistry.getScopedTheme()
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
UnistylesShadowRegistry.setScopedTheme(scope.name)
|
|
151
|
-
}
|
|
149
|
+
UnistylesShadowRegistry.setScopedTheme(scope?.name)
|
|
152
150
|
|
|
153
151
|
try {
|
|
154
152
|
const styleSecrets = getSecrets(narrowedProps.style)
|
|
@@ -156,9 +154,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
|
|
|
156
154
|
|
|
157
155
|
return { styleSecrets, contentContainerStyleSecrets }
|
|
158
156
|
} finally {
|
|
159
|
-
|
|
160
|
-
UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
|
|
161
|
-
}
|
|
157
|
+
UnistylesShadowRegistry.setScopedTheme(previousScopedTheme)
|
|
162
158
|
}
|
|
163
159
|
}
|
|
164
160
|
|
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'
|
|
@@ -176,23 +176,20 @@ HybridShadowRegistry.add = (handle, styles, scope) => {
|
|
|
176
176
|
)
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
const previousScopedTheme = scope ? HybridShadowRegistry.getScopedTheme() : undefined
|
|
179
|
+
const previousScopedTheme = HybridShadowRegistry.getScopedTheme()
|
|
181
180
|
|
|
182
|
-
|
|
183
|
-
HybridShadowRegistry.setScopedTheme(scope.name)
|
|
184
|
-
}
|
|
181
|
+
HybridShadowRegistry.setScopedTheme(scope?.name)
|
|
185
182
|
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
try {
|
|
184
|
+
HybridShadowRegistry.link(node, filteredStyles)
|
|
185
|
+
owners.link(host)
|
|
186
|
+
} finally {
|
|
187
|
+
HybridShadowRegistry.setScopedTheme(previousScopedTheme)
|
|
188
|
+
}
|
|
188
189
|
|
|
189
190
|
if (!handle.__internalInstanceHandle) {
|
|
190
191
|
linkedHosts.set(handle, host)
|
|
191
192
|
}
|
|
192
|
-
|
|
193
|
-
if (scope) {
|
|
194
|
-
HybridShadowRegistry.setScopedTheme(previousScopedTheme)
|
|
195
|
-
}
|
|
196
193
|
}
|
|
197
194
|
}
|
|
198
195
|
|
|
@@ -50,18 +50,14 @@ export const createUnistylesStyleSource = (scopedTheme: ScopedThemeAccess) => {
|
|
|
50
50
|
|
|
51
51
|
hasUnistyles = true
|
|
52
52
|
|
|
53
|
-
const previousScopedTheme =
|
|
53
|
+
const previousScopedTheme = scopedTheme.get()
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
scopedTheme.set(scope.name)
|
|
57
|
-
}
|
|
55
|
+
scopedTheme.set(scope?.name)
|
|
58
56
|
|
|
59
57
|
try {
|
|
60
58
|
Object.assign(fresh, style[key]?.uni__getStyles?.())
|
|
61
59
|
} finally {
|
|
62
|
-
|
|
63
|
-
scopedTheme.set(previousScopedTheme)
|
|
64
|
-
}
|
|
60
|
+
scopedTheme.set(previousScopedTheme)
|
|
65
61
|
}
|
|
66
62
|
}
|
|
67
63
|
}
|
package/src/web/registry.ts
CHANGED
|
@@ -167,13 +167,13 @@ export class UnistylesRegistry {
|
|
|
167
167
|
stylesCounter.delete(ref)
|
|
168
168
|
|
|
169
169
|
if (stylesCounter.size === 0) {
|
|
170
|
-
// Safe to drop now: connect creates a new Set
|
|
170
|
+
// Safe to drop now: connect creates a new Set, which the cleanup below checks
|
|
171
171
|
this.stylesCounter.delete(hash)
|
|
172
172
|
|
|
173
173
|
// Move this to the end of the event loop so the element is removed from the DOM
|
|
174
174
|
return Promise.resolve().then(() => {
|
|
175
|
-
//
|
|
176
|
-
if (document.querySelector(`.${hash}`)) {
|
|
175
|
+
// Keep the style while an element uses it, even one connected outside the DOM, eg. in a portal attached later
|
|
176
|
+
if (this.stylesCounter.has(hash) || document.querySelector(`.${hash}`)) {
|
|
177
177
|
return false
|
|
178
178
|
}
|
|
179
179
|
|