@tamagui/web 1.14.6 → 1.14.8
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 +4 -1
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +50 -24
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/views/ThemeDebug.js +57 -38
- package/dist/cjs/views/ThemeDebug.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +4 -1
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.mjs +4 -1
- package/dist/esm/helpers/ThemeManager.mjs.map +2 -2
- package/dist/esm/hooks/useTheme.js +50 -24
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/hooks/useTheme.mjs +50 -24
- package/dist/esm/hooks/useTheme.mjs.map +2 -2
- package/dist/esm/views/ThemeDebug.js +59 -40
- package/dist/esm/views/ThemeDebug.js.map +2 -2
- package/dist/esm/views/ThemeDebug.mjs +59 -40
- package/dist/esm/views/ThemeDebug.mjs.map +2 -2
- package/package.json +9 -9
- package/src/helpers/ThemeManager.tsx +5 -1
- package/src/hooks/useTheme.tsx +54 -26
- package/src/views/ThemeDebug.tsx +55 -34
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/views/ThemeDebug.d.ts.map +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeDebug.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useState } from 'react'\n\nimport { ChangedThemeResponse } from '../hooks/useTheme.js'\nimport { ThemeProps } from '../types.js'\n\nexport function ThemeDebug({\n themeState,\n themeProps,\n children,\n}: {\n themeState: ChangedThemeResponse\n themeProps: ThemeProps\n children: any\n}) {\n if (process.env.NODE_ENV === 'development') {\n const [onChangeCount, setOnChangeCount] = useState(0)\n const rerender = useForceUpdate()\n\n useEffect(() => {\n themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {\n setOnChangeCount((p) => ++p)\n console.warn(`theme changed`, name)\n })\n }, [themeState.themeManager])\n\n useEffect(() => {\n // to refresh _listeningIds every so often\n const tm = setInterval(rerender, 100)\n return () => clearTimeout(tm)\n }, [])\n\n return (\n <
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useId, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { ChangedThemeResponse } from '../hooks/useTheme.js'\nimport { ThemeProps } from '../types.js'\n\nlet node\n\nexport function ThemeDebug({\n themeState,\n themeProps,\n children,\n}: {\n themeState: ChangedThemeResponse\n themeProps: ThemeProps\n children: any\n}) {\n if (process.env.NODE_ENV === 'development') {\n const [onChangeCount, setOnChangeCount] = useState(0)\n const rerender = useForceUpdate()\n const id = useId()\n\n if (process.env.NODE_ENV === 'development' && typeof document !== 'undefined') {\n if (!node) {\n node = document.createElement('div')\n node.style.width = '100%'\n node.style.height = '200px'\n node.style.overflowY = 'scroll'\n node.style.position = 'fixed'\n node.style.top = '0px'\n node.style.left = '0px'\n node.style.display = 'flex'\n node.style.flexDirection = 'row'\n node.style.background = 'var(--background)'\n document.body.appendChild(node)\n }\n }\n\n useEffect(() => {\n themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {\n setOnChangeCount((p) => ++p)\n console.warn(`theme changed`, name)\n })\n }, [themeState.themeManager])\n\n useEffect(() => {\n // to refresh _listeningIds every so often\n const tm = setInterval(rerender, 100)\n return () => clearTimeout(tm)\n }, [])\n\n return (\n <>\n {createPortal(\n <code\n style={{\n whiteSpace: 'pre',\n }}\n >\n <Theme {id} /> \n {JSON.stringify(\n {\n name: themeState.name,\n className: themeState.className,\n inverse: themeProps.inverse,\n forceClassName: themeProps.forceClassName,\n parent: themeState.themeManager?.state.parentName,\n id: themeState.themeManager?.id,\n parentId: themeState.themeManager?.parentManager?.id,\n isNew: themeState.isNewTheme,\n onChangeCount,\n listening: [...(themeState.themeManager?.['_listeningIds'] || [])].join(\n ','\n ),\n _numChangeEventsSent: themeState.themeManager?.['_numChangeEventsSent'],\n },\n null,\n 2\n )}\n </code>,\n node\n )}\n\n <div>{id}</div>\n\n {children}\n </>\n )\n }\n return children\n}\n"],
|
|
5
|
+
"mappings": "AAqDM,mBA+BE,KA7BE,YAFJ;AArDN,SAAS,sBAAsB;AAC/B,SAAS,WAAW,OAAe,gBAAgB;AACnD,SAAS,oBAAoB;AAK7B,IAAI;AAEG,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAjBH;AAkBE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,CAAC;AACpD,UAAM,WAAW,eAAe;AAChC,UAAM,KAAK,MAAM;AAEjB,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,aAAa,aAAa;AAC7E,UAAI,CAAC,MAAM;AACT,eAAO,SAAS,cAAc,KAAK;AACnC,aAAK,MAAM,QAAQ;AACnB,aAAK,MAAM,SAAS;AACpB,aAAK,MAAM,YAAY;AACvB,aAAK,MAAM,WAAW;AACtB,aAAK,MAAM,MAAM;AACjB,aAAK,MAAM,OAAO;AAClB,aAAK,MAAM,UAAU;AACrB,aAAK,MAAM,gBAAgB;AAC3B,aAAK,MAAM,aAAa;AACxB,iBAAS,KAAK,YAAY,IAAI;AAAA,MAChC;AAAA,IACF;AAEA,cAAU,MAAM;AAvCpB,UAAAA,KAAAC;AAwCM,OAAAA,OAAAD,MAAA,WAAW,iBAAX,gBAAAA,IAAyB,kBAAzB,gBAAAC,IAAwC,cAAc,CAAC,MAAM,YAAY;AACvE,yBAAiB,CAAC,MAAM,EAAE,CAAC;AAC3B,gBAAQ,KAAK,iBAAiB,IAAI;AAAA,MACpC;AAAA,IACF,GAAG,CAAC,WAAW,YAAY,CAAC;AAE5B,cAAU,MAAM;AAEd,YAAM,KAAK,YAAY,UAAU,GAAG;AACpC,aAAO,MAAM,aAAa,EAAE;AAAA,IAC9B,GAAG,CAAC,CAAC;AAEL,WACE,iCACG;AAAA;AAAA,QACC;AAAA,UAAC;AAAA;AAAA,YACC,OAAO;AAAA,cACL,YAAY;AAAA,YACd;AAAA,YACD;AAAA;AAAA,cACY;AAAA,cAAG;AAAA,cACb,KAAK;AAAA,gBACJ;AAAA,kBACE,MAAM,WAAW;AAAA,kBACjB,WAAW,WAAW;AAAA,kBACtB,SAAS,WAAW;AAAA,kBACpB,gBAAgB,WAAW;AAAA,kBAC3B,SAAQ,gBAAW,iBAAX,mBAAyB,MAAM;AAAA,kBACvC,KAAI,gBAAW,iBAAX,mBAAyB;AAAA,kBAC7B,WAAU,sBAAW,iBAAX,mBAAyB,kBAAzB,mBAAwC;AAAA,kBAClD,OAAO,WAAW;AAAA,kBAClB;AAAA,kBACA,WAAW,CAAC,KAAI,gBAAW,iBAAX,mBAA0B,qBAAoB,CAAC,CAAE,EAAE;AAAA,oBACjE;AAAA,kBACF;AAAA,kBACA,uBAAsB,gBAAW,iBAAX,mBAA0B;AAAA,gBAClD;AAAA,gBACA;AAAA,gBACA;AAAA,cACF;AAAA;AAAA;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,MAEA,oBAAC,SAAK,cAAG;AAAA,MAER;AAAA,OACH;AAAA,EAEJ;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["_a", "_b"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
3
|
+
import { useEffect, useId, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
let node;
|
|
4
6
|
function ThemeDebug({
|
|
5
7
|
themeState,
|
|
6
8
|
themeProps,
|
|
@@ -10,6 +12,22 @@ function ThemeDebug({
|
|
|
10
12
|
if (process.env.NODE_ENV === "development") {
|
|
11
13
|
const [onChangeCount, setOnChangeCount] = useState(0);
|
|
12
14
|
const rerender = useForceUpdate();
|
|
15
|
+
const id = useId();
|
|
16
|
+
if (process.env.NODE_ENV === "development" && typeof document !== "undefined") {
|
|
17
|
+
if (!node) {
|
|
18
|
+
node = document.createElement("div");
|
|
19
|
+
node.style.width = "100%";
|
|
20
|
+
node.style.height = "200px";
|
|
21
|
+
node.style.overflowY = "scroll";
|
|
22
|
+
node.style.position = "fixed";
|
|
23
|
+
node.style.top = "0px";
|
|
24
|
+
node.style.left = "0px";
|
|
25
|
+
node.style.display = "flex";
|
|
26
|
+
node.style.flexDirection = "row";
|
|
27
|
+
node.style.background = "var(--background)";
|
|
28
|
+
document.body.appendChild(node);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
13
31
|
useEffect(() => {
|
|
14
32
|
var _a2, _b2;
|
|
15
33
|
(_b2 = (_a2 = themeState.themeManager) == null ? void 0 : _a2.parentManager) == null ? void 0 : _b2.onChangeTheme((name, manager) => {
|
|
@@ -21,44 +39,45 @@ function ThemeDebug({
|
|
|
21
39
|
const tm = setInterval(rerender, 100);
|
|
22
40
|
return () => clearTimeout(tm);
|
|
23
41
|
}, []);
|
|
24
|
-
return /* @__PURE__ */ jsxs(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
42
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
43
|
+
createPortal(
|
|
44
|
+
/* @__PURE__ */ jsxs(
|
|
45
|
+
"code",
|
|
46
|
+
{
|
|
47
|
+
style: {
|
|
48
|
+
whiteSpace: "pre"
|
|
49
|
+
},
|
|
50
|
+
children: [
|
|
51
|
+
"<Theme ",
|
|
52
|
+
id,
|
|
53
|
+
" />\xA0",
|
|
54
|
+
JSON.stringify(
|
|
55
|
+
{
|
|
56
|
+
name: themeState.name,
|
|
57
|
+
className: themeState.className,
|
|
58
|
+
inverse: themeProps.inverse,
|
|
59
|
+
forceClassName: themeProps.forceClassName,
|
|
60
|
+
parent: (_a = themeState.themeManager) == null ? void 0 : _a.state.parentName,
|
|
61
|
+
id: (_b = themeState.themeManager) == null ? void 0 : _b.id,
|
|
62
|
+
parentId: (_d = (_c = themeState.themeManager) == null ? void 0 : _c.parentManager) == null ? void 0 : _d.id,
|
|
63
|
+
isNew: themeState.isNewTheme,
|
|
64
|
+
onChangeCount,
|
|
65
|
+
listening: [...((_e = themeState.themeManager) == null ? void 0 : _e["_listeningIds"]) || []].join(
|
|
66
|
+
","
|
|
67
|
+
),
|
|
68
|
+
_numChangeEventsSent: (_f = themeState.themeManager) == null ? void 0 : _f["_numChangeEventsSent"]
|
|
69
|
+
},
|
|
70
|
+
null,
|
|
71
|
+
2
|
|
72
|
+
)
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
node
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ jsx("div", { children: id }),
|
|
79
|
+
children
|
|
80
|
+
] });
|
|
62
81
|
}
|
|
63
82
|
return children;
|
|
64
83
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeDebug.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useState } from 'react'\n\nimport { ChangedThemeResponse } from '../hooks/useTheme.js'\nimport { ThemeProps } from '../types.js'\n\nexport function ThemeDebug({\n themeState,\n themeProps,\n children,\n}: {\n themeState: ChangedThemeResponse\n themeProps: ThemeProps\n children: any\n}) {\n if (process.env.NODE_ENV === 'development') {\n const [onChangeCount, setOnChangeCount] = useState(0)\n const rerender = useForceUpdate()\n\n useEffect(() => {\n themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {\n setOnChangeCount((p) => ++p)\n console.warn(`theme changed`, name)\n })\n }, [themeState.themeManager])\n\n useEffect(() => {\n // to refresh _listeningIds every so often\n const tm = setInterval(rerender, 100)\n return () => clearTimeout(tm)\n }, [])\n\n return (\n <
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useId, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { ChangedThemeResponse } from '../hooks/useTheme.js'\nimport { ThemeProps } from '../types.js'\n\nlet node\n\nexport function ThemeDebug({\n themeState,\n themeProps,\n children,\n}: {\n themeState: ChangedThemeResponse\n themeProps: ThemeProps\n children: any\n}) {\n if (process.env.NODE_ENV === 'development') {\n const [onChangeCount, setOnChangeCount] = useState(0)\n const rerender = useForceUpdate()\n const id = useId()\n\n if (process.env.NODE_ENV === 'development' && typeof document !== 'undefined') {\n if (!node) {\n node = document.createElement('div')\n node.style.width = '100%'\n node.style.height = '200px'\n node.style.overflowY = 'scroll'\n node.style.position = 'fixed'\n node.style.top = '0px'\n node.style.left = '0px'\n node.style.display = 'flex'\n node.style.flexDirection = 'row'\n node.style.background = 'var(--background)'\n document.body.appendChild(node)\n }\n }\n\n useEffect(() => {\n themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {\n setOnChangeCount((p) => ++p)\n console.warn(`theme changed`, name)\n })\n }, [themeState.themeManager])\n\n useEffect(() => {\n // to refresh _listeningIds every so often\n const tm = setInterval(rerender, 100)\n return () => clearTimeout(tm)\n }, [])\n\n return (\n <>\n {createPortal(\n <code\n style={{\n whiteSpace: 'pre',\n }}\n >\n <Theme {id} /> \n {JSON.stringify(\n {\n name: themeState.name,\n className: themeState.className,\n inverse: themeProps.inverse,\n forceClassName: themeProps.forceClassName,\n parent: themeState.themeManager?.state.parentName,\n id: themeState.themeManager?.id,\n parentId: themeState.themeManager?.parentManager?.id,\n isNew: themeState.isNewTheme,\n onChangeCount,\n listening: [...(themeState.themeManager?.['_listeningIds'] || [])].join(\n ','\n ),\n _numChangeEventsSent: themeState.themeManager?.['_numChangeEventsSent'],\n },\n null,\n 2\n )}\n </code>,\n node\n )}\n\n <div>{id}</div>\n\n {children}\n </>\n )\n }\n return children\n}\n"],
|
|
5
|
+
"mappings": "AAqDM,mBA+BE,KA7BE,YAFJ;AArDN,SAAS,sBAAsB;AAC/B,SAAS,WAAW,OAAe,gBAAgB;AACnD,SAAS,oBAAoB;AAK7B,IAAI;AAEG,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAIG;AAjBH;AAkBE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,CAAC;AACpD,UAAM,WAAW,eAAe;AAChC,UAAM,KAAK,MAAM;AAEjB,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,aAAa,aAAa;AAC7E,UAAI,CAAC,MAAM;AACT,eAAO,SAAS,cAAc,KAAK;AACnC,aAAK,MAAM,QAAQ;AACnB,aAAK,MAAM,SAAS;AACpB,aAAK,MAAM,YAAY;AACvB,aAAK,MAAM,WAAW;AACtB,aAAK,MAAM,MAAM;AACjB,aAAK,MAAM,OAAO;AA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AAC,SAAK,cAAG;AAAA,MAER;AAAA,OACH;AAAA,EAEJ;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["_a", "_b"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.8",
|
|
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.14.
|
|
31
|
-
"@tamagui/constants": "1.14.
|
|
32
|
-
"@tamagui/helpers": "1.14.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.14.
|
|
34
|
-
"@tamagui/use-did-finish-ssr": "1.14.
|
|
35
|
-
"@tamagui/use-event": "1.14.
|
|
36
|
-
"@tamagui/use-force-update": "1.14.
|
|
30
|
+
"@tamagui/compose-refs": "1.14.8",
|
|
31
|
+
"@tamagui/constants": "1.14.8",
|
|
32
|
+
"@tamagui/helpers": "1.14.8",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.14.8",
|
|
34
|
+
"@tamagui/use-did-finish-ssr": "1.14.8",
|
|
35
|
+
"@tamagui/use-event": "1.14.8",
|
|
36
|
+
"@tamagui/use-force-update": "1.14.8"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.14.
|
|
42
|
+
"@tamagui/build": "1.14.8",
|
|
43
43
|
"@testing-library/react": "^13.4.0",
|
|
44
44
|
"csstype": "^3.0.10",
|
|
45
45
|
"react": "^18.2.0",
|
|
@@ -209,6 +209,10 @@ function getState(
|
|
|
209
209
|
throw new Error('Cannot reset + set new name')
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
+
if (!props.name && !props.inverse && !props.reset && !props.componentName) {
|
|
213
|
+
return null
|
|
214
|
+
}
|
|
215
|
+
|
|
212
216
|
if (props.reset && !parentManager?.parentManager) {
|
|
213
217
|
if (process.env.NODE_ENV === 'development') {
|
|
214
218
|
console.warn('Cannot reset no grandparent exists')
|
|
@@ -288,7 +292,7 @@ function getState(
|
|
|
288
292
|
const found = potentials.find((t) => t in themes)
|
|
289
293
|
|
|
290
294
|
if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {
|
|
291
|
-
console.log(' - ', { found, potentials })
|
|
295
|
+
console.log(' - ', { found, potentials, parentManager })
|
|
292
296
|
}
|
|
293
297
|
|
|
294
298
|
if (found) {
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -180,19 +180,12 @@ export const useChangeThemeEffect = (
|
|
|
180
180
|
const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)
|
|
181
181
|
const shouldReturnParentState = isInversingOnMount
|
|
182
182
|
|
|
183
|
-
function
|
|
184
|
-
const next = manager.getState(
|
|
185
|
-
props,
|
|
186
|
-
parentManager === themeManager ? parentManager.parentManager : parentManager
|
|
187
|
-
)
|
|
188
|
-
return next
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function getThemeManagerNextStateIfChanged(
|
|
183
|
+
function getShouldUpdateTheme(
|
|
192
184
|
manager = themeManager,
|
|
185
|
+
nextState?: ThemeManagerState | null,
|
|
193
186
|
forceShouldChange = false
|
|
194
187
|
) {
|
|
195
|
-
const next =
|
|
188
|
+
const next = nextState || manager.getState(props, parentManager)
|
|
196
189
|
if (!next) return
|
|
197
190
|
if (disableUpdate?.() === true) return
|
|
198
191
|
if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return
|
|
@@ -221,26 +214,35 @@ export const useChangeThemeEffect = (
|
|
|
221
214
|
|
|
222
215
|
// listen for parent change + notify children change
|
|
223
216
|
useLayoutEffect(() => {
|
|
224
|
-
const nextState =
|
|
217
|
+
const nextState = getShouldUpdateTheme(themeManager)
|
|
225
218
|
|
|
226
219
|
if (nextState) {
|
|
227
220
|
if (isNewTheme) {
|
|
228
221
|
// if it's a new theme we can just update + publish to children
|
|
229
222
|
themeManager.updateState(nextState, true)
|
|
230
223
|
}
|
|
224
|
+
|
|
231
225
|
// if not we will be creating a whole new themeManager
|
|
232
226
|
setThemeState(createState)
|
|
227
|
+
} else {
|
|
228
|
+
if (isNewTheme) {
|
|
229
|
+
// need to revert to parent
|
|
230
|
+
setThemeState(createState)
|
|
231
|
+
}
|
|
233
232
|
}
|
|
234
233
|
|
|
235
|
-
const disposeChangeListener = parentManager?.onChangeTheme(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
234
|
+
const disposeChangeListener = themeManager.parentManager?.onChangeTheme(
|
|
235
|
+
(name, manager) => {
|
|
236
|
+
const shouldUpdate = Boolean(keys?.length || isNewTheme)
|
|
237
|
+
if (shouldUpdate) {
|
|
238
|
+
if (process.env.NODE_ENV === 'development' && props['debug']) {
|
|
239
|
+
console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })
|
|
240
|
+
}
|
|
241
|
+
setThemeState(createState)
|
|
240
242
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
},
|
|
244
|
+
themeManager.id
|
|
245
|
+
)
|
|
244
246
|
|
|
245
247
|
return () => {
|
|
246
248
|
disposeChangeListener?.()
|
|
@@ -253,6 +255,16 @@ export const useChangeThemeEffect = (
|
|
|
253
255
|
props.name,
|
|
254
256
|
props.reset,
|
|
255
257
|
])
|
|
258
|
+
|
|
259
|
+
if (process.env.NODE_ENV === 'development') {
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
globalThis['TamaguiThemeManagers'] ??= new Set()
|
|
262
|
+
globalThis['TamaguiThemeManagers'].add(themeManager)
|
|
263
|
+
return () => {
|
|
264
|
+
globalThis['TamaguiThemeManagers'].delete(themeManager)
|
|
265
|
+
}
|
|
266
|
+
}, [themeManager])
|
|
267
|
+
}
|
|
256
268
|
}
|
|
257
269
|
|
|
258
270
|
if (shouldReturnParentState) {
|
|
@@ -295,7 +307,8 @@ export const useChangeThemeEffect = (
|
|
|
295
307
|
// update if keys.length is set + onChangeTheme called
|
|
296
308
|
const forceChange = Boolean(keys?.length)
|
|
297
309
|
|
|
298
|
-
const
|
|
310
|
+
const next = themeManager.getState(props, parentManager)
|
|
311
|
+
const nextState = getShouldUpdateTheme(themeManager, next, forceChange)
|
|
299
312
|
|
|
300
313
|
if (nextState) {
|
|
301
314
|
state = nextState
|
|
@@ -305,15 +318,19 @@ export const useChangeThemeEffect = (
|
|
|
305
318
|
} else {
|
|
306
319
|
themeManager.updateState(nextState, true)
|
|
307
320
|
}
|
|
321
|
+
} else {
|
|
322
|
+
if (prev.isNewTheme) {
|
|
323
|
+
// reset to parent
|
|
324
|
+
if (parentManager && !next) {
|
|
325
|
+
themeManager = parentManager
|
|
326
|
+
}
|
|
327
|
+
}
|
|
308
328
|
}
|
|
309
329
|
} else {
|
|
310
330
|
themeManager = getNewThemeManager()
|
|
311
331
|
}
|
|
312
332
|
|
|
313
|
-
const isNewTheme = Boolean(
|
|
314
|
-
themeManager !== parentManager ||
|
|
315
|
-
(prev && themeManager.state.name !== prev.state.name)
|
|
316
|
-
)
|
|
333
|
+
const isNewTheme = Boolean(themeManager !== parentManager)
|
|
317
334
|
|
|
318
335
|
// only inverse relies on this for ssr
|
|
319
336
|
const mounted = !props.inverse ? true : root || prev?.mounted
|
|
@@ -330,8 +347,19 @@ export const useChangeThemeEffect = (
|
|
|
330
347
|
}
|
|
331
348
|
|
|
332
349
|
if (process.env.NODE_ENV === 'development' && props['debug']) {
|
|
333
|
-
console.groupCollapsed(` 🔷 useChangeThemeEffect createState`)
|
|
334
|
-
|
|
350
|
+
console.groupCollapsed(` 🔷 ${themeManager.id} useChangeThemeEffect createState`)
|
|
351
|
+
const parentState = { ...parentManager?.state }
|
|
352
|
+
const parentId = parentManager?.id
|
|
353
|
+
const themeManagerState = { ...themeManager.state }
|
|
354
|
+
console.log({
|
|
355
|
+
props,
|
|
356
|
+
parentState,
|
|
357
|
+
parentId,
|
|
358
|
+
themeManager,
|
|
359
|
+
prev,
|
|
360
|
+
response,
|
|
361
|
+
themeManagerState,
|
|
362
|
+
})
|
|
335
363
|
console.groupEnd()
|
|
336
364
|
}
|
|
337
365
|
|
package/src/views/ThemeDebug.tsx
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { useForceUpdate } from '@tamagui/use-force-update'
|
|
2
|
-
import { useEffect, useState } from 'react'
|
|
2
|
+
import { useEffect, useId, useRef, useState } from 'react'
|
|
3
|
+
import { createPortal } from 'react-dom'
|
|
3
4
|
|
|
4
5
|
import { ChangedThemeResponse } from '../hooks/useTheme.js'
|
|
5
6
|
import { ThemeProps } from '../types.js'
|
|
6
7
|
|
|
8
|
+
let node
|
|
9
|
+
|
|
7
10
|
export function ThemeDebug({
|
|
8
11
|
themeState,
|
|
9
12
|
themeProps,
|
|
@@ -16,6 +19,23 @@ export function ThemeDebug({
|
|
|
16
19
|
if (process.env.NODE_ENV === 'development') {
|
|
17
20
|
const [onChangeCount, setOnChangeCount] = useState(0)
|
|
18
21
|
const rerender = useForceUpdate()
|
|
22
|
+
const id = useId()
|
|
23
|
+
|
|
24
|
+
if (process.env.NODE_ENV === 'development' && typeof document !== 'undefined') {
|
|
25
|
+
if (!node) {
|
|
26
|
+
node = document.createElement('div')
|
|
27
|
+
node.style.width = '100%'
|
|
28
|
+
node.style.height = '200px'
|
|
29
|
+
node.style.overflowY = 'scroll'
|
|
30
|
+
node.style.position = 'fixed'
|
|
31
|
+
node.style.top = '0px'
|
|
32
|
+
node.style.left = '0px'
|
|
33
|
+
node.style.display = 'flex'
|
|
34
|
+
node.style.flexDirection = 'row'
|
|
35
|
+
node.style.background = 'var(--background)'
|
|
36
|
+
document.body.appendChild(node)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
19
39
|
|
|
20
40
|
useEffect(() => {
|
|
21
41
|
themeState.themeManager?.parentManager?.onChangeTheme((name, manager) => {
|
|
@@ -31,40 +51,41 @@ export function ThemeDebug({
|
|
|
31
51
|
}, [])
|
|
32
52
|
|
|
33
53
|
return (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
</
|
|
54
|
+
<>
|
|
55
|
+
{createPortal(
|
|
56
|
+
<code
|
|
57
|
+
style={{
|
|
58
|
+
whiteSpace: 'pre',
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
61
|
+
<Theme {id} />
|
|
62
|
+
{JSON.stringify(
|
|
63
|
+
{
|
|
64
|
+
name: themeState.name,
|
|
65
|
+
className: themeState.className,
|
|
66
|
+
inverse: themeProps.inverse,
|
|
67
|
+
forceClassName: themeProps.forceClassName,
|
|
68
|
+
parent: themeState.themeManager?.state.parentName,
|
|
69
|
+
id: themeState.themeManager?.id,
|
|
70
|
+
parentId: themeState.themeManager?.parentManager?.id,
|
|
71
|
+
isNew: themeState.isNewTheme,
|
|
72
|
+
onChangeCount,
|
|
73
|
+
listening: [...(themeState.themeManager?.['_listeningIds'] || [])].join(
|
|
74
|
+
','
|
|
75
|
+
),
|
|
76
|
+
_numChangeEventsSent: themeState.themeManager?.['_numChangeEventsSent'],
|
|
77
|
+
},
|
|
78
|
+
null,
|
|
79
|
+
2
|
|
80
|
+
)}
|
|
81
|
+
</code>,
|
|
82
|
+
node
|
|
83
|
+
)}
|
|
84
|
+
|
|
85
|
+
<div>{id}</div>
|
|
86
|
+
|
|
66
87
|
{children}
|
|
67
|
-
|
|
88
|
+
</>
|
|
68
89
|
)
|
|
69
90
|
}
|
|
70
91
|
return children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../../src/helpers/ThemeManager.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAErD,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,YAAY,EAAE,YAAY,KAAK,IAAI,CAAA;AAE9E,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,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAID,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,WAExD;AAID,qBAAa,YAAY;IAQd,KAAK,EAAE,UAAU;IAP1B,EAAE,SAAQ;IACV,WAAW,UAAQ;IACnB,cAAc,qBAA2B;IACzC,aAAa,EAAE,YAAY,GAAG,IAAI,CAAO;IACzC,KAAK,EAAE,iBAAiB,CAAa;gBAG5B,KAAK,GAAE,UAAe,EAC7B,eAAe,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;IAkC5D,WAAW,CACT,KAAK,GAAE,UAAU,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;;gBA7BrC,OAAO;kBACL,YAAY,GAAG,IAAI;UAC3B,MAAM;;QAmEb,CAAA;AAED,wBAAgB,eAAe,CAC7B,EACE,KAAK,EACL,YAAY,GACb,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG;IACjC,KAAK,EAAE,WAAW,CAAA;CACnB,EACD,IAAI,CAAC,EAAE,MAAM,EAAE,eA2ChB;AAED,eAAO,MAAM,mBAAmB,mBAA0B,CAAA;AAE1D,eAAO,MAAM,oBAAoB,UACxB,UAAU,yBAEV,MAAM,EAAE,kBACC,MAAM,OAAO,KAC5B,oBAyNF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeDebug.d.ts","sourceRoot":"","sources":["../../src/views/ThemeDebug.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ThemeDebug.d.ts","sourceRoot":"","sources":["../../src/views/ThemeDebug.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAIxC,wBAAgB,UAAU,CAAC,EACzB,UAAU,EACV,UAAU,EACV,QAAQ,GACT,EAAE;IACD,UAAU,EAAE,oBAAoB,CAAA;IAChC,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,GAAG,CAAA;CACd,OA0EA"}
|