@tamagui/web 1.45.2 → 1.45.4
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/createComponent.js +24 -22
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTamagui.js +1 -1
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/helpers/ThemeManager.js +3 -1
- package/dist/cjs/helpers/ThemeManager.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +3 -5
- package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
- package/dist/cjs/hooks/useAnimationDriver.js +0 -3
- package/dist/cjs/hooks/useAnimationDriver.js.map +1 -1
- package/dist/cjs/hooks/useStyle.js +1 -1
- package/dist/cjs/hooks/useStyle.js.map +1 -1
- package/dist/cjs/hooks/useTheme.js +6 -21
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/hooks/useThemeName.js +0 -5
- package/dist/cjs/hooks/useThemeName.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.js +1 -11
- package/dist/cjs/views/TamaguiProvider.js.map +1 -1
- package/dist/cjs/views/Theme.js +6 -5
- package/dist/cjs/views/Theme.js.map +1 -1
- package/dist/esm/createComponent.js +27 -30
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +2 -2
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.js +3 -1
- package/dist/esm/helpers/ThemeManager.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +3 -6
- package/dist/esm/helpers/getSplitStyles.js.map +1 -1
- package/dist/esm/hooks/useAnimationDriver.js +0 -3
- package/dist/esm/hooks/useAnimationDriver.js.map +1 -1
- package/dist/esm/hooks/useStyle.js +2 -2
- package/dist/esm/hooks/useStyle.js.map +1 -1
- package/dist/esm/hooks/useTheme.js +8 -23
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/hooks/useThemeName.js +1 -6
- package/dist/esm/hooks/useThemeName.js.map +1 -1
- package/dist/esm/views/TamaguiProvider.js +2 -12
- package/dist/esm/views/TamaguiProvider.js.map +1 -1
- package/dist/esm/views/Theme.js +7 -6
- package/dist/esm/views/Theme.js.map +1 -1
- package/package.json +9 -9
- package/src/createComponent.tsx +32 -34
- package/src/createTamagui.ts +3 -3
- package/src/helpers/ThemeManager.tsx +3 -1
- package/src/helpers/getSplitStyles.tsx +3 -6
- package/src/hooks/useAnimationDriver.tsx +0 -2
- package/src/hooks/useStyle.tsx +2 -2
- package/src/hooks/useTheme.tsx +13 -29
- package/src/hooks/useThemeName.tsx +1 -7
- package/src/views/TamaguiProvider.tsx +2 -13
- package/src/views/Theme.tsx +6 -4
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/hooks/useAnimationDriver.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/hooks/useThemeName.d.ts.map +1 -1
- package/types/views/TamaguiProvider.d.ts.map +1 -1
- package/types/views/Theme.d.ts +2 -1
- package/types/views/Theme.d.ts.map +1 -1
- package/src/hooks/useServerHooks.tsx +0 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isClient,
|
|
2
|
-
import { useContext, useEffect, useLayoutEffect, useMemo, useState } from "react";
|
|
1
|
+
import { isClient, isServer, isWeb } from "@tamagui/constants";
|
|
2
|
+
import { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { getConfig } from "../config";
|
|
4
4
|
import { isDevTools } from "../constants/isDevTools";
|
|
5
5
|
import { getVariable } from "../createVariable";
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from "../helpers/ThemeManager";
|
|
11
11
|
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
12
12
|
import { GetThemeUnwrapped } from "./getThemeUnwrapped";
|
|
13
|
-
import { useServerRef } from "./useServerHooks";
|
|
14
13
|
const emptyProps = { name: null };
|
|
15
14
|
function getDefaultThemeProxied() {
|
|
16
15
|
const config = getConfig();
|
|
@@ -22,10 +21,10 @@ function getDefaultThemeProxied() {
|
|
|
22
21
|
}
|
|
23
22
|
const useTheme = (props = emptyProps) => {
|
|
24
23
|
var _a;
|
|
25
|
-
return (
|
|
24
|
+
return ((_a = useThemeWithState(props)) == null ? void 0 : _a.theme) || getDefaultThemeProxied();
|
|
26
25
|
};
|
|
27
26
|
const useThemeWithState = (props) => {
|
|
28
|
-
const keys =
|
|
27
|
+
const keys = useRef([]);
|
|
29
28
|
const changedTheme = useChangeThemeEffect(
|
|
30
29
|
props,
|
|
31
30
|
false,
|
|
@@ -102,13 +101,6 @@ function getThemeProxied({
|
|
|
102
101
|
}
|
|
103
102
|
const activeThemeManagers = /* @__PURE__ */ new Set();
|
|
104
103
|
const useChangeThemeEffect = (props, root = false, keys, shouldUpdate) => {
|
|
105
|
-
if (isRSC) {
|
|
106
|
-
return {
|
|
107
|
-
isNewTheme: false,
|
|
108
|
-
...createState().state,
|
|
109
|
-
themeManager: null
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
104
|
const {
|
|
113
105
|
// @ts-expect-error internal use only
|
|
114
106
|
disable
|
|
@@ -152,15 +144,8 @@ const useChangeThemeEffect = (props, root = false, keys, shouldUpdate) => {
|
|
|
152
144
|
activeThemeManagers.add(themeManager);
|
|
153
145
|
}
|
|
154
146
|
const nextState = getShouldUpdateTheme(themeManager);
|
|
155
|
-
if (nextState) {
|
|
156
|
-
if (isNewTheme) {
|
|
157
|
-
themeManager.updateState(nextState, true);
|
|
158
|
-
}
|
|
147
|
+
if (nextState || isNewTheme) {
|
|
159
148
|
setThemeState(createState);
|
|
160
|
-
} else {
|
|
161
|
-
if (isNewTheme) {
|
|
162
|
-
setThemeState(createState);
|
|
163
|
-
}
|
|
164
149
|
}
|
|
165
150
|
const selfListenerDispose = themeManager.onChangeTheme((_a, _b, forced) => {
|
|
166
151
|
if (forced) {
|
|
@@ -171,8 +156,7 @@ const useChangeThemeEffect = (props, root = false, keys, shouldUpdate) => {
|
|
|
171
156
|
const force = shouldUpdate == null ? void 0 : shouldUpdate();
|
|
172
157
|
const doUpdate = force ?? Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
|
|
173
158
|
if (process.env.NODE_ENV === "development" && props.debug) {
|
|
174
|
-
|
|
175
|
-
console.log(` \u{1F538} onChange`, themeManager.id, logs);
|
|
159
|
+
console.log(` \u{1F538} onChange`, themeManager.id, { force, doUpdate, props, name, manager, keys });
|
|
176
160
|
}
|
|
177
161
|
if (doUpdate) {
|
|
178
162
|
setThemeState(createState);
|
|
@@ -184,13 +168,14 @@ const useChangeThemeEffect = (props, root = false, keys, shouldUpdate) => {
|
|
|
184
168
|
activeThemeManagers.delete(themeManager);
|
|
185
169
|
};
|
|
186
170
|
}, [
|
|
171
|
+
themeManager,
|
|
187
172
|
parentManager,
|
|
188
173
|
isNewTheme,
|
|
189
174
|
props.componentName,
|
|
190
175
|
props.inverse,
|
|
191
176
|
props.name,
|
|
192
177
|
props.reset,
|
|
193
|
-
|
|
178
|
+
mounted
|
|
194
179
|
]);
|
|
195
180
|
if (process.env.NODE_ENV === "development") {
|
|
196
181
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"mappings": "AACA,SAAS,UAAU,
|
|
4
|
+
"mappings": "AACA,SAAS,UAAU,UAAU,aAAa;AAC1C,SAAS,YAAY,WAAW,iBAAiB,SAAS,QAAQ,gBAAgB;AAElF,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAiBlC,MAAM,aAAa,E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;AAElD,cAAQ,IAAI;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,cAAQ,SAAS;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
5
5
|
"names": ["_", "themeManager", "state", "isNewTheme", "mounted"]
|
|
6
6
|
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
2
|
import { useContext, useState } from "react";
|
|
3
|
-
import { getConfig } from "../config";
|
|
4
3
|
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
5
4
|
function useThemeName(opts) {
|
|
6
|
-
if (isRSC) {
|
|
7
|
-
const config = getConfig();
|
|
8
|
-
return config.themes[Object.keys(config.themes)[0]];
|
|
9
|
-
}
|
|
10
5
|
const manager = useContext(ThemeManagerContext);
|
|
11
6
|
const [name, setName] = useState((manager == null ? void 0 : manager.state.name) || "");
|
|
12
7
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useThemeName.tsx"],
|
|
4
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"mappings": "AAAA,SAAS,iCAAiC;AAC1C,SAAS,YAAY,gBAAgB;AAErC,SAAS,2BAA2B;AAG7B,SAAS,aAAa,MAAqC;AAChE,QAAM,UAAU,WAAW,mBAAmB;AAC9C,QAAM,CAAC,MAAM,OAAO,IAAI,UAAS,mCAAS,MAAM,SAAQ,EAAE;AAE1D,4BAA0B,MAAM;AAC9B,QAAI,CAAC;AAAS;AACd,YAAQ,QAAQ,MAAM,IAAI;AAC1B,WAAO,QAAQ,cAAc,CAAC,MAAMA,aAAY;AAC9C,YAAMC,SAAO,6BAAM,UAASD,SAAQ,MAAM,cAAc,OAAO;AAC/D,UAAI,CAACC;AAAM;AACX,cAAQA,KAAI;AAAA,IACd,CAAC;AAAA,EACH,GAAG,CAAC,mCAAS,MAAM,IAAI,CAAC;AAExB,SAAO;AACT;",
|
|
5
5
|
"names": ["manager", "name"]
|
|
6
6
|
}
|
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { isClient,
|
|
2
|
+
import { isClient, isServer, isWeb } from "@tamagui/constants";
|
|
3
3
|
import * as React from "react";
|
|
4
|
+
import { AnimationDriverContext } from "../contexts/AnimationDriverContext";
|
|
4
5
|
import { ButtonNestingContext } from "../contexts/ButtonNestingContext";
|
|
5
6
|
import { TextAncestorContext } from "../contexts/TextAncestorContext";
|
|
6
7
|
import { useMediaListeners } from "../hooks/useMedia";
|
|
7
8
|
import { ThemeProvider } from "./ThemeProvider";
|
|
8
|
-
import { AnimationDriverContext } from "../contexts/AnimationDriverContext";
|
|
9
9
|
function TamaguiProvider({
|
|
10
10
|
children,
|
|
11
11
|
disableInjectCSS,
|
|
12
12
|
config,
|
|
13
13
|
...themePropsProvider
|
|
14
14
|
}) {
|
|
15
|
-
if (isRSC) {
|
|
16
|
-
return /* @__PURE__ */ jsx(
|
|
17
|
-
"span",
|
|
18
|
-
{
|
|
19
|
-
style: { display: "contents" },
|
|
20
|
-
className: `t_${Object.keys(config.themes)[0] || "light"}`,
|
|
21
|
-
children
|
|
22
|
-
}
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
15
|
if (!(isWeb && isServer)) {
|
|
26
16
|
useMediaListeners(config);
|
|
27
17
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/TamaguiProvider.tsx"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": "AA4CU;AA5CV,SAAS,UAAU,UAAU,aAAa;AAC1C,YAAY,WAAW;AAEvB,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;AAElC,SAAS,qBAAqB;AAEvB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAyB;AACvB,MAAI,EAAE,SAAS,WAAW;AACxB,sBAAkB,MAAM;AAAA,EAC1B;AAEA,MAAI,UAAU;AAGZ,UAAM,gBAAgB,MAAM;AAG1B,UAAI,SAAS,gBAAgB,UAAU,SAAS,aAAa,GAAG;AAC9D,iBAAS,gBAAgB,UAAU,OAAO,aAAa;AAAA,MACzD;AAEA,UAAI;AAAkB;AACtB,YAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,YAAM,YAAY,SAAS,eAAe,OAAO,OAAO,CAAC,CAAC;AAC1D,eAAS,KAAK,YAAY,KAAK;AAC/B,aAAO,MAAM;AACX,iBAAS,KAAK,YAAY,KAAK;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,QAAQ,gBAAgB,CAAC;AAAA,EAC/B;AAEA,SACE,oBAAC,qBAAqB,UAArB,EAA8B,OAAO,OACpC,8BAAC,oBAAoB,UAApB,EAA6B,OAAO,OACnC,8BAAC,uBAAuB,UAAvB,EAAgC,OAAO,OAAO,YAC7C;AAAA,IAAC;AAAA;AAAA,MACC,sBAAsB,OAAO;AAAA,MAC7B,uBAAuB,OAAO;AAAA,MAC7B,GAAG;AAAA,MACJ,cACE,mBAAmB,gBAAgB,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;AAAA,MAGhE;AAAA;AAAA,EACH,GACF,GACF,GACF;AAEJ;",
|
|
5
5
|
"names": []
|
|
6
6
|
}
|
package/dist/esm/views/Theme.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { isWeb } from "@tamagui/constants";
|
|
3
|
-
import React, { Children, cloneElement, forwardRef, isValidElement } from "react";
|
|
3
|
+
import React, { Children, cloneElement, forwardRef, isValidElement, useRef } from "react";
|
|
4
4
|
import { variableToString } from "../createVariable";
|
|
5
5
|
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
6
|
-
import { useServerRef } from "../hooks/useServerHooks";
|
|
7
6
|
import { useChangeThemeEffect } from "../hooks/useTheme";
|
|
8
7
|
import { ThemeDebug } from "./ThemeDebug";
|
|
9
8
|
const Theme = forwardRef((props, ref) => {
|
|
@@ -34,7 +33,7 @@ Theme["avoidForwardRef"] = true;
|
|
|
34
33
|
function useThemedChildren(themeState, children, props, isRoot = false) {
|
|
35
34
|
const { themeManager, isNewTheme } = themeState;
|
|
36
35
|
const { shallow, forceClassName } = props;
|
|
37
|
-
const hasEverThemed =
|
|
36
|
+
const hasEverThemed = useRef(false);
|
|
38
37
|
if (isNewTheme) {
|
|
39
38
|
hasEverThemed.current = true;
|
|
40
39
|
}
|
|
@@ -59,17 +58,19 @@ function useThemedChildren(themeState, children, props, isRoot = false) {
|
|
|
59
58
|
if (isWeb && !props.passPropsToChildren) {
|
|
60
59
|
return wrapThemeElements({
|
|
61
60
|
children: elementsWithContext,
|
|
62
|
-
themeState
|
|
61
|
+
themeState,
|
|
62
|
+
forceClassName
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
return elementsWithContext;
|
|
66
66
|
}
|
|
67
67
|
function wrapThemeElements({
|
|
68
68
|
children,
|
|
69
|
-
themeState
|
|
69
|
+
themeState,
|
|
70
|
+
forceClassName
|
|
70
71
|
}) {
|
|
71
72
|
var _a, _b, _c;
|
|
72
|
-
if (!themeState.isNewTheme) {
|
|
73
|
+
if (!themeState.isNewTheme && !forceClassName) {
|
|
73
74
|
return /* @__PURE__ */ jsx("span", { className: "_dsp_contents is_Theme", children });
|
|
74
75
|
}
|
|
75
76
|
const themeColor = themeState.theme && themeState.isNewTheme ? variableToString(themeState.theme.color) : "";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/Theme.tsx"],
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1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.45.
|
|
3
|
+
"version": "1.45.4",
|
|
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.45.
|
|
31
|
-
"@tamagui/constants": "1.45.
|
|
32
|
-
"@tamagui/helpers": "1.45.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.45.
|
|
34
|
-
"@tamagui/use-did-finish-ssr": "1.45.
|
|
35
|
-
"@tamagui/use-event": "1.45.
|
|
36
|
-
"@tamagui/use-force-update": "1.45.
|
|
30
|
+
"@tamagui/compose-refs": "1.45.4",
|
|
31
|
+
"@tamagui/constants": "1.45.4",
|
|
32
|
+
"@tamagui/helpers": "1.45.4",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.45.4",
|
|
34
|
+
"@tamagui/use-did-finish-ssr": "1.45.4",
|
|
35
|
+
"@tamagui/use-event": "1.45.4",
|
|
36
|
+
"@tamagui/use-force-update": "1.45.4"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.45.
|
|
42
|
+
"@tamagui/build": "1.45.4",
|
|
43
43
|
"@testing-library/react": "^13.4.0",
|
|
44
44
|
"csstype": "^3.0.10",
|
|
45
45
|
"react": "^18.2.0",
|
package/src/createComponent.tsx
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
2
|
-
import {
|
|
3
|
-
isClient,
|
|
4
|
-
isRSC,
|
|
5
|
-
isServer,
|
|
6
|
-
isWeb,
|
|
7
|
-
useIsomorphicLayoutEffect,
|
|
8
|
-
} from '@tamagui/constants'
|
|
2
|
+
import { isClient, isServer, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
9
3
|
import { validStyles } from '@tamagui/helpers'
|
|
10
4
|
import React, {
|
|
11
5
|
Children,
|
|
@@ -16,8 +10,8 @@ import React, {
|
|
|
16
10
|
useCallback,
|
|
17
11
|
useContext,
|
|
18
12
|
useId,
|
|
19
|
-
useMemo,
|
|
20
13
|
useRef,
|
|
14
|
+
useState,
|
|
21
15
|
} from 'react'
|
|
22
16
|
|
|
23
17
|
import { getConfig, onConfiguredOnce } from './config'
|
|
@@ -33,7 +27,6 @@ import { themeable } from './helpers/themeable'
|
|
|
33
27
|
import { useShallowSetState } from './helpers/useShallowSetState'
|
|
34
28
|
import { useAnimationDriver } from './hooks/useAnimationDriver'
|
|
35
29
|
import { setMediaShouldUpdate, useMedia } from './hooks/useMedia'
|
|
36
|
-
import { useServerRef, useServerState } from './hooks/useServerHooks'
|
|
37
30
|
import { useThemeWithState } from './hooks/useTheme'
|
|
38
31
|
import { hooks } from './setupHooks'
|
|
39
32
|
import {
|
|
@@ -253,7 +246,7 @@ export function createComponent<
|
|
|
253
246
|
)
|
|
254
247
|
stateRef.current ||= {}
|
|
255
248
|
|
|
256
|
-
const hostRef =
|
|
249
|
+
const hostRef = useRef<TamaguiElement>(null)
|
|
257
250
|
|
|
258
251
|
/**
|
|
259
252
|
* Component state for tracking animations, pseudos
|
|
@@ -277,7 +270,7 @@ export function createComponent<
|
|
|
277
270
|
})()
|
|
278
271
|
|
|
279
272
|
const usePresence = animationsConfig?.usePresence
|
|
280
|
-
const presence = (
|
|
273
|
+
const presence = (willBeAnimated && usePresence?.()) || null
|
|
281
274
|
|
|
282
275
|
const hasEnterStyle = !!props.enterStyle
|
|
283
276
|
|
|
@@ -293,7 +286,7 @@ export function createComponent<
|
|
|
293
286
|
? defaultComponentStateShouldEnter!
|
|
294
287
|
: defaultComponentState!
|
|
295
288
|
: defaultComponentStateMounted!
|
|
296
|
-
const states =
|
|
289
|
+
const states = useState<TamaguiComponentState>(initialState)
|
|
297
290
|
|
|
298
291
|
const state = propsIn.forceStyle
|
|
299
292
|
? { ...states[0], [propsIn.forceStyle]: true }
|
|
@@ -327,7 +320,7 @@ export function createComponent<
|
|
|
327
320
|
? `is_${props.componentName}`
|
|
328
321
|
: defaultComponentClassName
|
|
329
322
|
const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)
|
|
330
|
-
const languageContext =
|
|
323
|
+
const languageContext = useContext(FontLanguageContext)
|
|
331
324
|
const isDisabled = props.disabled ?? props.accessibilityState?.disabled
|
|
332
325
|
|
|
333
326
|
const isTaggable = !Component || typeof Component === 'string'
|
|
@@ -439,6 +432,9 @@ export function createComponent<
|
|
|
439
432
|
? 'value'
|
|
440
433
|
: 'auto'
|
|
441
434
|
|
|
435
|
+
// temp: once we fix above we can disable this
|
|
436
|
+
const keepStyleSSR = willBeAnimated && animationsConfig?.keepStyleSSR
|
|
437
|
+
|
|
442
438
|
const splitStyles = useSplitStyles(
|
|
443
439
|
props,
|
|
444
440
|
staticConfig,
|
|
@@ -451,8 +447,7 @@ export function createComponent<
|
|
|
451
447
|
resolveVariablesAs,
|
|
452
448
|
isExiting,
|
|
453
449
|
isAnimated,
|
|
454
|
-
|
|
455
|
-
keepStyleSSR: willBeAnimated && animationsConfig?.keepStyleSSR,
|
|
450
|
+
keepStyleSSR,
|
|
456
451
|
},
|
|
457
452
|
null,
|
|
458
453
|
languageContext || undefined,
|
|
@@ -522,7 +517,7 @@ export function createComponent<
|
|
|
522
517
|
// once you set animation prop don't remove it, you can set to undefined/false
|
|
523
518
|
// reason is animations are heavy - no way around it, and must be run inline here (🙅 loading as a sub-component)
|
|
524
519
|
let animationStyles: any
|
|
525
|
-
if (
|
|
520
|
+
if (willBeAnimated && useAnimations && !isHOC) {
|
|
526
521
|
const animations = useAnimations({
|
|
527
522
|
props: propsWithAnimation,
|
|
528
523
|
// if hydrating, send empty style
|
|
@@ -636,21 +631,24 @@ export function createComponent<
|
|
|
636
631
|
})
|
|
637
632
|
}, [shouldSetMounted, state.unmounted])
|
|
638
633
|
|
|
639
|
-
let styles: Record<string, any>[]
|
|
634
|
+
let styles: Record<string, any>[] | undefined
|
|
635
|
+
const avoidStyle = keepStyleSSR && state.unmounted === true
|
|
640
636
|
|
|
641
|
-
if (
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
637
|
+
if (!avoidStyle) {
|
|
638
|
+
if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {
|
|
639
|
+
styles = {
|
|
640
|
+
...(animationStyles ?? splitStylesStyle),
|
|
641
|
+
}
|
|
642
|
+
} else {
|
|
643
|
+
styles = [animationStyles ?? splitStylesStyle]
|
|
644
|
+
|
|
645
|
+
// ugly but for now...
|
|
646
|
+
if (shouldForcePseudo) {
|
|
647
|
+
const next = {}
|
|
648
|
+
styles.forEach((style) => Object.assign(next, style))
|
|
649
|
+
// @ts-ignore
|
|
650
|
+
Object.assign(splitStyles.style, next)
|
|
651
|
+
}
|
|
654
652
|
}
|
|
655
653
|
}
|
|
656
654
|
|
|
@@ -674,9 +672,9 @@ export function createComponent<
|
|
|
674
672
|
const className = classList.join(' ')
|
|
675
673
|
|
|
676
674
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
677
|
-
const style = animationStyles ?? splitStyles.style
|
|
675
|
+
const style = avoidStyle ? null : animationStyles ?? splitStyles.style
|
|
678
676
|
|
|
679
|
-
if (isAnimatedReactNativeWeb) {
|
|
677
|
+
if (isAnimatedReactNativeWeb && !avoidStyle) {
|
|
680
678
|
viewProps.style = style
|
|
681
679
|
} else if (isReactNative) {
|
|
682
680
|
// TODO these shouldn't really return from getSplitStyles when in Native mode
|
|
@@ -705,7 +703,7 @@ export function createComponent<
|
|
|
705
703
|
// TODO MOVE INTO HOOK
|
|
706
704
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
707
705
|
// swap out the right family based on weight/style
|
|
708
|
-
if (splitStyles.fontFamily) {
|
|
706
|
+
if (styles && splitStyles.fontFamily) {
|
|
709
707
|
const faceInfo = tamaguiConfig.fontsParsed[splitStyles.fontFamily]?.face
|
|
710
708
|
if (faceInfo) {
|
|
711
709
|
const [weight, style] = (() => {
|
|
@@ -755,7 +753,7 @@ export function createComponent<
|
|
|
755
753
|
)
|
|
756
754
|
|
|
757
755
|
const events: TamaguiComponentEvents | null =
|
|
758
|
-
shouldAttach && !
|
|
756
|
+
shouldAttach && !isDisabled && !asChild
|
|
759
757
|
? {
|
|
760
758
|
onPressOut: attachPress
|
|
761
759
|
? (e) => {
|
package/src/createTamagui.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isWeb } from '@tamagui/constants'
|
|
2
2
|
|
|
3
3
|
import { configListeners, setConfig } from './config'
|
|
4
|
-
import { Variable
|
|
4
|
+
import { Variable } from './createVariable'
|
|
5
5
|
import { createVariables } from './createVariables'
|
|
6
6
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
7
7
|
import {
|
|
@@ -203,7 +203,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
203
203
|
// then, generate CSS from de-duped
|
|
204
204
|
let themeRuleSets: string[] = []
|
|
205
205
|
|
|
206
|
-
if (isWeb
|
|
206
|
+
if (isWeb) {
|
|
207
207
|
for (const themeName in dedupedThemes) {
|
|
208
208
|
const nextRules = getThemeCSSRules({
|
|
209
209
|
config: configIn,
|
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
currentPlatform,
|
|
3
3
|
isAndroid,
|
|
4
4
|
isClient,
|
|
5
|
-
isRSC,
|
|
6
5
|
isServer,
|
|
7
6
|
isWeb,
|
|
8
7
|
useIsomorphicLayoutEffect,
|
|
@@ -1226,11 +1225,9 @@ const useInsertEffectCompat = isWeb
|
|
|
1226
1225
|
export const useSplitStyles: StyleSplitter = (...args) => {
|
|
1227
1226
|
const res = getSplitStyles(...args)
|
|
1228
1227
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
}, [res.rulesToInsert])
|
|
1233
|
-
}
|
|
1228
|
+
useInsertEffectCompat(() => {
|
|
1229
|
+
insertStyleRules(res.rulesToInsert)
|
|
1230
|
+
}, [res.rulesToInsert])
|
|
1234
1231
|
|
|
1235
1232
|
return res
|
|
1236
1233
|
}
|
|
@@ -2,9 +2,7 @@ import { useContext } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import { AnimationDriverContext } from '../contexts/AnimationDriverContext'
|
|
4
4
|
import { getAnimationDriver } from '../helpers/getAnimationDriver'
|
|
5
|
-
import { isRSC } from '@tamagui/constants'
|
|
6
5
|
|
|
7
6
|
export const useAnimationDriver = () => {
|
|
8
|
-
if (isRSC) return getAnimationDriver()
|
|
9
7
|
return useContext(AnimationDriverContext) ?? getAnimationDriver()
|
|
10
8
|
}
|
package/src/hooks/useStyle.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isWeb } from '@tamagui/constants'
|
|
2
2
|
import { useContext } from 'react'
|
|
3
3
|
|
|
4
4
|
import { FontLanguageContext } from '../contexts/FontLanguageContext'
|
|
@@ -24,7 +24,7 @@ export function useStyle<
|
|
|
24
24
|
) {
|
|
25
25
|
const isText = base.staticConfig.isText
|
|
26
26
|
const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)
|
|
27
|
-
const languageContext =
|
|
27
|
+
const languageContext = useContext(FontLanguageContext)
|
|
28
28
|
const themeState = useThemeWithState({})
|
|
29
29
|
const media = useMedia()
|
|
30
30
|
const out = useSplitStyles(
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
import { isClient,
|
|
3
|
-
import { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'
|
|
2
|
+
import { isClient, isServer, isWeb } from '@tamagui/constants'
|
|
3
|
+
import { useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
|
4
4
|
|
|
5
5
|
import { getConfig } from '../config'
|
|
6
6
|
import { isDevTools } from '../constants/isDevTools'
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
import { ThemeManagerContext } from '../helpers/ThemeManagerContext'
|
|
15
15
|
import type { ThemeParsed, ThemeProps } from '../types'
|
|
16
16
|
import { GetThemeUnwrapped } from './getThemeUnwrapped'
|
|
17
|
-
import { useServerRef } from './useServerHooks'
|
|
18
17
|
|
|
19
18
|
export type ChangedThemeResponse = {
|
|
20
19
|
isNewTheme: boolean
|
|
@@ -49,11 +48,11 @@ type UseThemeResult = {
|
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
export const useTheme = (props: ThemeProps = emptyProps): UseThemeResult => {
|
|
52
|
-
return
|
|
51
|
+
return useThemeWithState(props)?.theme || getDefaultThemeProxied()
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
export const useThemeWithState = (props: ThemeProps) => {
|
|
56
|
-
const keys =
|
|
55
|
+
const keys = useRef<string[]>([])
|
|
57
56
|
|
|
58
57
|
const changedTheme = useChangeThemeEffect(
|
|
59
58
|
props,
|
|
@@ -158,15 +157,6 @@ export const useChangeThemeEffect = (
|
|
|
158
157
|
keys?: string[],
|
|
159
158
|
shouldUpdate?: () => boolean | undefined
|
|
160
159
|
): ChangedThemeResponse => {
|
|
161
|
-
if (isRSC) {
|
|
162
|
-
// we need context working for this to work well
|
|
163
|
-
return {
|
|
164
|
-
isNewTheme: false,
|
|
165
|
-
...createState().state,
|
|
166
|
-
themeManager: null,
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
160
|
const {
|
|
171
161
|
// @ts-expect-error internal use only
|
|
172
162
|
disable,
|
|
@@ -186,7 +176,6 @@ export const useChangeThemeEffect = (
|
|
|
186
176
|
|
|
187
177
|
const [themeState, setThemeState] = useState<State>(createState)
|
|
188
178
|
const { state, mounted, isNewTheme, themeManager } = themeState
|
|
189
|
-
|
|
190
179
|
const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)
|
|
191
180
|
|
|
192
181
|
function getShouldUpdateTheme(
|
|
@@ -223,19 +212,13 @@ export const useChangeThemeEffect = (
|
|
|
223
212
|
|
|
224
213
|
const nextState = getShouldUpdateTheme(themeManager)
|
|
225
214
|
|
|
226
|
-
if (nextState) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
215
|
+
// if (nextState && isNewTheme) {
|
|
216
|
+
// // if it's a new theme we can just update + publish to children
|
|
217
|
+
// themeManager.updateState(nextState, true)
|
|
218
|
+
// }
|
|
231
219
|
|
|
232
|
-
|
|
220
|
+
if (nextState || isNewTheme) {
|
|
233
221
|
setThemeState(createState)
|
|
234
|
-
} else {
|
|
235
|
-
if (isNewTheme) {
|
|
236
|
-
// need to revert to parent
|
|
237
|
-
setThemeState(createState)
|
|
238
|
-
}
|
|
239
222
|
}
|
|
240
223
|
|
|
241
224
|
// for updateTheme/replaceTheme
|
|
@@ -249,9 +232,9 @@ export const useChangeThemeEffect = (
|
|
|
249
232
|
const force = shouldUpdate?.()
|
|
250
233
|
const doUpdate = force ?? Boolean(keys?.length || isNewTheme)
|
|
251
234
|
if (process.env.NODE_ENV === 'development' && props.debug) {
|
|
252
|
-
|
|
235
|
+
// prettier-ignore
|
|
253
236
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
254
|
-
console.log(` 🔸 onChange`, themeManager.id,
|
|
237
|
+
console.log(` 🔸 onChange`, themeManager.id, { force, doUpdate, props, name, manager, keys })
|
|
255
238
|
}
|
|
256
239
|
if (doUpdate) {
|
|
257
240
|
setThemeState(createState)
|
|
@@ -264,13 +247,14 @@ export const useChangeThemeEffect = (
|
|
|
264
247
|
activeThemeManagers.delete(themeManager)
|
|
265
248
|
}
|
|
266
249
|
}, [
|
|
250
|
+
themeManager,
|
|
267
251
|
parentManager,
|
|
268
252
|
isNewTheme,
|
|
269
253
|
props.componentName,
|
|
270
254
|
props.inverse,
|
|
271
255
|
props.name,
|
|
272
256
|
props.reset,
|
|
273
|
-
|
|
257
|
+
mounted,
|
|
274
258
|
])
|
|
275
259
|
|
|
276
260
|
if (process.env.NODE_ENV === 'development') {
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
2
2
|
import { useContext, useState } from 'react'
|
|
3
3
|
|
|
4
|
-
import { getConfig } from '../config'
|
|
5
4
|
import { ThemeManagerContext } from '../helpers/ThemeManagerContext'
|
|
6
5
|
import { ThemeName } from '../types'
|
|
7
6
|
|
|
8
7
|
export function useThemeName(opts?: { parent?: true }): ThemeName {
|
|
9
|
-
if (isRSC) {
|
|
10
|
-
const config = getConfig()
|
|
11
|
-
return config.themes[Object.keys(config.themes)[0]] as any
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
const manager = useContext(ThemeManagerContext)
|
|
15
9
|
const [name, setName] = useState(manager?.state.name || '')
|
|
16
10
|
|