@tamagui/web 1.58.1 → 1.58.3
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/constants/accessibilityDirectMap.native.js +10 -10
- package/dist/cjs/constants/accessibilityDirectMap.native.js.map +1 -1
- package/dist/cjs/createComponent.js +16 -5
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTheme.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +1 -5
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/hooks/useTheme.js +21 -13
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/esm/constants/accessibilityDirectMap.native.js +10 -10
- package/dist/esm/constants/accessibilityDirectMap.native.js.map +1 -1
- package/dist/esm/createComponent.js +16 -5
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTheme.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +1 -5
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/hooks/useTheme.js +21 -13
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/package.json +9 -9
- package/src/constants/accessibilityDirectMap.native.tsx +9 -9
- package/src/createComponent.tsx +18 -8
- package/src/createTheme.ts +4 -7
- package/src/helpers/getSplitStyles.tsx +3 -8
- package/src/hooks/useTheme.tsx +42 -18
- package/types/constants/accessibilityDirectMap.native.d.ts +9 -9
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTheme.d.ts +4 -1
- package/types/createTheme.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -30,9 +30,13 @@ export type ChangedThemeResponse = {
|
|
|
30
30
|
|
|
31
31
|
const emptyProps = { name: null }
|
|
32
32
|
|
|
33
|
+
let cached: any
|
|
33
34
|
function getDefaultThemeProxied() {
|
|
35
|
+
if (cached) return cached
|
|
34
36
|
const config = getConfig()
|
|
35
|
-
|
|
37
|
+
const defaultTheme = config.themes.light ?? config.themes[Object.keys(config.themes)[0]]
|
|
38
|
+
cached = getThemeProxied(defaultTheme)
|
|
39
|
+
return cached
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
type ThemeGettable<Val> = Val & {
|
|
@@ -41,7 +45,7 @@ type ThemeGettable<Val> = Val & {
|
|
|
41
45
|
| (Val extends Variable<infer X>
|
|
42
46
|
? X extends VariableValGeneric
|
|
43
47
|
? any
|
|
44
|
-
: X
|
|
48
|
+
: Exclude<X, Variable>
|
|
45
49
|
: Val extends VariableVal
|
|
46
50
|
? string | number
|
|
47
51
|
: unknown)
|
|
@@ -70,7 +74,11 @@ export const useThemeWithState = (
|
|
|
70
74
|
? () => {
|
|
71
75
|
const next =
|
|
72
76
|
props.shouldUpdate?.() ?? (keys.current.length > 0 ? true : undefined)
|
|
73
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
process.env.NODE_ENV === 'development' &&
|
|
79
|
+
props.debug &&
|
|
80
|
+
props.debug !== 'profile'
|
|
81
|
+
) {
|
|
74
82
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
75
83
|
console.log(` 🎨 useTheme() shouldUpdate?`, next, {
|
|
76
84
|
shouldUpdateProp: props.shouldUpdate?.(),
|
|
@@ -118,11 +126,13 @@ export function getThemeProxied(
|
|
|
118
126
|
): UseThemeResult {
|
|
119
127
|
return createProxy(theme, {
|
|
120
128
|
has(_, key) {
|
|
129
|
+
if (Reflect.has(theme, key)) {
|
|
130
|
+
return true
|
|
131
|
+
}
|
|
121
132
|
if (typeof key === 'string') {
|
|
122
133
|
if (key[0] === '$') key = key.slice(1)
|
|
123
134
|
return themeManager?.allKeys.has(key)
|
|
124
135
|
}
|
|
125
|
-
return Reflect.has(theme, key)
|
|
126
136
|
},
|
|
127
137
|
get(_, key) {
|
|
128
138
|
if (key === GetThemeUnwrapped) {
|
|
@@ -132,8 +142,7 @@ export function getThemeProxied(
|
|
|
132
142
|
// dont ask me, idk why but on hermes you can see that useTheme()[undefined] passes in STRING undefined to proxy
|
|
133
143
|
// if someone is crazy enough to use "undefined" as a theme key then this not working is on them
|
|
134
144
|
key !== 'undefined' &&
|
|
135
|
-
typeof key === 'string'
|
|
136
|
-
keys
|
|
145
|
+
typeof key === 'string'
|
|
137
146
|
) {
|
|
138
147
|
// auto convert variables to plain
|
|
139
148
|
const keyString = key[0] === '$' ? key.slice(1) : key
|
|
@@ -146,14 +155,16 @@ export function getThemeProxied(
|
|
|
146
155
|
// if its a variable (web), its ignored!
|
|
147
156
|
get(_, subkey) {
|
|
148
157
|
// trigger read key that makes it track updates
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
if (keys) {
|
|
159
|
+
if (
|
|
160
|
+
(subkey === 'val' || (subkey === 'get' && !isWeb)) &&
|
|
161
|
+
!keys.includes(keyString)
|
|
162
|
+
) {
|
|
163
|
+
keys.push(keyString)
|
|
164
|
+
if (process.env.NODE_ENV === 'development' && debug) {
|
|
165
|
+
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
166
|
+
console.log(` 🎨 useTheme() tracking new key: ${keyString}`)
|
|
167
|
+
}
|
|
157
168
|
}
|
|
158
169
|
}
|
|
159
170
|
if (subkey === 'get') {
|
|
@@ -194,6 +205,19 @@ export const useChangeThemeEffect = (
|
|
|
194
205
|
}
|
|
195
206
|
}
|
|
196
207
|
|
|
208
|
+
// for testing performance can bail it out early with this fake response:
|
|
209
|
+
// i found most of the cost was just having a useState at all, at least 30%
|
|
210
|
+
// if (!disable && parentManager) {
|
|
211
|
+
// return {
|
|
212
|
+
// isNewTheme: false,
|
|
213
|
+
// state: {
|
|
214
|
+
// name: 'light',
|
|
215
|
+
// theme: getConfig().themes.light,
|
|
216
|
+
// },
|
|
217
|
+
// themeManager: parentManager!,
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
220
|
+
|
|
197
221
|
const [themeState, setThemeState] = useState<ChangedThemeResponse>(createState)
|
|
198
222
|
const { state, mounted, isNewTheme, themeManager } = themeState
|
|
199
223
|
const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)
|
|
@@ -209,8 +233,8 @@ export const useChangeThemeEffect = (
|
|
|
209
233
|
const next = nextState || manager.getState(props, parentManager)
|
|
210
234
|
if (forceShouldChange) return next
|
|
211
235
|
if (!next) return
|
|
212
|
-
if (forceUpdate !== true) {
|
|
213
|
-
|
|
236
|
+
if (forceUpdate !== true && !manager.getStateShouldChange(next, prevState)) {
|
|
237
|
+
return
|
|
214
238
|
}
|
|
215
239
|
return next
|
|
216
240
|
}
|
|
@@ -278,7 +302,7 @@ export const useChangeThemeEffect = (
|
|
|
278
302
|
mounted,
|
|
279
303
|
])
|
|
280
304
|
|
|
281
|
-
if (process.env.NODE_ENV === 'development') {
|
|
305
|
+
if (process.env.NODE_ENV === 'development' && props.debug !== 'profile') {
|
|
282
306
|
useEffect(() => {
|
|
283
307
|
globalThis['TamaguiThemeManagers'] ??= new Set()
|
|
284
308
|
globalThis['TamaguiThemeManagers'].add(themeManager)
|
|
@@ -369,7 +393,7 @@ export const useChangeThemeEffect = (
|
|
|
369
393
|
|
|
370
394
|
if (!state) {
|
|
371
395
|
if (isNewTheme) {
|
|
372
|
-
state =
|
|
396
|
+
state = themeManager.state
|
|
373
397
|
} else {
|
|
374
398
|
state = parentManager!.state
|
|
375
399
|
themeManager = parentManager!
|
|
@@ -20,37 +20,37 @@ export declare const nativeAccessibilityState: {
|
|
|
20
20
|
'aria-expanded': string;
|
|
21
21
|
};
|
|
22
22
|
export declare const accessibilityWebRoleToNativeRole: {
|
|
23
|
-
slider: string;
|
|
24
|
-
heading: string;
|
|
25
|
-
img: string;
|
|
26
|
-
link: string;
|
|
27
|
-
presentation: string;
|
|
28
|
-
region: string;
|
|
29
|
-
group: string;
|
|
30
23
|
alert: string;
|
|
31
24
|
button: string;
|
|
32
25
|
checkbox: string;
|
|
33
26
|
combobox: string;
|
|
27
|
+
grid: string;
|
|
28
|
+
group: string;
|
|
29
|
+
heading: string;
|
|
34
30
|
imagebutton: string;
|
|
31
|
+
img: string;
|
|
35
32
|
keyboardkey: string;
|
|
33
|
+
link: string;
|
|
36
34
|
menu: string;
|
|
37
35
|
menubar: string;
|
|
38
36
|
menuitem: string;
|
|
39
37
|
none: string;
|
|
38
|
+
presentation: string;
|
|
40
39
|
progressbar: string;
|
|
41
40
|
radio: string;
|
|
42
41
|
radiogroup: string;
|
|
42
|
+
region: string;
|
|
43
43
|
scrollbar: string;
|
|
44
44
|
searchbox: string;
|
|
45
|
+
slider: string;
|
|
45
46
|
spinbutton: string;
|
|
46
|
-
grid: string;
|
|
47
47
|
summary: string;
|
|
48
48
|
switch: string;
|
|
49
49
|
tab: string;
|
|
50
50
|
tablist: string;
|
|
51
51
|
text: string;
|
|
52
52
|
timer: string;
|
|
53
|
-
toolbar: string;
|
|
54
53
|
togglebutton: string;
|
|
54
|
+
toolbar: string;
|
|
55
55
|
};
|
|
56
56
|
//# sourceMappingURL=accessibilityDirectMap.native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AAIA,OAAO,KAaN,MAAM,OAAO,CAAA;AAiBd,OAAO,EAEL,SAAS,EAIT,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,gBAAgB,EAEhB,qBAAqB,EACrB,cAAc,EAEd,SAAS,EAGV,MAAM,SAAS,CAAA;AAQhB,eAAO,MAAM,qBAAqB,EAAE,qBAMnC,CAAA;
|
|
1
|
+
{"version":3,"file":"createComponent.d.ts","sourceRoot":"","sources":["../src/createComponent.tsx"],"names":[],"mappings":"AAIA,OAAO,KAaN,MAAM,OAAO,CAAA;AAiBd,OAAO,EAEL,SAAS,EAIT,cAAc,EACd,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,gBAAgB,EAEhB,qBAAqB,EACrB,cAAc,EAEd,SAAS,EAGV,MAAM,SAAS,CAAA;AAQhB,eAAO,MAAM,qBAAqB,EAAE,qBAMnC,CAAA;AAqBD,eAAO,MAAM,QAAQ,eAAsB,CAAA;AAmB3C,wBAAgB,eAAe,CAC7B,kBAAkB,SAAS,UAAU,GAAG,SAAS,GAAG,EAAE,EACtD,GAAG,GAAG,cAAc,EACpB,SAAS,GAAG,KAAK,EACjB,YAAY,EAAE,YAAY,4DA4kC3B;AAGD,wBAAgB,QAAQ,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAE,OAEjD;AAMD,eAAO,MAAM,MAAM,0DA8CjB,CAAA;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;CAClB,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,mBAkGxD"}
|
package/types/createTheme.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import type { Variable } from './createVariable';
|
|
|
2
2
|
type GenericTheme = {
|
|
3
3
|
[key: string]: string | Variable;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated no need to use this anymore, can just remove the call and use plain objects
|
|
7
|
+
*/
|
|
8
|
+
export declare const createTheme: <Theme extends GenericTheme>(theme: Theme) => Theme;
|
|
6
9
|
export {};
|
|
7
10
|
//# sourceMappingURL=createTheme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTheme.d.ts","sourceRoot":"","sources":["../src/createTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEhD,KAAK,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"createTheme.d.ts","sourceRoot":"","sources":["../src/createTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEhD,KAAK,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAExD;;GAEG;AACH,eAAO,MAAM,WAAW,qDAEvB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSplitStyles.d.ts","sourceRoot":"","sources":["../../src/helpers/getSplitStyles.tsx"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAEV,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,aAAa,EAMb,eAAe,EACf,YAAY,EAEZ,qBAAqB,EAErB,cAAc,EACd,WAAW,EAEZ,MAAM,UAAU,CAAA;AAyBjB,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA;AAE3D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA;AAMhE,KAAK,aAAa,GAAG,CACnB,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC7B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,qBAAqB,EACrC,UAAU,EAAE,eAAe,EAC3B,iBAAiB,CAAC,EAAE,cAAc,GAAG,IAAI,EACzC,OAAO,CAAC,EAAE,iBAAiB,EAE3B,WAAW,CAAC,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,SAAS,KACd,cAAc,CAAA;AAEnB,eAAO,MAAM,UAAU,MAAM,CAAA;AAuB7B,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"getSplitStyles.d.ts","sourceRoot":"","sources":["../../src/helpers/getSplitStyles.tsx"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAEV,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,aAAa,EAMb,eAAe,EACf,YAAY,EAEZ,qBAAqB,EAErB,cAAc,EACd,WAAW,EAEZ,MAAM,UAAU,CAAA;AAyBjB,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA;AAE3D,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA;AAMhE,KAAK,aAAa,GAAG,CACnB,KAAK,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC7B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,qBAAqB,EACrC,UAAU,EAAE,eAAe,EAC3B,iBAAiB,CAAC,EAAE,cAAc,GAAG,IAAI,EACzC,OAAO,CAAC,EAAE,iBAAiB,EAE3B,WAAW,CAAC,EAAE,MAAM,EACpB,KAAK,CAAC,EAAE,SAAS,KACd,cAAc,CAAA;AAEnB,eAAO,MAAM,UAAU,MAAM,CAAA;AAuB7B,eAAO,MAAM,cAAc,EAAE,aAgpC5B,CAAA;AAqDD,eAAO,MAAM,WAAW,eACV,aAAa,UACjB,MAAM,WACL,MAAM,wBACO,OAAO,KAC5B,cAuBF,CAAA;AA0BD,eAAO,MAAM,cAAc,EAAE,aAQ5B,CAAA"}
|
|
@@ -8,7 +8,7 @@ export type ChangedThemeResponse = {
|
|
|
8
8
|
mounted?: boolean;
|
|
9
9
|
};
|
|
10
10
|
type ThemeGettable<Val> = Val & {
|
|
11
|
-
get: () => string | (Val extends Variable<infer X> ? X extends VariableValGeneric ? any : X : Val extends VariableVal ? string | number : unknown);
|
|
11
|
+
get: () => string | (Val extends Variable<infer X> ? X extends VariableValGeneric ? any : Exclude<X, Variable> : Val extends VariableVal ? string | number : unknown);
|
|
12
12
|
};
|
|
13
13
|
type UseThemeResult = {
|
|
14
14
|
[Key in keyof ThemeParsed]: ThemeGettable<ThemeParsed[Key]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.tsx"],"names":[],"mappings":"AAKA,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,EAEV,WAAW,EACX,kBAAkB,EACnB,MAAM,UAAU,CAAA;AAGjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,iBAAiB,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;IAC1B,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;
|
|
1
|
+
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.tsx"],"names":[],"mappings":"AAKA,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,EAEV,WAAW,EACX,kBAAkB,EACnB,MAAM,UAAU,CAAA;AAGjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,iBAAiB,CAAA;IACxB,YAAY,EAAE,YAAY,CAAA;IAC1B,UAAU,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAaD,KAAK,aAAa,CAAC,GAAG,IAAI,GAAG,GAAG;IAC9B,GAAG,EAAE,MACD,MAAM,GACN,CAAC,GAAG,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GAC1B,CAAC,SAAS,kBAAkB,GAC1B,GAAG,GACH,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,GACtB,GAAG,SAAS,WAAW,GACvB,MAAM,GAAG,MAAM,GACf,OAAO,CAAC,CAAA;CACjB,CAAA;AAED,KAAK,cAAc,GAAG;KACnB,GAAG,IAAI,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;CAC5D,CAAA;AAED,eAAO,MAAM,QAAQ,WAAW,UAAU,mBAIzC,CAAA;AAED,eAAO,MAAM,iBAAiB,UACrB,UAAU,KAChB,CAAC,oBAAoB,EAAE,WAAW,CAqDpC,CAAA;AAED,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,EAClB,YAAY,CAAC,EAAE,YAAY,EAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,EACf,KAAK,CAAC,EAAE,SAAS,GAChB,cAAc,CAwDhB;AAED,eAAO,MAAM,mBAAmB,mBAA0B,CAAA;AAE1D,eAAO,MAAM,oBAAoB,UACxB,UAAU,yBAEV,MAAM,EAAE,iBACA,MAAM,OAAO,GAAG,SAAS,KACvC,oBAmPF,CAAA"}
|