@tamagui/web 1.74.15 → 1.74.16
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/helpers/ThemeManager.js +42 -62
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.native.js +42 -62
- package/dist/cjs/helpers/ThemeManager.native.js.map +2 -2
- package/dist/cjs/helpers/scheme.js +1 -0
- package/dist/cjs/helpers/scheme.js.map +6 -0
- package/dist/cjs/helpers/scheme.native.js +2 -0
- package/dist/cjs/helpers/scheme.native.js.map +6 -0
- package/dist/cjs/hooks/useTheme.js +1 -1
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/hooks/useTheme.native.js +24 -16
- package/dist/cjs/hooks/useTheme.native.js.map +1 -1
- package/dist/cjs/setupReactNative.js.map +1 -1
- package/dist/cjs/setupReactNative.native.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.js +41 -59
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.native.js +41 -59
- package/dist/esm/helpers/ThemeManager.native.js.map +2 -2
- package/dist/esm/helpers/scheme.js +1 -0
- package/dist/esm/helpers/scheme.js.map +6 -0
- package/dist/esm/helpers/scheme.native.js +1 -0
- package/dist/esm/helpers/scheme.native.js.map +6 -0
- package/dist/esm/hooks/useTheme.js +1 -1
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/hooks/useTheme.native.js +24 -16
- package/dist/esm/hooks/useTheme.native.js.map +1 -1
- package/dist/esm/setupReactNative.js.map +1 -1
- package/dist/esm/setupReactNative.native.js.map +1 -1
- package/package.json +9 -9
- package/src/helpers/ThemeManager.tsx +87 -93
- package/src/hooks/useTheme.tsx +20 -9
- package/src/setupReactNative.ts +3 -0
- package/src/types.tsx +2 -0
- package/types/helpers/ThemeManager.d.ts +7 -7
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/helpers/scheme.d.ts.map +1 -0
- package/types/hooks/useTheme.d.ts +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/setupReactNative.d.ts.map +1 -1
- package/types/types.d.ts +1 -0
- package/types/types.d.ts.map +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/setupReactNative.ts"],
|
|
4
|
-
"mappings": "AAEA,MAAM,2BAA2B,oBAAI,QAA2C;AAEzE,SAAS,qBAAqB,WAAgB;AACnD,MAAK;AAGH,WAAI,UAAU,WAAW,eAAe,UAAU,WAAW,eACpD,UAAU,YAEf,UAAU,qBACL,UAAU,QAEf,UAAU,WAAW,oBAChB,UAAU,
|
|
4
|
+
"mappings": "AAEA,MAAM,2BAA2B,oBAAI,QAA2C;AAEzE,SAAS,qBAAqB,WAAgB;AACnD,MAAK;AAGH,WAAI,UAAU,WAAW,eAAe,UAAU,WAAW,eACpD,UAAU,YAEf,UAAU,qBACL,UAAU,QAEf,UAAU,WAAW,oBAChB,UAAU,OAMZ,UAAU;AAoBrB;AAEA,MAAM,YAAY;AAAA,EAChB,OAAO;AAAA,IACL,eAAe;AAAA,IACf,aAAa,oBAAI,IAAI,CAAC,OAAO,SAAS,QAAQ,CAAC;AAAA,EACjD;AAAA,EACA,MAAM;AAAA,IACJ,eAAe;AAAA,IACf,QAAQ;AAAA,EACV;AAAA,EACA,WAAW;AAAA,IACT,eAAe;AAAA,IACf,SAAS;AAAA,IACT,QAAQ;AAAA,EACV;AAAA,EACA,SAAS;AAAA,IACP,eAAe;AAAA,EACjB;AACF;AAKO,SAAS,iBAAiB,WAAgC;AAcjE;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.74.
|
|
3
|
+
"version": "1.74.16",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"reset.css"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/compose-refs": "1.74.
|
|
31
|
-
"@tamagui/constants": "1.74.
|
|
32
|
-
"@tamagui/helpers": "1.74.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.74.
|
|
34
|
-
"@tamagui/timer": "1.74.
|
|
35
|
-
"@tamagui/use-did-finish-ssr": "1.74.
|
|
36
|
-
"@tamagui/use-force-update": "1.74.
|
|
30
|
+
"@tamagui/compose-refs": "1.74.16",
|
|
31
|
+
"@tamagui/constants": "1.74.16",
|
|
32
|
+
"@tamagui/helpers": "1.74.16",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.74.16",
|
|
34
|
+
"@tamagui/timer": "1.74.16",
|
|
35
|
+
"@tamagui/use-did-finish-ssr": "1.74.16",
|
|
36
|
+
"@tamagui/use-force-update": "1.74.16"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.74.
|
|
42
|
+
"@tamagui/build": "1.74.16",
|
|
43
43
|
"@testing-library/react": "^14.0.0",
|
|
44
44
|
"csstype": "^3.0.10",
|
|
45
45
|
"react": "^18.2.0",
|
|
@@ -2,7 +2,7 @@ import { isWeb } from '@tamagui/constants'
|
|
|
2
2
|
|
|
3
3
|
import { getThemes } from '../config'
|
|
4
4
|
import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants'
|
|
5
|
-
import { ThemeParsed, ThemeProps } from '../types'
|
|
5
|
+
import { ColorScheme, ThemeParsed, ThemeProps } from '../types'
|
|
6
6
|
|
|
7
7
|
type ThemeListener = (
|
|
8
8
|
name: string | null,
|
|
@@ -20,11 +20,12 @@ export type SetActiveThemeProps = {
|
|
|
20
20
|
|
|
21
21
|
export type ThemeManagerState = {
|
|
22
22
|
name: string
|
|
23
|
+
parentName?: string
|
|
23
24
|
theme?: ThemeParsed | null
|
|
25
|
+
isComponent?: boolean
|
|
24
26
|
className?: string
|
|
25
|
-
parentName?: string
|
|
26
|
-
componentName?: string
|
|
27
27
|
inverse?: boolean
|
|
28
|
+
scheme?: ColorScheme
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
const emptyState: ThemeManagerState = { name: '' }
|
|
@@ -37,22 +38,20 @@ let uid = 0
|
|
|
37
38
|
|
|
38
39
|
export class ThemeManager {
|
|
39
40
|
id = uid++
|
|
40
|
-
isComponent = false
|
|
41
41
|
themeListeners = new Set<ThemeListener>()
|
|
42
42
|
parentManager: ThemeManager | null = null
|
|
43
43
|
state: ThemeManagerState = emptyState
|
|
44
|
-
scheme: 'light' | 'dark' | null = null
|
|
45
44
|
|
|
46
45
|
constructor(
|
|
47
46
|
public props: ThemeProps = {},
|
|
48
|
-
|
|
47
|
+
parentManager?: ThemeManager | 'root' | null | undefined
|
|
49
48
|
) {
|
|
50
|
-
if (
|
|
49
|
+
if (parentManager === 'root') {
|
|
51
50
|
this.updateStateFromProps(props, false)
|
|
52
51
|
return
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
if (!
|
|
54
|
+
if (!parentManager) {
|
|
56
55
|
if (process.env.NODE_ENV !== 'production') {
|
|
57
56
|
throw new Error(
|
|
58
57
|
`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.`
|
|
@@ -61,13 +60,14 @@ export class ThemeManager {
|
|
|
61
60
|
throw `❌ 0`
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
this
|
|
63
|
+
// this is used in updateStateFromProps so must be set
|
|
64
|
+
this.parentManager = parentManager
|
|
65
65
|
|
|
66
66
|
if (this.updateStateFromProps(props, false)) {
|
|
67
67
|
return
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
return
|
|
70
|
+
return parentManager
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
updateStateFromProps(
|
|
@@ -81,6 +81,7 @@ export class ThemeManager {
|
|
|
81
81
|
return true
|
|
82
82
|
}
|
|
83
83
|
const nextState = this.getStateIfChanged(props)
|
|
84
|
+
|
|
84
85
|
if (nextState) {
|
|
85
86
|
this.updateState(nextState, shouldNotify)
|
|
86
87
|
return nextState
|
|
@@ -89,11 +90,7 @@ export class ThemeManager {
|
|
|
89
90
|
|
|
90
91
|
updateState(nextState: ThemeManagerState, shouldNotify = true) {
|
|
91
92
|
this.state = nextState
|
|
92
|
-
const names = this.state.name.split('_')
|
|
93
|
-
const lastName = names[names.length - 1][0]
|
|
94
|
-
this.isComponent = lastName[0] === lastName[0].toUpperCase()
|
|
95
93
|
this._allKeys = null
|
|
96
|
-
this.scheme = names[0] === 'light' ? 'light' : names[0] === 'dark' ? 'dark' : null
|
|
97
94
|
if (process.env.NODE_ENV === 'development') {
|
|
98
95
|
this['_numChangeEventsSent'] ??= 0
|
|
99
96
|
this['_numChangeEventsSent']++
|
|
@@ -166,86 +163,61 @@ export class ThemeManager {
|
|
|
166
163
|
}
|
|
167
164
|
}
|
|
168
165
|
|
|
169
|
-
function getNextThemeClassName(name: string) {
|
|
170
|
-
const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`
|
|
171
|
-
return next.replace('light_', '').replace('dark_', '')
|
|
172
|
-
}
|
|
173
|
-
|
|
174
166
|
function getState(
|
|
175
167
|
props: ThemeProps,
|
|
176
|
-
|
|
168
|
+
manager?: ThemeManager | null
|
|
177
169
|
): ThemeManagerState | null {
|
|
178
|
-
const validManagerAndAllComponentThemes = getNonComponentParentManager(parentManager)
|
|
179
|
-
parentManager = validManagerAndAllComponentThemes[0]
|
|
180
|
-
const allComponentThemes = validManagerAndAllComponentThemes[1]
|
|
181
|
-
const themes = getThemes()
|
|
182
|
-
const isDirectParentAComponentTheme = allComponentThemes.length > 0
|
|
183
|
-
|
|
184
170
|
if (props.name && props.reset) {
|
|
185
|
-
throw new Error(
|
|
171
|
+
throw new Error(
|
|
172
|
+
process.env.NODE_ENV === 'production'
|
|
173
|
+
? `❌004`
|
|
174
|
+
: 'Cannot reset and set a new name at the same time.'
|
|
175
|
+
)
|
|
186
176
|
}
|
|
187
177
|
|
|
188
|
-
if (!props
|
|
178
|
+
if (!getHasThemeUpdatingProps(props)) {
|
|
189
179
|
return null
|
|
190
180
|
}
|
|
191
181
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
182
|
+
const themes = getThemes()
|
|
183
|
+
const [allManagers, componentManagers] = getManagers(manager)
|
|
184
|
+
|
|
185
|
+
const isDirectParentAComponentTheme = !!manager?.state.isComponent
|
|
186
|
+
const startIndex =
|
|
187
|
+
allManagers.findIndex((x) => !x?.state.isComponent) +
|
|
188
|
+
(props.reset && !isDirectParentAComponentTheme ? 1 : 0)
|
|
189
|
+
|
|
190
|
+
let baseManager = allManagers[startIndex]
|
|
191
|
+
let parentManager = allManagers[startIndex + 1]
|
|
192
|
+
|
|
193
|
+
if (!baseManager && props.reset) {
|
|
194
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
195
|
+
console.warn('Cannot reset, no parent theme exists')
|
|
195
196
|
}
|
|
196
197
|
return null
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
let result: ThemeManagerState | null = null
|
|
200
201
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
? parentManager?.state?.name || ''
|
|
204
|
-
: parentManager?.parentManager?.state?.name || ''
|
|
205
|
-
: props.name || ''
|
|
206
|
-
const { componentName } = props
|
|
207
|
-
const parentName = props.reset
|
|
208
|
-
? isDirectParentAComponentTheme
|
|
209
|
-
? // here because parentManager already skipped componentTheme so we have to only go up once
|
|
210
|
-
parentManager?.parentManager?.state.name || ''
|
|
211
|
-
: parentManager?.parentManager?.parentManager?.state.name || ''
|
|
212
|
-
: isDirectParentAComponentTheme
|
|
213
|
-
? allComponentThemes[0] || ''
|
|
214
|
-
: parentManager?.state.name || ''
|
|
202
|
+
const baseName = baseManager?.state.name || ''
|
|
203
|
+
const nextName = props.reset ? baseName : props.name || ''
|
|
215
204
|
|
|
205
|
+
const allComponentThemes = componentManagers.map((x) => x?.state.name || '')
|
|
216
206
|
if (props.reset && isDirectParentAComponentTheme) {
|
|
217
|
-
// skip nearest component theme
|
|
218
207
|
allComponentThemes.shift()
|
|
219
208
|
}
|
|
220
209
|
|
|
221
210
|
// components look for most specific, fallback upwards
|
|
222
|
-
const base =
|
|
223
|
-
const lastSegment = base[base.length - 1]
|
|
224
|
-
const isParentComponentTheme =
|
|
225
|
-
parentName && lastSegment[0].toUpperCase() === lastSegment[0]
|
|
226
|
-
if (isParentComponentTheme) {
|
|
227
|
-
base.pop() // always remove componentName they can't nest
|
|
228
|
-
}
|
|
229
|
-
const parentBaseTheme = isParentComponentTheme
|
|
230
|
-
? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)
|
|
231
|
-
: parentName
|
|
211
|
+
const base = baseName.split(THEME_NAME_SEPARATOR)
|
|
232
212
|
const max = base.length
|
|
233
213
|
const min =
|
|
234
|
-
componentName && !nextName
|
|
214
|
+
props.componentName && !nextName
|
|
235
215
|
? max // component name only don't search upwards
|
|
236
216
|
: 0
|
|
237
217
|
|
|
238
218
|
if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {
|
|
239
219
|
console.groupCollapsed('ThemeManager.getState()')
|
|
240
|
-
console.info({
|
|
241
|
-
props,
|
|
242
|
-
parentName,
|
|
243
|
-
parentBaseTheme,
|
|
244
|
-
base,
|
|
245
|
-
min,
|
|
246
|
-
max,
|
|
247
|
-
isParentComponentTheme,
|
|
248
|
-
})
|
|
220
|
+
console.info({ props, baseName, base, min, max })
|
|
249
221
|
}
|
|
250
222
|
|
|
251
223
|
for (let i = max; i >= min; i--) {
|
|
@@ -256,7 +228,7 @@ function getState(
|
|
|
256
228
|
}
|
|
257
229
|
let potentials: string[] = []
|
|
258
230
|
|
|
259
|
-
if (prefix && prefix !==
|
|
231
|
+
if (prefix && prefix !== baseName) {
|
|
260
232
|
potentials.push(prefix)
|
|
261
233
|
}
|
|
262
234
|
if (nextName) {
|
|
@@ -269,41 +241,63 @@ function getState(
|
|
|
269
241
|
}
|
|
270
242
|
}
|
|
271
243
|
|
|
272
|
-
if (componentName) {
|
|
244
|
+
if (props.componentName) {
|
|
273
245
|
let componentPotentials: string[] = []
|
|
274
246
|
// components only look for component themes
|
|
275
247
|
if (nextName) {
|
|
276
248
|
const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))
|
|
277
|
-
componentPotentials.push(`${beforeSeparator}_${nextName}_${componentName}`)
|
|
249
|
+
componentPotentials.push(`${beforeSeparator}_${nextName}_${props.componentName}`)
|
|
278
250
|
}
|
|
279
|
-
componentPotentials.push(`${prefix}_${componentName}`)
|
|
251
|
+
componentPotentials.push(`${prefix}_${props.componentName}`)
|
|
280
252
|
if (nextName) {
|
|
281
253
|
// do this one and one level up
|
|
282
254
|
const prefixLessOne = base.slice(0, i - 1).join(THEME_NAME_SEPARATOR)
|
|
283
255
|
if (prefixLessOne) {
|
|
284
|
-
const lessSpecific = `${prefixLessOne}_${nextName}_${componentName}`
|
|
256
|
+
const lessSpecific = `${prefixLessOne}_${nextName}_${props.componentName}`
|
|
285
257
|
componentPotentials.unshift(lessSpecific)
|
|
286
258
|
}
|
|
287
|
-
const moreSpecific = `${prefix}_${nextName}_${componentName}`
|
|
259
|
+
const moreSpecific = `${prefix}_${nextName}_${props.componentName}`
|
|
288
260
|
componentPotentials.unshift(moreSpecific)
|
|
289
261
|
}
|
|
290
262
|
potentials = [...componentPotentials, ...potentials, ...allComponentThemes]
|
|
291
263
|
}
|
|
264
|
+
|
|
292
265
|
const found = potentials.find((t) => t in themes)
|
|
293
266
|
|
|
294
267
|
if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {
|
|
295
|
-
console.info(' - ', { found, potentials,
|
|
268
|
+
console.info(' - ', { found, potentials, baseManager })
|
|
296
269
|
}
|
|
297
270
|
|
|
298
271
|
if (found) {
|
|
272
|
+
const names = found.split('_')
|
|
273
|
+
const [firstName, ...restNames] = names
|
|
274
|
+
const lastName = names[names.length - 1]
|
|
275
|
+
const isComponent = lastName[0] === lastName[0].toUpperCase()
|
|
276
|
+
const scheme =
|
|
277
|
+
firstName === 'light' ? 'light' : firstName === 'dark' ? 'dark' : undefined
|
|
278
|
+
const pre = THEME_CLASSNAME_PREFIX
|
|
279
|
+
const className = !isWeb
|
|
280
|
+
? ''
|
|
281
|
+
: `${pre}sub_theme ${pre}${
|
|
282
|
+
!scheme || !restNames.length ? firstName : restNames.join('_')
|
|
283
|
+
}`
|
|
284
|
+
|
|
285
|
+
// because its a new theme the baseManager is now the parent
|
|
286
|
+
const parentState = baseManager?.state
|
|
287
|
+
const parentScheme = parentState?.scheme
|
|
288
|
+
const parentName = parentState?.name
|
|
289
|
+
const inverse = parentScheme && scheme !== parentScheme
|
|
290
|
+
|
|
299
291
|
result = {
|
|
300
292
|
name: found,
|
|
301
|
-
theme: themes[found],
|
|
302
|
-
className: isWeb ? getNextThemeClassName(found) : '',
|
|
303
293
|
parentName,
|
|
304
|
-
|
|
305
|
-
|
|
294
|
+
theme: themes[found],
|
|
295
|
+
className,
|
|
296
|
+
inverse,
|
|
297
|
+
isComponent,
|
|
298
|
+
scheme,
|
|
306
299
|
}
|
|
300
|
+
|
|
307
301
|
break
|
|
308
302
|
}
|
|
309
303
|
}
|
|
@@ -313,9 +307,7 @@ function getState(
|
|
|
313
307
|
typeof props.debug === 'string' &&
|
|
314
308
|
typeof window !== 'undefined'
|
|
315
309
|
) {
|
|
316
|
-
console.warn('ThemeManager.getState():', {
|
|
317
|
-
result,
|
|
318
|
-
})
|
|
310
|
+
console.warn('ThemeManager.getState():', { result })
|
|
319
311
|
console.trace()
|
|
320
312
|
console.groupEnd()
|
|
321
313
|
}
|
|
@@ -329,19 +321,21 @@ const inverseThemeName = (themeName: string) => {
|
|
|
329
321
|
: themeName.replace(/^dark/, 'light')
|
|
330
322
|
}
|
|
331
323
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
324
|
+
type MaybeThemeManager = ThemeManager | undefined
|
|
325
|
+
|
|
326
|
+
// components never inherit from components
|
|
327
|
+
// example <Switch><Switch.Thumb /></Switch>
|
|
328
|
+
// the Switch theme shouldn't be considered parent of Thumb
|
|
329
|
+
export function getManagers(themeManager?: ThemeManager | null) {
|
|
330
|
+
const comp: MaybeThemeManager[] = []
|
|
331
|
+
const all: MaybeThemeManager[] = []
|
|
332
|
+
let cur = themeManager
|
|
333
|
+
while (cur) {
|
|
334
|
+
all.push(cur)
|
|
335
|
+
if (cur.state.isComponent) {
|
|
336
|
+
comp.push(cur)
|
|
344
337
|
}
|
|
338
|
+
cur = cur.parentManager
|
|
345
339
|
}
|
|
346
|
-
return [
|
|
340
|
+
return [all, comp] as const
|
|
347
341
|
}
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -133,7 +133,7 @@ export const useThemeWithState = (
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
export function getThemeProxied(
|
|
136
|
-
{ theme, name }: ThemeManagerState,
|
|
136
|
+
{ theme, name, scheme }: ThemeManagerState,
|
|
137
137
|
deopt = false,
|
|
138
138
|
themeManager?: ThemeManager,
|
|
139
139
|
keys?: string[],
|
|
@@ -198,22 +198,21 @@ export function getThemeProxied(
|
|
|
198
198
|
platform !== 'web' &&
|
|
199
199
|
isIos &&
|
|
200
200
|
!deopt &&
|
|
201
|
-
config.settings.fastSchemeChange
|
|
201
|
+
config.settings.fastSchemeChange &&
|
|
202
|
+
!someParentIsInversed(themeManager)
|
|
202
203
|
) {
|
|
203
|
-
|
|
204
|
-
const isLight = !isDark && name.startsWith('light')
|
|
205
|
-
if (isDark || isLight) {
|
|
204
|
+
if (scheme) {
|
|
206
205
|
const oppositeThemeName = name.replace(
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
scheme === 'dark' ? 'dark' : 'light',
|
|
207
|
+
scheme === 'dark' ? 'light' : 'dark'
|
|
209
208
|
)
|
|
210
209
|
const oppositeTheme = config.themes[oppositeThemeName]
|
|
211
210
|
const oppositeVal = getVariable(oppositeTheme?.[keyString])
|
|
212
211
|
if (oppositeVal) {
|
|
213
212
|
const dynamicVal = {
|
|
214
213
|
dynamic: {
|
|
215
|
-
dark:
|
|
216
|
-
light:
|
|
214
|
+
dark: scheme === 'dark' ? outVal : oppositeVal,
|
|
215
|
+
light: scheme === 'light' ? outVal : oppositeVal,
|
|
217
216
|
},
|
|
218
217
|
}
|
|
219
218
|
return dynamicVal
|
|
@@ -240,6 +239,18 @@ export function getThemeProxied(
|
|
|
240
239
|
}) as UseThemeResult
|
|
241
240
|
}
|
|
242
241
|
|
|
242
|
+
// to tell if we are inversing the scheme anywhere in the tree, if so we need to de-opt
|
|
243
|
+
function someParentIsInversed(manager?: ThemeManager) {
|
|
244
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
245
|
+
let cur: ThemeManager | null | undefined = manager
|
|
246
|
+
while (cur) {
|
|
247
|
+
if (cur.state.inverse) return true
|
|
248
|
+
cur = cur.parentManager
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return false
|
|
252
|
+
}
|
|
253
|
+
|
|
243
254
|
export const activeThemeManagers = new Set<ThemeManager>()
|
|
244
255
|
|
|
245
256
|
export const useChangeThemeEffect = (
|
package/src/setupReactNative.ts
CHANGED
|
@@ -15,6 +15,9 @@ export function getReactNativeConfig(Component: any) {
|
|
|
15
15
|
if (Component.propTypes?.textBreakStrategy) {
|
|
16
16
|
return RNConfigs.Text
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
// can optimize plain View or Text to not be react native specific
|
|
20
|
+
|
|
18
21
|
// can assume everything else is react native on native
|
|
19
22
|
return RNConfigs.default
|
|
20
23
|
} else {
|
package/src/types.tsx
CHANGED
|
@@ -29,6 +29,8 @@ import type { ThemeProviderProps } from './views/ThemeProvider'
|
|
|
29
29
|
|
|
30
30
|
export type { MediaStyleObject, StyleObject } from '@tamagui/helpers'
|
|
31
31
|
|
|
32
|
+
export type ColorScheme = 'light' | 'dark'
|
|
33
|
+
|
|
32
34
|
export type IsMediaType = boolean | 'platform' | 'theme' | 'group'
|
|
33
35
|
|
|
34
36
|
export type SpaceDirection = 'vertical' | 'horizontal' | 'both'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThemeParsed, ThemeProps } from '../types';
|
|
1
|
+
import { ColorScheme, ThemeParsed, ThemeProps } from '../types';
|
|
2
2
|
type ThemeListener = (name: string | null, themeManager: ThemeManager, forced: boolean) => void;
|
|
3
3
|
export type SetActiveThemeProps = {
|
|
4
4
|
className?: string;
|
|
@@ -9,22 +9,21 @@ export type SetActiveThemeProps = {
|
|
|
9
9
|
};
|
|
10
10
|
export type ThemeManagerState = {
|
|
11
11
|
name: string;
|
|
12
|
+
parentName?: string;
|
|
12
13
|
theme?: ThemeParsed | null;
|
|
14
|
+
isComponent?: boolean;
|
|
13
15
|
className?: string;
|
|
14
|
-
parentName?: string;
|
|
15
|
-
componentName?: string;
|
|
16
16
|
inverse?: boolean;
|
|
17
|
+
scheme?: ColorScheme;
|
|
17
18
|
};
|
|
18
19
|
export declare function getHasThemeUpdatingProps(props: ThemeProps): string | boolean | undefined;
|
|
19
20
|
export declare class ThemeManager {
|
|
20
21
|
props: ThemeProps;
|
|
21
22
|
id: number;
|
|
22
|
-
isComponent: boolean;
|
|
23
23
|
themeListeners: Set<ThemeListener>;
|
|
24
24
|
parentManager: ThemeManager | null;
|
|
25
25
|
state: ThemeManagerState;
|
|
26
|
-
|
|
27
|
-
constructor(props?: ThemeProps, parentManagerIn?: ThemeManager | 'root' | null | undefined);
|
|
26
|
+
constructor(props?: ThemeProps, parentManager?: ThemeManager | 'root' | null | undefined);
|
|
28
27
|
updateStateFromProps(props?: ThemeProps & {
|
|
29
28
|
forceTheme?: ThemeParsed;
|
|
30
29
|
}, shouldNotify?: boolean): true | ThemeManagerState | undefined;
|
|
@@ -37,6 +36,7 @@ export declare class ThemeManager {
|
|
|
37
36
|
notify(forced?: boolean): void;
|
|
38
37
|
onChangeTheme(cb: ThemeListener, debugId?: number): () => void;
|
|
39
38
|
}
|
|
40
|
-
|
|
39
|
+
type MaybeThemeManager = ThemeManager | undefined;
|
|
40
|
+
export declare function getManagers(themeManager?: ThemeManager | null): readonly [MaybeThemeManager[], MaybeThemeManager[]];
|
|
41
41
|
export {};
|
|
42
42
|
//# sourceMappingURL=ThemeManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../../src/helpers/ThemeManager.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../../src/helpers/ThemeManager.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE/D,KAAK,aAAa,GAAG,CACnB,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,OAAO,KACZ,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;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AG,YAAY,GAAG,SAAS,CAAA;AAKjD,wBAAgB,WAAW,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,uDAY7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheme.d.ts","sourceRoot":"","sources":["../../src/helpers/scheme.ts"],"names":[],"mappings":""}
|
|
@@ -25,7 +25,7 @@ export type UseThemeResult = {
|
|
|
25
25
|
};
|
|
26
26
|
export declare const useTheme: (props?: ThemeProps) => UseThemeResult;
|
|
27
27
|
export declare const useThemeWithState: (props: UseThemeWithStateProps) => [ChangedThemeResponse, ThemeParsed];
|
|
28
|
-
export declare function getThemeProxied({ theme, name }: ThemeManagerState, deopt?: boolean, themeManager?: ThemeManager, keys?: string[], debug?: DebugProp): UseThemeResult;
|
|
28
|
+
export declare function getThemeProxied({ theme, name, scheme }: ThemeManagerState, deopt?: boolean, themeManager?: ThemeManager, keys?: string[], debug?: DebugProp): UseThemeResult;
|
|
29
29
|
export declare const activeThemeManagers: Set<ThemeManager>;
|
|
30
30
|
export declare const useChangeThemeEffect: (props: UseThemeWithStateProps, isRoot?: boolean, keys?: string[], shouldUpdate?: () => boolean | undefined) => ChangedThemeResponse;
|
|
31
31
|
//# sourceMappingURL=useTheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAe,MAAM,mBAAmB,CAAA;AAEzD,OAAO,EACL,YAAY,EACZ,iBAAiB,EAElB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,WAAW,EACX,kBAAkB,EACnB,MAAM,UAAU,CAAA;AAGjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,iBAAiB,CAAA;IACzB,YAAY,CAAC,EAAE,YAAY,GAA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C,SAAS,EAAE,GAAG;;
|
|
1
|
+
{"version":3,"file":"setupReactNative.d.ts","sourceRoot":"","sources":["../src/setupReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAItC,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,GAAG;;qBAqClD;AAqBD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAc9D"}
|
package/types/types.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { Role } from './interfaces/Role';
|
|
|
9
9
|
import type { LanguageContextType } from './views/FontLanguage.types';
|
|
10
10
|
import type { ThemeProviderProps } from './views/ThemeProvider';
|
|
11
11
|
export type { MediaStyleObject, StyleObject } from '@tamagui/helpers';
|
|
12
|
+
export type ColorScheme = 'light' | 'dark';
|
|
12
13
|
export type IsMediaType = boolean | 'platform' | 'theme' | 'group';
|
|
13
14
|
export type SpaceDirection = 'vertical' | 'horizontal' | 'both';
|
|
14
15
|
export type TamaguiElement = HTMLElement | View;
|