@tamagui/web 1.123.17 → 1.124.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/dist/cjs/Tamagui.cjs +1 -6
- package/dist/cjs/Tamagui.js +1 -5
- package/dist/cjs/Tamagui.js.map +1 -1
- package/dist/cjs/Tamagui.native.js +2 -8
- package/dist/cjs/Tamagui.native.js.map +2 -2
- package/dist/cjs/createComponent.cjs +9 -13
- package/dist/cjs/createComponent.js +10 -8
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createComponent.native.js +17 -19
- package/dist/cjs/createComponent.native.js.map +2 -2
- package/dist/cjs/helpers/createShallowSetState.cjs +7 -4
- package/dist/cjs/helpers/createShallowSetState.js +12 -6
- package/dist/cjs/helpers/createShallowSetState.js.map +1 -1
- package/dist/cjs/helpers/createShallowSetState.native.js +10 -4
- package/dist/cjs/helpers/createShallowSetState.native.js.map +2 -2
- package/dist/cjs/hooks/{shouldDeoptDueToParentScheme.cjs → doesRootSchemeMatchSystem.cjs} +5 -5
- package/dist/cjs/hooks/{shouldDeoptDueToParentScheme.js → doesRootSchemeMatchSystem.js} +6 -6
- package/dist/cjs/hooks/doesRootSchemeMatchSystem.js.map +6 -0
- package/dist/cjs/hooks/doesRootSchemeMatchSystem.native.js +30 -0
- package/dist/cjs/hooks/doesRootSchemeMatchSystem.native.js.map +6 -0
- package/dist/cjs/hooks/getThemeProxied.cjs +58 -0
- package/dist/cjs/hooks/getThemeProxied.js +53 -0
- package/dist/cjs/hooks/getThemeProxied.js.map +6 -0
- package/dist/cjs/hooks/getThemeProxied.native.js +76 -0
- package/dist/cjs/hooks/getThemeProxied.native.js.map +6 -0
- package/dist/cjs/hooks/useComponentState.cjs +16 -16
- package/dist/cjs/hooks/useComponentState.js +22 -15
- package/dist/cjs/hooks/useComponentState.js.map +1 -1
- package/dist/cjs/hooks/useComponentState.native.js +15 -15
- package/dist/cjs/hooks/useComponentState.native.js.map +2 -2
- package/dist/cjs/hooks/useProps.cjs +2 -2
- package/dist/cjs/hooks/useProps.js +2 -2
- package/dist/cjs/hooks/useProps.js.map +1 -1
- package/dist/cjs/hooks/useProps.native.js +2 -2
- package/dist/cjs/hooks/useProps.native.js.map +2 -2
- package/dist/cjs/hooks/useTheme.cjs +10 -208
- package/dist/cjs/hooks/useTheme.js +7 -207
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/hooks/useTheme.native.js +8 -252
- package/dist/cjs/hooks/useTheme.native.js.map +2 -2
- package/dist/cjs/hooks/useThemeName.cjs +15 -27
- package/dist/cjs/hooks/useThemeName.js +6 -20
- package/dist/cjs/hooks/useThemeName.js.map +2 -2
- package/dist/cjs/hooks/useThemeName.native.js +16 -22
- package/dist/cjs/hooks/useThemeName.native.js.map +2 -2
- package/dist/cjs/hooks/useThemeState.cjs +187 -0
- package/dist/cjs/hooks/useThemeState.js +159 -0
- package/dist/cjs/hooks/useThemeState.js.map +6 -0
- package/dist/cjs/hooks/useThemeState.native.js +206 -0
- package/dist/cjs/hooks/useThemeState.native.js.map +6 -0
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +3 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.native.js.map +1 -1
- package/dist/cjs/views/Theme.cjs +81 -85
- package/dist/cjs/views/Theme.js +44 -51
- package/dist/cjs/views/Theme.js.map +2 -2
- package/dist/cjs/views/Theme.native.js +58 -58
- package/dist/cjs/views/Theme.native.js.map +2 -2
- package/dist/cjs/views/ThemeDebug.cjs +21 -43
- package/dist/cjs/views/ThemeDebug.js +18 -38
- package/dist/cjs/views/ThemeDebug.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.cjs +1 -1
- package/dist/cjs/views/ThemeProvider.js +1 -1
- package/dist/cjs/views/ThemeProvider.js.map +1 -1
- package/dist/cjs/views/ThemeProvider.native.js +1 -1
- package/dist/cjs/views/ThemeProvider.native.js.map +2 -2
- package/dist/esm/Tamagui.js +0 -5
- package/dist/esm/Tamagui.js.map +1 -1
- package/dist/esm/Tamagui.mjs +0 -5
- package/dist/esm/Tamagui.mjs.map +1 -1
- package/dist/esm/Tamagui.native.js +1 -8
- package/dist/esm/Tamagui.native.js.map +2 -2
- package/dist/esm/createComponent.js +9 -8
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createComponent.mjs +9 -13
- package/dist/esm/createComponent.mjs.map +1 -1
- package/dist/esm/createComponent.native.js +16 -19
- package/dist/esm/createComponent.native.js.map +2 -2
- package/dist/esm/helpers/createShallowSetState.js +13 -7
- package/dist/esm/helpers/createShallowSetState.js.map +1 -1
- package/dist/esm/helpers/createShallowSetState.mjs +8 -5
- package/dist/esm/helpers/createShallowSetState.mjs.map +1 -1
- package/dist/esm/helpers/createShallowSetState.native.js +11 -5
- package/dist/esm/helpers/createShallowSetState.native.js.map +2 -2
- package/dist/esm/hooks/doesRootSchemeMatchSystem.js +7 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.js.map +6 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.mjs +5 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.mjs.map +1 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.native.js +10 -0
- package/dist/esm/hooks/doesRootSchemeMatchSystem.native.js.map +6 -0
- package/dist/esm/hooks/getThemeProxied.js +40 -0
- package/dist/esm/hooks/getThemeProxied.js.map +6 -0
- package/dist/esm/hooks/getThemeProxied.mjs +35 -0
- package/dist/esm/hooks/getThemeProxied.mjs.map +1 -0
- package/dist/esm/hooks/getThemeProxied.native.js +59 -0
- package/dist/esm/hooks/getThemeProxied.native.js.map +6 -0
- package/dist/esm/hooks/useComponentState.js +22 -15
- package/dist/esm/hooks/useComponentState.js.map +1 -1
- package/dist/esm/hooks/useComponentState.mjs +16 -16
- package/dist/esm/hooks/useComponentState.mjs.map +1 -1
- package/dist/esm/hooks/useComponentState.native.js +15 -15
- package/dist/esm/hooks/useComponentState.native.js.map +2 -2
- package/dist/esm/hooks/useProps.js +2 -2
- package/dist/esm/hooks/useProps.js.map +1 -1
- package/dist/esm/hooks/useProps.mjs +2 -2
- package/dist/esm/hooks/useProps.mjs.map +1 -1
- package/dist/esm/hooks/useProps.native.js +2 -2
- package/dist/esm/hooks/useProps.native.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +9 -220
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/hooks/useTheme.mjs +10 -205
- package/dist/esm/hooks/useTheme.mjs.map +1 -1
- package/dist/esm/hooks/useTheme.native.js +11 -257
- package/dist/esm/hooks/useTheme.native.js.map +2 -2
- package/dist/esm/hooks/useThemeName.js +4 -12
- package/dist/esm/hooks/useThemeName.js.map +2 -2
- package/dist/esm/hooks/useThemeName.mjs +11 -12
- package/dist/esm/hooks/useThemeName.mjs.map +1 -1
- package/dist/esm/hooks/useThemeName.native.js +15 -14
- package/dist/esm/hooks/useThemeName.native.js.map +2 -2
- package/dist/esm/hooks/useThemeState.js +151 -0
- package/dist/esm/hooks/useThemeState.js.map +6 -0
- package/dist/esm/hooks/useThemeState.mjs +159 -0
- package/dist/esm/hooks/useThemeState.mjs.map +1 -0
- package/dist/esm/hooks/useThemeState.native.js +182 -0
- package/dist/esm/hooks/useThemeState.native.js.map +6 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js.map +1 -1
- package/dist/esm/views/TamaguiProvider.mjs.map +1 -1
- package/dist/esm/views/TamaguiProvider.native.js.map +1 -1
- package/dist/esm/views/Theme.js +57 -54
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/Theme.mjs +81 -85
- package/dist/esm/views/Theme.mjs.map +1 -1
- package/dist/esm/views/Theme.native.js +61 -61
- package/dist/esm/views/Theme.native.js.map +2 -2
- package/dist/esm/views/ThemeDebug.js +16 -29
- package/dist/esm/views/ThemeDebug.js.map +1 -1
- package/dist/esm/views/ThemeDebug.mjs +16 -27
- package/dist/esm/views/ThemeDebug.mjs.map +1 -1
- package/dist/esm/views/ThemeProvider.js +2 -2
- package/dist/esm/views/ThemeProvider.js.map +1 -1
- package/dist/esm/views/ThemeProvider.mjs +2 -2
- package/dist/esm/views/ThemeProvider.mjs.map +1 -1
- package/dist/esm/views/ThemeProvider.native.js +2 -2
- package/dist/esm/views/ThemeProvider.native.js.map +2 -2
- package/package.json +11 -11
- package/src/Tamagui.ts +0 -6
- package/src/createComponent.tsx +19 -28
- package/src/helpers/createShallowSetState.tsx +17 -8
- package/src/hooks/doesRootSchemeMatchSystem.native.ts +7 -0
- package/src/hooks/doesRootSchemeMatchSystem.ts +4 -0
- package/src/hooks/getThemeProxied.ts +165 -0
- package/src/hooks/useComponentState.ts +26 -21
- package/src/hooks/useProps.tsx +2 -2
- package/src/hooks/useTheme.tsx +22 -633
- package/src/hooks/useThemeName.tsx +6 -18
- package/src/hooks/useThemeState.ts +341 -0
- package/src/index.ts +1 -0
- package/src/types.tsx +2 -2
- package/src/views/TamaguiProvider.tsx +1 -1
- package/src/views/Theme.tsx +129 -132
- package/src/views/ThemeDebug.native.tsx +2 -2
- package/src/views/ThemeDebug.tsx +17 -39
- package/src/views/ThemeProvider.tsx +2 -2
- package/types/Tamagui.d.ts +0 -2
- package/types/Tamagui.d.ts.map +1 -1
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/createShallowSetState.d.ts +1 -1
- package/types/helpers/createShallowSetState.d.ts.map +1 -1
- package/types/hooks/doesRootSchemeMatchSystem.d.ts +2 -0
- package/types/hooks/doesRootSchemeMatchSystem.d.ts.map +1 -0
- package/types/hooks/doesRootSchemeMatchSystem.native.d.ts +2 -0
- package/types/hooks/doesRootSchemeMatchSystem.native.d.ts.map +1 -0
- package/types/hooks/getThemeProxied.d.ts +25 -0
- package/types/hooks/getThemeProxied.d.ts.map +1 -0
- package/types/hooks/useComponentState.d.ts.map +1 -1
- package/types/hooks/useConfiguration.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +9 -36
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/hooks/useThemeName.d.ts +1 -3
- package/types/hooks/useThemeName.d.ts.map +1 -1
- package/types/hooks/useThemeState.d.ts +22 -0
- package/types/hooks/useThemeState.d.ts.map +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +2 -2
- package/types/types.d.ts.map +1 -1
- package/types/views/Theme.d.ts +3 -3
- package/types/views/Theme.d.ts.map +1 -1
- package/types/views/ThemeDebug.d.ts +2 -2
- package/types/views/ThemeDebug.d.ts.map +1 -1
- package/types/views/ThemeDebug.native.d.ts +2 -2
- package/types/views/ThemeDebug.native.d.ts.map +1 -1
- package/dist/cjs/helpers/ThemeManager.cjs +0 -202
- package/dist/cjs/helpers/ThemeManager.js +0 -183
- package/dist/cjs/helpers/ThemeManager.js.map +0 -6
- package/dist/cjs/helpers/ThemeManager.native.js +0 -282
- package/dist/cjs/helpers/ThemeManager.native.js.map +0 -6
- package/dist/cjs/helpers/ThemeManagerContext.cjs +0 -38
- package/dist/cjs/helpers/ThemeManagerContext.js +0 -30
- package/dist/cjs/helpers/ThemeManagerContext.js.map +0 -6
- package/dist/cjs/helpers/ThemeManagerContext.native.js +0 -34
- package/dist/cjs/helpers/ThemeManagerContext.native.js.map +0 -6
- package/dist/cjs/hooks/shouldDeoptDueToParentScheme.js.map +0 -6
- package/dist/cjs/hooks/shouldDeoptDueToParentScheme.native.js +0 -50
- package/dist/cjs/hooks/shouldDeoptDueToParentScheme.native.js.map +0 -6
- package/dist/esm/helpers/ThemeManager.js +0 -169
- package/dist/esm/helpers/ThemeManager.js.map +0 -6
- package/dist/esm/helpers/ThemeManager.mjs +0 -177
- package/dist/esm/helpers/ThemeManager.mjs.map +0 -1
- package/dist/esm/helpers/ThemeManager.native.js +0 -261
- package/dist/esm/helpers/ThemeManager.native.js.map +0 -6
- package/dist/esm/helpers/ThemeManagerContext.js +0 -6
- package/dist/esm/helpers/ThemeManagerContext.js.map +0 -6
- package/dist/esm/helpers/ThemeManagerContext.mjs +0 -4
- package/dist/esm/helpers/ThemeManagerContext.mjs.map +0 -1
- package/dist/esm/helpers/ThemeManagerContext.native.js +0 -6
- package/dist/esm/helpers/ThemeManagerContext.native.js.map +0 -6
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.js +0 -7
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.js.map +0 -6
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.mjs +0 -5
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.mjs.map +0 -1
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.native.js +0 -29
- package/dist/esm/hooks/shouldDeoptDueToParentScheme.native.js.map +0 -6
- package/src/helpers/ThemeManager.tsx +0 -405
- package/src/helpers/ThemeManagerContext.tsx +0 -4
- package/src/hooks/shouldDeoptDueToParentScheme.native.tsx +0 -37
- package/src/hooks/shouldDeoptDueToParentScheme.tsx +0 -6
- package/types/helpers/ThemeManager.d.ts +0 -45
- package/types/helpers/ThemeManager.d.ts.map +0 -1
- package/types/helpers/ThemeManagerContext.d.ts +0 -4
- package/types/helpers/ThemeManagerContext.d.ts.map +0 -1
- package/types/hooks/shouldDeoptDueToParentScheme.d.ts +0 -3
- package/types/hooks/shouldDeoptDueToParentScheme.d.ts.map +0 -1
- package/types/hooks/shouldDeoptDueToParentScheme.native.d.ts +0 -3
- package/types/hooks/shouldDeoptDueToParentScheme.native.d.ts.map +0 -1
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
import { isClient, isWeb } from '@tamagui/constants'
|
|
2
|
-
|
|
3
|
-
import { getThemes } from '../config'
|
|
4
|
-
import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'
|
|
5
|
-
import type { ColorScheme, ThemeParsed, ThemeProps } from '../types'
|
|
6
|
-
|
|
7
|
-
type ThemeListener = (
|
|
8
|
-
name: string | null,
|
|
9
|
-
themeManager: ThemeManager,
|
|
10
|
-
forced: boolean | 'self'
|
|
11
|
-
) => void
|
|
12
|
-
|
|
13
|
-
export type SetActiveThemeProps = {
|
|
14
|
-
className?: string
|
|
15
|
-
parentManager?: ThemeManager | null
|
|
16
|
-
name?: string | null
|
|
17
|
-
theme?: any
|
|
18
|
-
reset?: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type ThemeManagerState = {
|
|
22
|
-
name: string
|
|
23
|
-
parentName?: string
|
|
24
|
-
theme?: ThemeParsed | null
|
|
25
|
-
isComponent?: boolean
|
|
26
|
-
|
|
27
|
-
// if a theme is fixed to light/dark, we need to track
|
|
28
|
-
// so that dynamiccolorIOS knows its fixed a certain way
|
|
29
|
-
isSchemeFixed?: boolean
|
|
30
|
-
|
|
31
|
-
className?: string
|
|
32
|
-
scheme?: ColorScheme
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const emptyState: ThemeManagerState = { name: '' }
|
|
36
|
-
|
|
37
|
-
export function getHasThemeUpdatingProps(props: ThemeProps) {
|
|
38
|
-
return Boolean(props.name || props.componentName || props.inverse || props.reset)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let uid = 0
|
|
42
|
-
|
|
43
|
-
export class ThemeManager {
|
|
44
|
-
id = 0
|
|
45
|
-
themeListeners = new Set<ThemeListener>()
|
|
46
|
-
parentManager: ThemeManager | null = null
|
|
47
|
-
state: ThemeManagerState = emptyState
|
|
48
|
-
|
|
49
|
-
constructor(
|
|
50
|
-
public props: ThemeProps = {},
|
|
51
|
-
parentManager?: ThemeManager | 'root' | null | undefined
|
|
52
|
-
) {
|
|
53
|
-
uid = (uid + 1) % Number.MAX_VALUE
|
|
54
|
-
this.id = uid
|
|
55
|
-
|
|
56
|
-
if (parentManager === 'root') {
|
|
57
|
-
this.updateStateFromProps(props, false)
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!parentManager) {
|
|
62
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions. It could also be from an error somewhere else in your stack causing Tamagui to recieve undefined context, you can try putting some ErrorBoundary components around other areas of your app, or a Suspense boundary.`
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
throw `❌ 000`
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// this is used in updateStateFromProps so must be set
|
|
71
|
-
this.parentManager = parentManager
|
|
72
|
-
|
|
73
|
-
if (this.updateStateFromProps(props, false)) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return parentManager
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
updateStateFromProps(
|
|
81
|
-
props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},
|
|
82
|
-
shouldNotify = true
|
|
83
|
-
) {
|
|
84
|
-
this.props = props
|
|
85
|
-
|
|
86
|
-
if (props.forceTheme) {
|
|
87
|
-
this.state.theme = props.forceTheme
|
|
88
|
-
this.state.name = props.name || ''
|
|
89
|
-
this.updateState(this.state, true)
|
|
90
|
-
return this.state
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const nextState = this.getStateIfChanged(props)
|
|
94
|
-
if (nextState) {
|
|
95
|
-
this.updateState(nextState, shouldNotify)
|
|
96
|
-
return nextState
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
getParents() {
|
|
101
|
-
const parents: ThemeManager[] = []
|
|
102
|
-
let current: ThemeManager | null = this
|
|
103
|
-
while (current) {
|
|
104
|
-
parents.push(current)
|
|
105
|
-
current = current.parentManager
|
|
106
|
-
}
|
|
107
|
-
return parents
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
updateState(nextState: ThemeManagerState, shouldNotify = true) {
|
|
111
|
-
this.state = nextState
|
|
112
|
-
this._allKeys = null
|
|
113
|
-
// if (shouldNotify) {
|
|
114
|
-
// if (process.env.TAMAGUI_TARGET === 'native') {
|
|
115
|
-
// // native is way slower with queueMicrotask
|
|
116
|
-
// this.notify()
|
|
117
|
-
// } else {
|
|
118
|
-
// // web is way faster this way
|
|
119
|
-
// queueMicrotask(() => {
|
|
120
|
-
// this.notify()
|
|
121
|
-
// })
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
getStateIfChanged(
|
|
127
|
-
props = this.props,
|
|
128
|
-
state: ThemeManagerState | null = this.state,
|
|
129
|
-
parentManager = this.parentManager
|
|
130
|
-
) {
|
|
131
|
-
const _ = this.getState(props, parentManager)
|
|
132
|
-
|
|
133
|
-
// is removing
|
|
134
|
-
if (state && state !== emptyState && !_) {
|
|
135
|
-
return parentManager?.state
|
|
136
|
-
}
|
|
137
|
-
if (this.getStateShouldChange(_, state)) {
|
|
138
|
-
return _
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getStateShouldChange(
|
|
143
|
-
nextState: ThemeManagerState | null,
|
|
144
|
-
state: ThemeManagerState | null = this.state
|
|
145
|
-
) {
|
|
146
|
-
if (!nextState?.theme || nextState.theme === state?.theme) {
|
|
147
|
-
return false
|
|
148
|
-
}
|
|
149
|
-
return true
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
getState(props = this.props, parentManager = this.parentManager) {
|
|
153
|
-
const next =
|
|
154
|
-
getState(props, parentManager) ||
|
|
155
|
-
(process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)
|
|
156
|
-
return next
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
_allKeys: Set<string> | null = null
|
|
160
|
-
get allKeys() {
|
|
161
|
-
this._allKeys ||= new Set([
|
|
162
|
-
...(this.parentManager?.allKeys || []),
|
|
163
|
-
...Object.keys(this.state.theme || {}),
|
|
164
|
-
])
|
|
165
|
-
return this._allKeys
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
notify(forced = false) {
|
|
169
|
-
this.themeListeners.forEach((cb) => cb(this.state.name, this, forced))
|
|
170
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
171
|
-
this['_numChangeEventsSent'] ??= 0
|
|
172
|
-
this['_numChangeEventsSent']++
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
_selfListener?: ThemeListener
|
|
177
|
-
|
|
178
|
-
selfUpdate() {
|
|
179
|
-
this._selfListener?.(this.state.name, this, 'self')
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
onChangeTheme(cb: ThemeListener, debugId?: number | true) {
|
|
183
|
-
if (process.env.NODE_ENV !== 'production' && debugId) {
|
|
184
|
-
// @ts-ignore
|
|
185
|
-
this._listeningIds ??= new Set()
|
|
186
|
-
// @ts-ignore
|
|
187
|
-
this._listeningIds.add(debugId)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (debugId === true) {
|
|
191
|
-
this._selfListener = cb
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
this.themeListeners.add(cb)
|
|
195
|
-
return () => {
|
|
196
|
-
this.themeListeners.delete(cb)
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const cache: Record<string, ThemeManagerState | null> = {}
|
|
202
|
-
|
|
203
|
-
function getState(
|
|
204
|
-
props: ThemeProps,
|
|
205
|
-
manager?: ThemeManager | null
|
|
206
|
-
): ThemeManagerState | null {
|
|
207
|
-
if (!getHasThemeUpdatingProps(props)) {
|
|
208
|
-
return null
|
|
209
|
-
}
|
|
210
|
-
const [allManagers] = getManagers(manager)
|
|
211
|
-
const cacheKey = `${props.name || ''}${props.componentName || ''}${props.inverse || ''}${props.reset || ''}${allManagers.map((x) => x?.state.name || '.').join('')}`
|
|
212
|
-
const cached = cache[cacheKey]
|
|
213
|
-
if (!cached) {
|
|
214
|
-
const res = getStateUncached(props, manager)
|
|
215
|
-
cache[cacheKey] = res
|
|
216
|
-
return res
|
|
217
|
-
}
|
|
218
|
-
return cached
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function getStateUncached(
|
|
222
|
-
props: ThemeProps,
|
|
223
|
-
manager?: ThemeManager | null
|
|
224
|
-
): ThemeManagerState | null {
|
|
225
|
-
if (props.name && props.reset) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
process.env.NODE_ENV === 'production'
|
|
228
|
-
? `❌004`
|
|
229
|
-
: 'Cannot reset and set a new name at the same time.'
|
|
230
|
-
)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const themes = getThemes()
|
|
234
|
-
|
|
235
|
-
const [allManagers, componentManagers] = getManagers(manager)
|
|
236
|
-
|
|
237
|
-
const isDirectParentAComponentTheme = !!manager?.state.isComponent
|
|
238
|
-
const startIndex = props.reset && !isDirectParentAComponentTheme ? 1 : 0
|
|
239
|
-
let baseManager = allManagers[startIndex]
|
|
240
|
-
let parentManager = allManagers[startIndex + 1]
|
|
241
|
-
|
|
242
|
-
if (!baseManager && props.reset) {
|
|
243
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
244
|
-
console.warn('Cannot reset, no parent theme exists')
|
|
245
|
-
}
|
|
246
|
-
return null
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const { componentName } = props
|
|
250
|
-
let result: ThemeManagerState | null = null
|
|
251
|
-
|
|
252
|
-
let baseName = baseManager?.state.name || ''
|
|
253
|
-
|
|
254
|
-
if (baseManager?.state.isComponent) {
|
|
255
|
-
// remove component name
|
|
256
|
-
baseName = baseName.replace(/_[A-Z][A-Za-z]+/, '')
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const nextName = props.reset ? baseName : props.name || ''
|
|
260
|
-
|
|
261
|
-
const allComponentThemes = componentManagers.map((x) => x?.state.name || '')
|
|
262
|
-
if (isDirectParentAComponentTheme) {
|
|
263
|
-
allComponentThemes.shift()
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// components look for most specific, fallback upwards
|
|
267
|
-
const base = baseName.split(THEME_NAME_SEPARATOR)
|
|
268
|
-
const max = base.length
|
|
269
|
-
const min =
|
|
270
|
-
props.componentName && !nextName
|
|
271
|
-
? max // component name only don't search upwards
|
|
272
|
-
: 0
|
|
273
|
-
|
|
274
|
-
for (let i = max; i >= min; i--) {
|
|
275
|
-
let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)
|
|
276
|
-
|
|
277
|
-
if (props.inverse) {
|
|
278
|
-
prefix = inverseThemeName(prefix)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
let potentials: string[] = []
|
|
282
|
-
|
|
283
|
-
if (prefix && prefix !== baseName && prefix.includes(nextName)) {
|
|
284
|
-
potentials.push(prefix)
|
|
285
|
-
}
|
|
286
|
-
if (nextName) {
|
|
287
|
-
potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)
|
|
288
|
-
}
|
|
289
|
-
if (i === 1) {
|
|
290
|
-
const lastSegment = potentials.findIndex((x) => !x.includes('_'))
|
|
291
|
-
if (lastSegment > 0) {
|
|
292
|
-
potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (componentName && !props.reset) {
|
|
297
|
-
const baseLen = base.length
|
|
298
|
-
let componentPotentials: string[] = []
|
|
299
|
-
// components only look for component themes
|
|
300
|
-
if (nextName && baseLen > 1) {
|
|
301
|
-
const beforeSeparator = base[0]
|
|
302
|
-
componentPotentials.push(`${beforeSeparator}_${nextName}_${componentName}`)
|
|
303
|
-
}
|
|
304
|
-
componentPotentials.push(`${prefix}_${componentName}`)
|
|
305
|
-
if (nextName) {
|
|
306
|
-
// do this one and one level up
|
|
307
|
-
if (i > baseLen) {
|
|
308
|
-
const prefixLessOne = base.slice(0, i - 1).join(THEME_NAME_SEPARATOR)
|
|
309
|
-
if (prefixLessOne) {
|
|
310
|
-
const lessSpecific = `${prefixLessOne}_${nextName}_${componentName}`
|
|
311
|
-
componentPotentials.unshift(lessSpecific)
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
const moreSpecific = `${prefix}_${nextName}_${componentName}`
|
|
315
|
-
componentPotentials.unshift(moreSpecific)
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
potentials = [...componentPotentials, ...potentials, ...allComponentThemes]
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const found = potentials.find((t) => t in themes)
|
|
322
|
-
|
|
323
|
-
if (
|
|
324
|
-
process.env.NODE_ENV !== 'production' &&
|
|
325
|
-
typeof props.debug === 'string' &&
|
|
326
|
-
isClient
|
|
327
|
-
) {
|
|
328
|
-
console.info(` 🔷 [${manager?.id}] getState`, {
|
|
329
|
-
props,
|
|
330
|
-
found,
|
|
331
|
-
potentials,
|
|
332
|
-
baseManager,
|
|
333
|
-
nextName,
|
|
334
|
-
baseName,
|
|
335
|
-
prefix,
|
|
336
|
-
})
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (found) {
|
|
340
|
-
const names = found.split('_')
|
|
341
|
-
const [firstName, ...restNames] = names
|
|
342
|
-
const lastName = names[names.length - 1]
|
|
343
|
-
const isComponent = lastName[0] === lastName[0].toUpperCase()
|
|
344
|
-
const scheme =
|
|
345
|
-
firstName === 'light' ? 'light' : firstName === 'dark' ? 'dark' : undefined
|
|
346
|
-
const pre = THEME_CLASSNAME_PREFIX
|
|
347
|
-
const className = !isWeb
|
|
348
|
-
? ''
|
|
349
|
-
: `${pre}sub_theme ${pre}${
|
|
350
|
-
!scheme || !restNames.length ? firstName : restNames.join('_')
|
|
351
|
-
}`
|
|
352
|
-
|
|
353
|
-
// because its a new theme the baseManager is now the parent
|
|
354
|
-
const parentState = (baseManager || parentManager)?.state
|
|
355
|
-
const parentName = parentState?.name
|
|
356
|
-
|
|
357
|
-
result = {
|
|
358
|
-
name: found,
|
|
359
|
-
parentName,
|
|
360
|
-
theme: themes[found],
|
|
361
|
-
className,
|
|
362
|
-
isComponent,
|
|
363
|
-
isSchemeFixed: props.name === 'light' || props.name === 'dark',
|
|
364
|
-
scheme,
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
break
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if (process.env.NODE_ENV !== 'production' && props.debug === 'verbose' && isClient) {
|
|
372
|
-
console.groupCollapsed('ThemeManager.getState()')
|
|
373
|
-
console.info({ props, baseName, base, min, max })
|
|
374
|
-
console.warn('result', { result })
|
|
375
|
-
console.trace()
|
|
376
|
-
console.groupEnd()
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return result
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const inverseThemeName = (themeName: string) => {
|
|
383
|
-
return themeName.startsWith('light')
|
|
384
|
-
? themeName.replace(/^light/, 'dark')
|
|
385
|
-
: themeName.replace(/^dark/, 'light')
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
type MaybeThemeManager = ThemeManager | undefined
|
|
389
|
-
|
|
390
|
-
// components never inherit from components
|
|
391
|
-
// example <Switch><Switch.Thumb /></Switch>
|
|
392
|
-
// the Switch theme shouldn't be considered parent of Thumb
|
|
393
|
-
export function getManagers(themeManager?: ThemeManager | null) {
|
|
394
|
-
const comp: MaybeThemeManager[] = []
|
|
395
|
-
const all: MaybeThemeManager[] = []
|
|
396
|
-
let cur = themeManager
|
|
397
|
-
while (cur) {
|
|
398
|
-
all.push(cur)
|
|
399
|
-
if (cur.state.isComponent) {
|
|
400
|
-
comp.push(cur)
|
|
401
|
-
}
|
|
402
|
-
cur = cur.parentManager
|
|
403
|
-
}
|
|
404
|
-
return [all, comp] as const
|
|
405
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Appearance } from 'react-native'
|
|
2
|
-
import type { ThemeManager } from '../helpers/ThemeManager'
|
|
3
|
-
|
|
4
|
-
// on iOS for fast scheme change, we assume the root theme name is matching the system
|
|
5
|
-
// but if any intermediate theme is "fixed" to light or dark, we need to opt out
|
|
6
|
-
// optimizing no-rerenders, because it could change by the end-user at any time in the tree
|
|
7
|
-
// but also theres no point in doing a dynamic color in the first place since scheme is fixed one way
|
|
8
|
-
export function shouldDeoptDueToParentScheme(manager?: ThemeManager) {
|
|
9
|
-
// reverse so we get it from root => child (easier to check)
|
|
10
|
-
const parents = (manager?.getParents() || []).reverse()
|
|
11
|
-
const rootScheme = parents[0]?.state.scheme
|
|
12
|
-
|
|
13
|
-
// de-opt because the root isn't light/dark
|
|
14
|
-
if (!rootScheme) {
|
|
15
|
-
return true
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// de-opt if root scheme doesn't match system theme
|
|
19
|
-
// TODO we could be smarter about this and still support fast scheme change
|
|
20
|
-
// but we'd have to track the inverses which is a bit tricky
|
|
21
|
-
if (Appearance.getColorScheme() !== rootScheme) {
|
|
22
|
-
return true
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// dont count the root theme level as fixed because it will be matching system theme
|
|
26
|
-
let lastParentScheme = rootScheme
|
|
27
|
-
|
|
28
|
-
// we want to return true if a scheme changes anywhere in the tree
|
|
29
|
-
for (const parent of parents) {
|
|
30
|
-
if (parent.state.scheme !== lastParentScheme) {
|
|
31
|
-
return true
|
|
32
|
-
}
|
|
33
|
-
lastParentScheme = parent.state.scheme
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return false
|
|
37
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ColorScheme, ThemeParsed, ThemeProps } from '../types';
|
|
2
|
-
type ThemeListener = (name: string | null, themeManager: ThemeManager, forced: boolean | 'self') => void;
|
|
3
|
-
export type SetActiveThemeProps = {
|
|
4
|
-
className?: string;
|
|
5
|
-
parentManager?: ThemeManager | null;
|
|
6
|
-
name?: string | null;
|
|
7
|
-
theme?: any;
|
|
8
|
-
reset?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type ThemeManagerState = {
|
|
11
|
-
name: string;
|
|
12
|
-
parentName?: string;
|
|
13
|
-
theme?: ThemeParsed | null;
|
|
14
|
-
isComponent?: boolean;
|
|
15
|
-
isSchemeFixed?: boolean;
|
|
16
|
-
className?: string;
|
|
17
|
-
scheme?: ColorScheme;
|
|
18
|
-
};
|
|
19
|
-
export declare function getHasThemeUpdatingProps(props: ThemeProps): boolean;
|
|
20
|
-
export declare class ThemeManager {
|
|
21
|
-
props: ThemeProps;
|
|
22
|
-
id: number;
|
|
23
|
-
themeListeners: Set<ThemeListener>;
|
|
24
|
-
parentManager: ThemeManager | null;
|
|
25
|
-
state: ThemeManagerState;
|
|
26
|
-
constructor(props?: ThemeProps, parentManager?: ThemeManager | 'root' | null | undefined);
|
|
27
|
-
updateStateFromProps(props?: ThemeProps & {
|
|
28
|
-
forceTheme?: ThemeParsed;
|
|
29
|
-
}, shouldNotify?: boolean): ThemeManagerState | undefined;
|
|
30
|
-
getParents(): ThemeManager[];
|
|
31
|
-
updateState(nextState: ThemeManagerState, shouldNotify?: boolean): void;
|
|
32
|
-
getStateIfChanged(props?: ThemeProps, state?: ThemeManagerState | null, parentManager?: ThemeManager | null): ThemeManagerState | null | undefined;
|
|
33
|
-
getStateShouldChange(nextState: ThemeManagerState | null, state?: ThemeManagerState | null): boolean;
|
|
34
|
-
getState(props?: ThemeProps, parentManager?: ThemeManager | null): ThemeManagerState | null;
|
|
35
|
-
_allKeys: Set<string> | null;
|
|
36
|
-
get allKeys(): Set<string>;
|
|
37
|
-
notify(forced?: boolean): void;
|
|
38
|
-
_selfListener?: ThemeListener;
|
|
39
|
-
selfUpdate(): void;
|
|
40
|
-
onChangeTheme(cb: ThemeListener, debugId?: number | true): () => void;
|
|
41
|
-
}
|
|
42
|
-
type MaybeThemeManager = ThemeManager | undefined;
|
|
43
|
-
export declare function getManagers(themeManager?: ThemeManager | null): readonly [MaybeThemeManager[], MaybeThemeManager[]];
|
|
44
|
-
export {};
|
|
45
|
-
//# sourceMappingURL=ThemeManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../../src/helpers/ThemeManager.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAEpE,KAAK,aAAa,GAAG,CACnB,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,OAAO,GAAG,MAAM,KACrB,IAAI,CAAA;AAET,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IACnC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAA;IAIrB,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB,CAAA;AAID,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,UAAU,WAEzD;AAID,qBAAa,YAAY;IAOd,KAAK,EAAE,UAAU;IAN1B,EAAE,SAAI;IACN,cAAc,qBAA2B;IACzC,aAAa,EAAE,YAAY,GAAG,IAAI,CAAO;IACzC,KAAK,EAAE,iBAAiB,CAAa;gBAG5B,KAAK,GAAE,UAAe,EAC7B,aAAa,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;IA6B1D,oBAAoB,CAClB,KAAK,GAAE,UAAU,GAAG;QAAE,UAAU,CAAC,EAAE,WAAW,CAAA;KAAqB,EACnE,YAAY,UAAO;IAkBrB,UAAU;IAUV,WAAW,CAAC,SAAS,EAAE,iBAAiB,EAAE,YAAY,UAAO;IAgB7D,iBAAiB,CACf,KAAK,aAAa,EAClB,KAAK,GAAE,iBAAiB,GAAG,IAAiB,EAC5C,aAAa,sBAAqB;IAapC,oBAAoB,CAClB,SAAS,EAAE,iBAAiB,GAAG,IAAI,EACnC,KAAK,GAAE,iBAAiB,GAAG,IAAiB;IAQ9C,QAAQ,CAAC,KAAK,aAAa,EAAE,aAAa,sBAAqB;IAO/D,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAO;IACnC,IAAI,OAAO,gBAMV;IAED,MAAM,CAAC,MAAM,UAAQ;IAQrB,aAAa,CAAC,EAAE,aAAa,CAAA;IAE7B,UAAU;IAIV,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;CAiBzD;AA6LD,KAAK,iBAAiB,GAAG,YAAY,GAAG,SAAS,CAAA;AAKjD,wBAAgB,WAAW,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,uDAY7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeManagerContext.d.ts","sourceRoot":"","sources":["../../src/helpers/ThemeManagerContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD,eAAO,MAAM,mBAAmB,oCAAiD,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shouldDeoptDueToParentScheme.d.ts","sourceRoot":"","sources":["../../src/hooks/shouldDeoptDueToParentScheme.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAG3D,wBAAgB,4BAA4B,CAAC,OAAO,CAAC,EAAE,YAAY,WAElE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shouldDeoptDueToParentScheme.native.d.ts","sourceRoot":"","sources":["../../src/hooks/shouldDeoptDueToParentScheme.native.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAM3D,wBAAgB,4BAA4B,CAAC,OAAO,CAAC,EAAE,YAAY,WA6BlE"}
|