@tamagui/core 1.0.0-alpha.2 → 1.0.0-alpha.7

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.
Files changed (145) hide show
  1. package/dist/createComponent.js +43 -29
  2. package/dist/createComponent.js.map +2 -2
  3. package/dist/createFont.js +4 -0
  4. package/dist/createFont.js.map +2 -2
  5. package/dist/createTamagui.js +7 -0
  6. package/dist/createTamagui.js.map +2 -2
  7. package/dist/createTokens.js +4 -0
  8. package/dist/createTokens.js.map +2 -2
  9. package/dist/createVariable.js +3 -0
  10. package/dist/createVariable.js.map +2 -2
  11. package/dist/helpers/getSplitStyles.js +1 -13
  12. package/dist/helpers/getSplitStyles.js.map +2 -2
  13. package/dist/helpers/isComponent.js +10 -0
  14. package/dist/helpers/isComponent.js.map +7 -0
  15. package/dist/helpers/isTamaguiComponent.js +10 -0
  16. package/dist/helpers/isTamaguiComponent.js.map +7 -0
  17. package/dist/helpers/isTamaguiElement.js +10 -0
  18. package/dist/helpers/isTamaguiElement.js.map +7 -0
  19. package/dist/helpers/validate.js +60 -0
  20. package/dist/helpers/validate.js.map +7 -0
  21. package/dist/helpers/validateConfig.js +46 -0
  22. package/dist/helpers/validateConfig.js.map +7 -0
  23. package/dist/helpers/validateTokens.js +29 -0
  24. package/dist/helpers/validateTokens.js.map +7 -0
  25. package/dist/hooks/useMedia.js +1 -1
  26. package/dist/hooks/useMedia.js.map +2 -2
  27. package/dist/hooks/useTheme.js +1 -1
  28. package/dist/hooks/useTheme.js.map +2 -2
  29. package/dist/index.cjs +223 -137
  30. package/dist/index.cjs.map +3 -3
  31. package/dist/index.js +1 -2
  32. package/dist/index.js.map +2 -2
  33. package/dist/views/Theme.js +16 -7
  34. package/dist/views/Theme.js.map +2 -2
  35. package/dist/views/ThemeInverse.js +0 -1
  36. package/dist/views/ThemeInverse.js.map +2 -2
  37. package/dist/views/ThemeManagerContext.js +7 -1
  38. package/dist/views/ThemeManagerContext.js.map +2 -2
  39. package/package.json +12 -5
  40. package/src/createComponent.tsx +49 -38
  41. package/src/createFont.ts +5 -0
  42. package/src/createTamagui.ts +8 -0
  43. package/src/createTokens.ts +6 -1
  44. package/src/createVariable.ts +4 -0
  45. package/src/helpers/getSplitStyles.tsx +3 -16
  46. package/src/helpers/isTamaguiElement.tsx +5 -0
  47. package/src/helpers/validate.ts +59 -0
  48. package/src/hooks/useMedia.tsx +1 -1
  49. package/src/hooks/useTheme.tsx +1 -1
  50. package/src/index.ts +1 -2
  51. package/src/types.tsx +1 -0
  52. package/src/views/Theme.tsx +26 -9
  53. package/src/views/ThemeInverse.tsx +0 -1
  54. package/src/views/ThemeManagerContext.tsx +11 -1
  55. package/types.d.ts +3 -5
  56. package/.ultra.cache.json +0 -1
  57. package/_/constants/constants.js +0 -14
  58. package/_/constants/constants.js.map +0 -7
  59. package/_/constants/platform.js +0 -20
  60. package/_/constants/platform.js.map +0 -7
  61. package/_/constants/pseudos.js +0 -18
  62. package/_/constants/pseudos.js.map +0 -7
  63. package/_/constants/rnw.js +0 -22
  64. package/_/constants/rnw.js.map +0 -7
  65. package/_/createComponent.js +0 -427
  66. package/_/createComponent.js.map +0 -7
  67. package/_/createShorthands.js +0 -10
  68. package/_/createShorthands.js.map +0 -7
  69. package/_/createTamagui.js +0 -122
  70. package/_/createTamagui.js.map +0 -7
  71. package/_/createTheme.js +0 -20
  72. package/_/createTheme.js.map +0 -7
  73. package/_/createTokens.js +0 -29
  74. package/_/createTokens.js.map +0 -7
  75. package/_/createVariable.js +0 -22
  76. package/_/createVariable.js.map +0 -7
  77. package/_/helpers/addStylesUsingClassname.js +0 -32
  78. package/_/helpers/addStylesUsingClassname.js.map +0 -7
  79. package/_/helpers/createMediaStyle.js +0 -34
  80. package/_/helpers/createMediaStyle.js.map +0 -7
  81. package/_/helpers/createTamaguiProvider.js +0 -42
  82. package/_/helpers/createTamaguiProvider.js.map +0 -7
  83. package/_/helpers/extendStaticConfig.js +0 -176
  84. package/_/helpers/extendStaticConfig.js.map +0 -7
  85. package/_/helpers/fixNativeShadow.js +0 -8
  86. package/_/helpers/fixNativeShadow.js.map +0 -7
  87. package/_/helpers/fixNativeShadow.native.js +0 -30
  88. package/_/helpers/fixNativeShadow.native.js.map +0 -7
  89. package/_/helpers/getSplitStyles.js +0 -160
  90. package/_/helpers/getSplitStyles.js.map +0 -7
  91. package/_/helpers/getStylesAtomic.js +0 -84
  92. package/_/helpers/getStylesAtomic.js.map +0 -7
  93. package/_/helpers/getStylesAtomic.native.js +0 -10
  94. package/_/helpers/getStylesAtomic.native.js.map +0 -7
  95. package/_/helpers/insertStyleRule.js +0 -24
  96. package/_/helpers/insertStyleRule.js.map +0 -7
  97. package/_/helpers/matchMedia.js +0 -15
  98. package/_/helpers/matchMedia.js.map +0 -7
  99. package/_/helpers/matchMedia.native.js +0 -8
  100. package/_/helpers/matchMedia.native.js.map +0 -7
  101. package/_/helpers/themeable.js +0 -26
  102. package/_/helpers/themeable.js.map +0 -7
  103. package/_/hooks/useConstant.js +0 -15
  104. package/_/hooks/useConstant.js.map +0 -7
  105. package/_/hooks/useFeatures.js +0 -75
  106. package/_/hooks/useFeatures.js.map +0 -7
  107. package/_/hooks/useForceUpdate.js +0 -28
  108. package/_/hooks/useForceUpdate.js.map +0 -7
  109. package/_/hooks/useMedia.js +0 -173
  110. package/_/hooks/useMedia.js.map +0 -7
  111. package/_/hooks/usePressable.js +0 -14
  112. package/_/hooks/usePressable.js.map +0 -7
  113. package/_/hooks/useTheme.js +0 -94
  114. package/_/hooks/useTheme.js.map +0 -7
  115. package/_/index.js +0 -30
  116. package/_/index.js.map +0 -7
  117. package/_/static/postProcessStyles.js +0 -18
  118. package/_/static/postProcessStyles.js.map +0 -7
  119. package/_/static.js +0 -12
  120. package/_/static.js.map +0 -7
  121. package/_/styled.js +0 -21
  122. package/_/styled.js.map +0 -7
  123. package/_/types.js +0 -1
  124. package/_/types.js.map +0 -7
  125. package/_/views/Animated.js +0 -79
  126. package/_/views/Animated.js.map +0 -7
  127. package/_/views/Stack.js +0 -12
  128. package/_/views/Stack.js.map +0 -7
  129. package/_/views/Text.js +0 -60
  130. package/_/views/Text.js.map +0 -7
  131. package/_/views/TextAncestorContext.js +0 -19
  132. package/_/views/TextAncestorContext.js.map +0 -7
  133. package/_/views/Theme.js +0 -57
  134. package/_/views/Theme.js.map +0 -7
  135. package/_/views/ThemeContext.js +0 -6
  136. package/_/views/ThemeContext.js.map +0 -7
  137. package/_/views/ThemeInverse.js +0 -27
  138. package/_/views/ThemeInverse.js.map +0 -7
  139. package/_/views/ThemeManagerContext.js +0 -56
  140. package/_/views/ThemeManagerContext.js.map +0 -7
  141. package/_/views/ThemeProvider.js +0 -45
  142. package/_/views/ThemeProvider.js.map +0 -7
  143. package/src/hooks/useForceUpdate.tsx +0 -26
  144. package/src/views/SafeAreaProvider.tsx +0 -33
  145. package/tsconfig.json +0 -8
package/dist/index.js CHANGED
@@ -15,8 +15,8 @@ export * from "./helpers/isObj";
15
15
  export * from "./helpers/getStylesAtomic";
16
16
  export * from "./helpers/matchMedia";
17
17
  export * from "./helpers/themeable";
18
+ export * from "./helpers/isTamaguiElement";
18
19
  export * from "./hooks/useConstant";
19
- export * from "./hooks/useForceUpdate";
20
20
  export * from "./hooks/useMedia";
21
21
  export * from "./hooks/useTheme";
22
22
  export * from "./views/Animated";
@@ -26,7 +26,6 @@ export * from "./views/Theme";
26
26
  export * from "./views/ThemeInverse";
27
27
  export * from "./views/ThemeProvider";
28
28
  export * from "./views/TextAncestorContext";
29
- export * from "./views/SafeAreaProvider";
30
29
  export {
31
30
  createTokens
32
31
  };
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport { createTokens } from './createTokens'\nexport * from './createVariable'\nexport * from './styled'\nexport * from './types'\n\nexport * from './constants/pseudos'\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport * from './constants/rnw'\n\nexport * from './helpers/isObj'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useForceUpdate'\nexport * from './hooks/useMedia'\nexport * from './hooks/useTheme'\n\nexport * from './views/Animated'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/TextAncestorContext'\nexport * from './views/SafeAreaProvider'\n"],
5
- "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport { createTokens } from './createTokens'\nexport * from './createVariable'\nexport * from './styled'\nexport * from './types'\n\nexport * from './constants/pseudos'\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport * from './constants/rnw'\n\nexport * from './helpers/isObj'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/isTamaguiElement'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useMedia'\nexport * from './hooks/useTheme'\n\nexport * from './views/Animated'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/TextAncestorContext'\n"],
5
+ "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;",
6
6
  "names": []
7
7
  }
@@ -11,28 +11,37 @@ const Theme = /* @__PURE__ */ __name((props) => {
11
11
  const themes = useContext(ThemeContext);
12
12
  const [parentName, setParentName] = useState(parent.name || "light");
13
13
  if (!themes) {
14
- console.warn("no themes???", props);
14
+ console.warn("Error, no themes in context", props);
15
15
  return props.children;
16
16
  }
17
17
  const name = props.name;
18
- const theme = themes[name] || themes[`${name}-${parentName}`];
18
+ const nextNameParent = `${name}-${parentName}`;
19
+ const nextNameParentParent = `${name}-${parent.parentName}`;
20
+ const activeName = !name ? null : name in themes ? name : nextNameParent in themes ? nextNameParent : nextNameParentParent in themes ? nextNameParentParent : null;
21
+ const theme = activeName ? themes[activeName] : null;
19
22
  const themeManager = useConstant(() => {
23
+ if (!theme) {
24
+ return null;
25
+ }
20
26
  const manager = new ThemeManager();
21
27
  if (name) {
22
- manager.setActiveTheme(name, themes[name]);
28
+ manager.setActiveTheme({ name, theme: themes[name], parentName });
23
29
  }
24
30
  return manager;
25
31
  });
26
32
  useIsomorphicLayoutEffect(() => {
27
- themeManager.setActiveTheme(name, theme);
33
+ if (!themeManager) {
34
+ return;
35
+ }
36
+ themeManager.setActiveTheme({ name: activeName, theme, parentName });
28
37
  return parent.onChangeTheme((next) => {
29
38
  if (next) {
30
- themeManager.setActiveTheme(next, themes[next]);
39
+ themeManager.setActiveTheme({ name: next, theme: themes[next], parentName });
31
40
  setParentName(next);
32
41
  }
33
42
  });
34
- }, [themes, name]);
35
- if (!name) {
43
+ }, [themes, activeName, parentName]);
44
+ if (!name || !theme) {
36
45
  return props.children;
37
46
  }
38
47
  const contents = themeManager ? /* @__PURE__ */ React.createElement(ThemeManagerContext.Provider, {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/views/Theme.tsx"],
4
- "sourcesContent": ["import React, { useContext, useState } from 'react'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { getThemeParentClassName } from '../createTamagui'\nimport { useConstant } from '../hooks/useConstant'\nimport { ThemeName, Themes } from '../types'\nimport { ThemeContext } from './ThemeContext'\nimport { ThemeManager, ThemeManagerContext } from './ThemeManagerContext'\n\nexport type ThemeProps = {\n disableThemeClass?: boolean\n name: ThemeName | null\n children?: any\n}\n\nexport const Theme = (props: ThemeProps) => {\n const parent = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext)\n const [parentName, setParentName] = useState(parent.name || 'light')\n if (!themes) {\n console.warn('no themes???', props)\n return props.children\n }\n const name = props.name as string\n const theme = themes[name] || themes[`${name}-${parentName}`]\n const themeManager = useConstant<ThemeManager>(() => {\n const manager = new ThemeManager()\n if (name) {\n manager.setActiveTheme(name, themes[name])\n }\n return manager\n })\n\n useIsomorphicLayoutEffect(() => {\n themeManager.setActiveTheme(name, theme)\n return parent.onChangeTheme((next) => {\n if (next) {\n themeManager.setActiveTheme(next, themes[next])\n setParentName(next)\n }\n })\n }, [themes, name])\n\n if (!name) {\n return props.children\n }\n\n const contents = themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {props.children}\n </ThemeManagerContext.Provider>\n ) : (\n props.children\n )\n\n if (isWeb) {\n if (props.disableThemeClass) {\n return contents\n }\n const color = themes[name]?.['color']?.['variable']\n return (\n <div\n className={getThemeParentClassName(name)}\n // in order to provide currentColor, set color by default\n style={{ display: 'contents', color }}\n >\n {contents}\n </div>\n )\n }\n\n return contents\n}\n"],
5
- "mappings": ";;AAAA;AAEA;AACA;AACA;AAEA;AACA;AAQO,MAAM,QAAQ,wBAAC,UAAsB;AAC1C,QAAM,SAAS,WAAW;AAC1B,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,YAAY,iBAAiB,SAAS,OAAO,QAAQ;AAC5D,MAAI,CAAC,QAAQ;AACX,YAAQ,KAAK,gBAAgB;AAC7B,WAAO,MAAM;AAAA;AAEf,QAAM,OAAO,MAAM;AACnB,QAAM,QAAQ,OAAO,SAAS,OAAO,GAAG,QAAQ;AAChD,QAAM,eAAe,YAA0B,MAAM;AACnD,UAAM,UAAU,IAAI;AACpB,QAAI,MAAM;AACR,cAAQ,eAAe,MAAM,OAAO;AAAA;AAEtC,WAAO;AAAA;AAGT,4BAA0B,MAAM;AAC9B,iBAAa,eAAe,MAAM;AAClC,WAAO,OAAO,cAAc,CAAC,SAAS;AACpC,UAAI,MAAM;AACR,qBAAa,eAAe,MAAM,OAAO;AACzC,sBAAc;AAAA;AAAA;AAAA,KAGjB,CAAC,QAAQ;AAEZ,MAAI,CAAC,MAAM;AACT,WAAO,MAAM;AAAA;AAGf,QAAM,WAAW,eACf,oCAAC,oBAAoB,UAArB;AAAA,IAA8B,OAAO;AAAA,KAClC,MAAM,YAGT,MAAM;AAGR,MAAI,OAAO;AACT,QAAI,MAAM,mBAAmB;AAC3B,aAAO;AAAA;AAET,UAAM,QAAQ,OAAO,QAAQ,WAAW;AACxC,WACE,oCAAC,OAAD;AAAA,MACE,WAAW,wBAAwB;AAAA,MAEnC,OAAO,EAAE,SAAS,YAAY;AAAA,OAE7B;AAAA;AAKP,SAAO;AAAA,GAxDY;",
4
+ "sourcesContent": ["import React, { useContext, useState } from 'react'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { getThemeParentClassName } from '../createTamagui'\nimport { useConstant } from '../hooks/useConstant'\nimport { ThemeName } from '../types'\nimport { ThemeContext } from './ThemeContext'\nimport { ThemeManager, ThemeManagerContext } from './ThemeManagerContext'\n\nexport type ThemeProps = {\n disableThemeClass?: boolean\n name: ThemeName | null\n children?: any\n}\n\nexport const Theme = (props: ThemeProps) => {\n const parent = useContext(ThemeManagerContext)\n const themes = useContext(ThemeContext)\n const [parentName, setParentName] = useState(parent.name || 'light')\n if (!themes) {\n console.warn('Error, no themes in context', props)\n return props.children\n }\n const name = props.name as string\n const nextNameParent = `${name}-${parentName}`\n const nextNameParentParent = `${name}-${parent.parentName}`\n const activeName = !name\n ? null\n : name in themes\n ? name\n : nextNameParent in themes\n ? nextNameParent\n : nextNameParentParent in themes\n ? nextNameParentParent\n : null\n const theme = activeName ? themes[activeName] : null\n const themeManager = useConstant<ThemeManager | null>(() => {\n if (!theme) {\n return null\n }\n const manager = new ThemeManager()\n if (name) {\n manager.setActiveTheme({ name, theme: themes[name], parentName })\n }\n return manager\n })\n\n useIsomorphicLayoutEffect(() => {\n if (!themeManager) {\n return\n }\n themeManager.setActiveTheme({ name: activeName, theme, parentName })\n return parent.onChangeTheme((next) => {\n if (next) {\n themeManager.setActiveTheme({ name: next, theme: themes[next], parentName })\n setParentName(next)\n }\n })\n }, [themes, activeName, parentName])\n\n if (!name || !theme) {\n return props.children\n }\n\n const contents = themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {props.children}\n </ThemeManagerContext.Provider>\n ) : (\n props.children\n )\n\n if (isWeb) {\n if (props.disableThemeClass) {\n return contents\n }\n const color = themes[name]?.['color']?.['variable']\n return (\n <div\n className={getThemeParentClassName(name)}\n // in order to provide currentColor, set color by default\n style={{ display: 'contents', color }}\n >\n {contents}\n </div>\n )\n }\n\n return contents\n}\n"],
5
+ "mappings": ";;AAAA;AAEA;AACA;AACA;AAEA;AACA;AAQO,MAAM,QAAQ,wBAAC,UAAsB;AAC1C,QAAM,SAAS,WAAW;AAC1B,QAAM,SAAS,WAAW;AAC1B,QAAM,CAAC,YAAY,iBAAiB,SAAS,OAAO,QAAQ;AAC5D,MAAI,CAAC,QAAQ;AACX,YAAQ,KAAK,+BAA+B;AAC5C,WAAO,MAAM;AAAA;AAEf,QAAM,OAAO,MAAM;AACnB,QAAM,iBAAiB,GAAG,QAAQ;AAClC,QAAM,uBAAuB,GAAG,QAAQ,OAAO;AAC/C,QAAM,aAAa,CAAC,OAChB,OACA,QAAQ,SACR,OACA,kBAAkB,SAClB,iBACA,wBAAwB,SACxB,uBACA;AACJ,QAAM,QAAQ,aAAa,OAAO,cAAc;AAChD,QAAM,eAAe,YAAiC,MAAM;AAC1D,QAAI,CAAC,OAAO;AACV,aAAO;AAAA;AAET,UAAM,UAAU,IAAI;AACpB,QAAI,MAAM;AACR,cAAQ,eAAe,EAAE,MAAM,OAAO,OAAO,OAAO;AAAA;AAEtD,WAAO;AAAA;AAGT,4BAA0B,MAAM;AAC9B,QAAI,CAAC,cAAc;AACjB;AAAA;AAEF,iBAAa,eAAe,EAAE,MAAM,YAAY,OAAO;AACvD,WAAO,OAAO,cAAc,CAAC,SAAS;AACpC,UAAI,MAAM;AACR,qBAAa,eAAe,EAAE,MAAM,MAAM,OAAO,OAAO,OAAO;AAC/D,sBAAc;AAAA;AAAA;AAAA,KAGjB,CAAC,QAAQ,YAAY;AAExB,MAAI,CAAC,QAAQ,CAAC,OAAO;AACnB,WAAO,MAAM;AAAA;AAGf,QAAM,WAAW,eACf,oCAAC,oBAAoB,UAArB;AAAA,IAA8B,OAAO;AAAA,KAClC,MAAM,YAGT,MAAM;AAGR,MAAI,OAAO;AACT,QAAI,MAAM,mBAAmB;AAC3B,aAAO;AAAA;AAET,UAAM,QAAQ,OAAO,QAAQ,WAAW;AACxC,WACE,oCAAC,OAAD;AAAA,MACE,WAAW,wBAAwB;AAAA,MAEnC,OAAO,EAAE,SAAS,YAAY;AAAA,OAE7B;AAAA;AAKP,SAAO;AAAA,GAzEY;",
6
6
  "names": []
7
7
  }
@@ -15,7 +15,6 @@ const ThemeInverse = /* @__PURE__ */ __name((props) => {
15
15
  const themeName = useThemeName();
16
16
  const defaultTheme = useDefaultThemeName();
17
17
  const name = inversions[themeName] || inversions[defaultTheme] || null;
18
- console.log("todo fixme invert", { themeName, defaultTheme, next: name });
19
18
  return /* @__PURE__ */ React.createElement(Theme, {
20
19
  name
21
20
  }, props.children);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/views/ThemeInverse.tsx"],
4
- "sourcesContent": ["import React from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\ntype StringRecord = { [key: string]: string }\n\nlet inversions: StringRecord = {\n light: 'dark',\n dark: 'light',\n}\n\nexport function setThemeInversions(next: StringRecord) {\n inversions = next\n}\n\nexport const ThemeInverse = (props: { children: any }) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const name = inversions[themeName] || inversions[defaultTheme] || null\n console.log('todo fixme invert', { themeName, defaultTheme, next: name })\n return <Theme name={name}>{props.children}</Theme>\n}\n"],
5
- "mappings": ";;AAAA;AAEA;AACA;AAIA,IAAI,aAA2B;AAAA,EAC7B,OAAO;AAAA,EACP,MAAM;AAAA;AAGD,4BAA4B,MAAoB;AACrD,eAAa;AAAA;AADC;AAIT,MAAM,eAAe,wBAAC,UAA6B;AACxD,QAAM,YAAY;AAClB,QAAM,eAAe;AACrB,QAAM,OAAO,WAAW,cAAc,WAAW,iBAAiB;AAClE,UAAQ,IAAI,qBAAqB,EAAE,WAAW,cAAc,MAAM;AAClE,SAAO,oCAAC,OAAD;AAAA,IAAO;AAAA,KAAa,MAAM;AAAA,GALP;",
4
+ "sourcesContent": ["import React from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\ntype StringRecord = { [key: string]: string }\n\nlet inversions: StringRecord = {\n light: 'dark',\n dark: 'light',\n}\n\nexport function setThemeInversions(next: StringRecord) {\n inversions = next\n}\n\nexport const ThemeInverse = (props: { children: any }) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const name = inversions[themeName] || inversions[defaultTheme] || null\n return <Theme name={name}>{props.children}</Theme>\n}\n"],
5
+ "mappings": ";;AAAA;AAEA;AACA;AAIA,IAAI,aAA2B;AAAA,EAC7B,OAAO;AAAA,EACP,MAAM;AAAA;AAGD,4BAA4B,MAAoB;AACrD,eAAa;AAAA;AADC;AAIT,MAAM,eAAe,wBAAC,UAA6B;AACxD,QAAM,YAAY;AAClB,QAAM,eAAe;AACrB,QAAM,OAAO,WAAW,cAAc,WAAW,iBAAiB;AAClE,SAAO,oCAAC,OAAD;AAAA,IAAO;AAAA,KAAa,MAAM;AAAA,GAJP;",
6
6
  "names": []
7
7
  }
@@ -4,16 +4,22 @@ import { createContext } from "react";
4
4
  class ThemeManager {
5
5
  constructor() {
6
6
  this.name = "light";
7
+ this.parentName = null;
7
8
  this.keys = new Map();
8
9
  this.listeners = new Map();
9
10
  this.callbacks = new Set();
10
11
  this.theme = null;
11
12
  }
12
- setActiveTheme(name, theme) {
13
+ setActiveTheme({
14
+ name,
15
+ theme,
16
+ parentName
17
+ }) {
13
18
  if (name === this.name)
14
19
  return;
15
20
  this.name = name;
16
21
  this.theme = theme;
22
+ this.parentName = parentName || null;
17
23
  this.update();
18
24
  }
19
25
  track(uuid, keys) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/views/ThemeManagerContext.tsx"],
4
- "sourcesContent": ["import { createContext } from 'react'\n\nexport class ThemeManager {\n name: string | null = 'light'\n keys = new Map<any, Set<string>>()\n listeners = new Map<any, Function>()\n callbacks = new Set<Function>()\n theme = null\n\n setActiveTheme(name: string | null, theme?: any) {\n if (name === this.name) return\n this.name = name\n this.theme = theme\n this.update()\n }\n\n track(uuid: any, keys: Set<string>) {\n if (!this.name) return\n this.keys.set(uuid, keys)\n }\n\n update() {\n if (!this.name) {\n this.keys.clear()\n }\n for (const [uuid, keys] of this.keys.entries()) {\n if (keys.size) {\n this.listeners.get(uuid)?.()\n }\n }\n this.callbacks.forEach((cb) => cb(this.name))\n }\n\n onChangeTheme(cb: (name: string | null) => void) {\n this.callbacks.add(cb)\n return () => {\n this.callbacks.delete(cb)\n }\n }\n\n onUpdate(uuid: any, cb: Function) {\n this.listeners.set(uuid, cb)\n return () => {\n this.listeners.delete(uuid)\n this.keys.delete(uuid)\n }\n }\n}\n\nexport const ThemeManagerContext = createContext<ThemeManager>(new ThemeManager())\n"],
5
- "mappings": ";;AAAA;AAEO,mBAAmB;AAAA,EAAnB,cAFP;AAGE,gBAAsB;AACtB,gBAAO,IAAI;AACX,qBAAY,IAAI;AAChB,qBAAY,IAAI;AAChB,iBAAQ;AAAA;AAAA,EAER,eAAe,MAAqB,OAAa;AAC/C,QAAI,SAAS,KAAK;AAAM;AACxB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK;AAAA;AAAA,EAGP,MAAM,MAAW,MAAmB;AAClC,QAAI,CAAC,KAAK;AAAM;AAChB,SAAK,KAAK,IAAI,MAAM;AAAA;AAAA,EAGtB,SAAS;AACP,QAAI,CAAC,KAAK,MAAM;AACd,WAAK,KAAK;AAAA;AAEZ,eAAW,CAAC,MAAM,SAAS,KAAK,KAAK,WAAW;AAC9C,UAAI,KAAK,MAAM;AACb,aAAK,UAAU,IAAI;AAAA;AAAA;AAGvB,SAAK,UAAU,QAAQ,CAAC,OAAO,GAAG,KAAK;AAAA;AAAA,EAGzC,cAAc,IAAmC;AAC/C,SAAK,UAAU,IAAI;AACnB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO;AAAA;AAAA;AAAA,EAI1B,SAAS,MAAW,IAAc;AAChC,SAAK,UAAU,IAAI,MAAM;AACzB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO;AACtB,WAAK,KAAK,OAAO;AAAA;AAAA;AAAA;AA1ChB;AA+CA,MAAM,sBAAsB,cAA4B,IAAI;",
4
+ "sourcesContent": ["import { createContext } from 'react'\n\nexport class ThemeManager {\n name: string | null = 'light'\n parentName: string | null = null\n keys = new Map<any, Set<string>>()\n listeners = new Map<any, Function>()\n callbacks = new Set<Function>()\n theme = null\n\n setActiveTheme({\n name,\n theme,\n parentName,\n }: {\n parentName?: string | null\n name: string | null\n theme?: any\n }) {\n if (name === this.name) return\n this.name = name\n this.theme = theme\n this.parentName = parentName || null\n this.update()\n }\n\n track(uuid: any, keys: Set<string>) {\n if (!this.name) return\n this.keys.set(uuid, keys)\n }\n\n update() {\n if (!this.name) {\n this.keys.clear()\n }\n for (const [uuid, keys] of this.keys.entries()) {\n if (keys.size) {\n this.listeners.get(uuid)?.()\n }\n }\n this.callbacks.forEach((cb) => cb(this.name))\n }\n\n onChangeTheme(cb: (name: string | null) => void) {\n this.callbacks.add(cb)\n return () => {\n this.callbacks.delete(cb)\n }\n }\n\n onUpdate(uuid: any, cb: Function) {\n this.listeners.set(uuid, cb)\n return () => {\n this.listeners.delete(uuid)\n this.keys.delete(uuid)\n }\n }\n}\n\nexport const ThemeManagerContext = createContext<ThemeManager>(new ThemeManager())\n"],
5
+ "mappings": ";;AAAA;AAEO,mBAAmB;AAAA,EAAnB,cAFP;AAGE,gBAAsB;AACtB,sBAA4B;AAC5B,gBAAO,IAAI;AACX,qBAAY,IAAI;AAChB,qBAAY,IAAI;AAChB,iBAAQ;AAAA;AAAA,EAER,eAAe;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,KAKC;AACD,QAAI,SAAS,KAAK;AAAM;AACxB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,aAAa,cAAc;AAChC,SAAK;AAAA;AAAA,EAGP,MAAM,MAAW,MAAmB;AAClC,QAAI,CAAC,KAAK;AAAM;AAChB,SAAK,KAAK,IAAI,MAAM;AAAA;AAAA,EAGtB,SAAS;AACP,QAAI,CAAC,KAAK,MAAM;AACd,WAAK,KAAK;AAAA;AAEZ,eAAW,CAAC,MAAM,SAAS,KAAK,KAAK,WAAW;AAC9C,UAAI,KAAK,MAAM;AACb,aAAK,UAAU,IAAI;AAAA;AAAA;AAGvB,SAAK,UAAU,QAAQ,CAAC,OAAO,GAAG,KAAK;AAAA;AAAA,EAGzC,cAAc,IAAmC;AAC/C,SAAK,UAAU,IAAI;AACnB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO;AAAA;AAAA;AAAA,EAI1B,SAAS,MAAW,IAAc;AAChC,SAAK,UAAU,IAAI,MAAM;AACzB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO;AACtB,WAAK,KAAK,OAAO;AAAA;AAAA;AAAA;AApDhB;AAyDA,MAAM,sBAAsB,cAA4B,IAAI;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.7",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -9,17 +9,24 @@
9
9
  "build": "tamagui-build",
10
10
  "watch": "tamagui-build --watch"
11
11
  },
12
+ "files": [
13
+ "types.d.ts",
14
+ "dist",
15
+ "src"
16
+ ],
12
17
  "dependencies": {
13
- "@tamagui/helpers": "^1.0.0-alpha.2",
18
+ "@tamagui/helpers": "^1.0.0-alpha.5",
19
+ "@tamagui/use-debounce": "^1.0.0-alpha.6",
20
+ "@tamagui/use-force-update": "^1.0.0-alpha.5",
14
21
  "react": "*",
15
- "react-dom": "*",
16
- "react-native-safe-area-context": "^3.3.0"
22
+ "react-dom": "*"
17
23
  },
18
24
  "peerDependencies": {
19
25
  "react-native-web": "*"
20
26
  },
21
27
  "devDependencies": {
22
28
  "@tamagui/build": "^1.0.0-alpha.2",
29
+ "@tamagui/ow": "^0.28.1",
23
30
  "@types/react": "^17.0.35",
24
31
  "esbuild": "^0.11.20",
25
32
  "typescript": "^4.4.4"
@@ -30,5 +37,5 @@
30
37
  "engines": {
31
38
  "node": ">=16"
32
39
  },
33
- "gitHead": "a9f30fdf4ebd448961a6e133741cd4b903185559"
40
+ "gitHead": "13694a98d31535846699004532630788177537e9"
34
41
  }
@@ -1,4 +1,5 @@
1
1
  import { concatClassName, stylePropsView } from '@tamagui/helpers'
2
+ import { useForceUpdate } from '@tamagui/use-force-update'
2
3
  import React, {
3
4
  Children,
4
5
  Fragment,
@@ -20,7 +21,6 @@ import { addStylesUsingClassname, useStylesAsClassname } from './helpers/addStyl
20
21
  import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'
21
22
  import { getSplitStyles } from './helpers/getSplitStyles'
22
23
  import { useFeatures } from './hooks/useFeatures'
23
- import { useForceUpdate } from './hooks/useForceUpdate'
24
24
  import { usePressable } from './hooks/usePressable'
25
25
  import {
26
26
  SpaceTokens,
@@ -68,6 +68,44 @@ export function createComponent<A extends Object = DefaultProps>(
68
68
  // see onConfiguredOnce below which attaches a name then to this component
69
69
 
70
70
  const component = forwardRef<View, A>((props: any, forwardedRef) => {
71
+ const forceUpdate = useForceUpdate()
72
+ const features = useFeatures(props, { forceUpdate })
73
+ const manager = useContext(ThemeManagerContext)
74
+ const [state, set_] = useState(() => ({
75
+ hover: false,
76
+ press: false,
77
+ pressIn: false,
78
+ theme: manager.name,
79
+ }))
80
+ const set = (next: Partial<typeof state>) =>
81
+ set_((prev) => {
82
+ for (const key in next) {
83
+ if (prev[key] !== next[key]) {
84
+ return { ...prev, ...next }
85
+ }
86
+ }
87
+ return prev
88
+ })
89
+
90
+ // from react-native-web
91
+ if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
92
+ Children.toArray(props.children).forEach((item) => {
93
+ if (typeof item === 'string') {
94
+ console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)
95
+ }
96
+ })
97
+ }
98
+
99
+ const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false
100
+ const hostRef = useRef(null)
101
+
102
+ const {
103
+ viewProps: viewPropsIn,
104
+ pseudos,
105
+ style,
106
+ classNames,
107
+ } = getSplitStyles(props, staticConfig, (manager.theme as any) || initialTheme)
108
+
71
109
  const {
72
110
  tag,
73
111
  hitSlop,
@@ -101,40 +139,19 @@ export function createComponent<A extends Object = DefaultProps>(
101
139
  onStartShouldSetResponderCapture,
102
140
  onMouseDown,
103
141
  onClick,
104
- // TODO feature load layou hook
105
- onLayout,
106
- } = props
107
142
 
108
- const forceUpdate = useForceUpdate()
109
- const features = useFeatures(props, { forceUpdate })
110
- const manager = useContext(ThemeManagerContext)
111
- const [state, set_] = useState(() => ({
112
- hover: false,
113
- press: false,
114
- pressIn: false,
115
- theme: manager.name,
116
- }))
117
- const set = (next: Partial<typeof state>) =>
118
- set_((prev) => {
119
- for (const key in next) {
120
- if (prev[key] !== next[key]) {
121
- return { ...prev, ...next }
122
- }
123
- }
124
- return prev
125
- })
143
+ accessible,
144
+ accessibilityRole,
126
145
 
127
- // from react-native-web
128
- if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
129
- Children.toArray(props.children).forEach((item) => {
130
- if (typeof item === 'string') {
131
- console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)
132
- }
133
- })
134
- }
146
+ // TODO feature load layout hook
147
+ onLayout,
148
+ ...viewProps
149
+ } = viewPropsIn
135
150
 
136
- const hasTextAncestor = isWeb ? useContext(TextAncestorContext) : false
137
- const hostRef = useRef(null)
151
+ if (!isWeb) {
152
+ if (accessible) viewProps.accessible = accessible
153
+ if (accessibilityRole) viewProps.accessibilityRole = accessibilityRole
154
+ }
138
155
 
139
156
  if (isWeb) {
140
157
  // from react-native-web
@@ -160,12 +177,6 @@ export function createComponent<A extends Object = DefaultProps>(
160
177
 
161
178
  const isTracking = useRef(false)
162
179
 
163
- const { viewProps, pseudos, style, classNames } = getSplitStyles(
164
- props,
165
- staticConfig,
166
- (manager.theme as any) || initialTheme
167
- )
168
-
169
180
  // hasEverHadEvents prevents repareting if you remove onPress or similar...
170
181
  const internal = useRef<{ isMounted: boolean; hasEverHadEvents?: boolean }>()
171
182
  if (!internal.current) {
package/src/createFont.ts CHANGED
@@ -1,6 +1,11 @@
1
+ import { validateFont } from './helpers/validate'
1
2
  import { GenericFont } from './types'
2
3
 
3
4
  export const createFont = <A extends GenericFont>(font: A): A => {
5
+ if (process.env.NODE_ENV === 'development') {
6
+ validateFont(font)
7
+ }
8
+
4
9
  // fills in any missing values based on size keys being standard
5
10
  const sizeKeys = Object.keys(font.size)
6
11
 
@@ -2,6 +2,7 @@ import { getStyleRules } from '@tamagui/helpers'
2
2
 
3
3
  import { Variable, createVariable, isVariable } from './createVariable'
4
4
  import { createTamaguiProvider } from './helpers/createTamaguiProvider'
5
+ import { validateConfig } from './helpers/validate'
5
6
  import { configureMedia } from './hooks/useMedia'
6
7
  import {
7
8
  CreateTamaguiConfig,
@@ -46,6 +47,12 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
46
47
  ): Conf extends CreateTamaguiConfig<infer A, infer B, infer C, infer D>
47
48
  ? TamaguiInternalConfig<A, B, C, D>
48
49
  : unknown {
50
+ if (process.env.NODE_ENV === 'development') {
51
+ // config is re-run by the @tamagui/static, dont double validate
52
+ if (!config['parsed']) {
53
+ validateConfig(config)
54
+ }
55
+ }
49
56
  // test env loads a few times as it runs diff tests
50
57
  if (conf) {
51
58
  console.warn('Called createTamagui twice! Should never do so')
@@ -157,6 +164,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
157
164
  themeConfig,
158
165
  themeParsed,
159
166
  tokensParsed,
167
+ parsed: true,
160
168
  getCSS() {
161
169
  return `${themeConfig.css}\n${[...getStyleRules()].join('\n')}`
162
170
  },
@@ -1,9 +1,14 @@
1
1
  import { Variable, createVariable } from './createVariable'
2
+ import { validateTokens } from './helpers/validate'
2
3
  import { CreateTokens } from './types'
3
4
 
4
- // tokens.color.dark.red ===>{ var: `color-dark-red`, val: '' }
5
+ // tokens.color.dark.red ===> { var: `color-dark-red`, val: '' }
5
6
 
6
7
  export function createTokens<T extends CreateTokens>(tokens: T): MakeTokens<T> {
8
+ if (process.env.NODE_ENV === 'development') {
9
+ validateTokens(tokens)
10
+ }
11
+
7
12
  return setupTokens(tokens) as any
8
13
  }
9
14
 
@@ -11,6 +11,10 @@ export class Variable {
11
11
  this.name = name
12
12
  this.variable = isWeb ? `var(--${name})` : this.val
13
13
  }
14
+
15
+ toString() {
16
+ return isWeb ? this.variable : this.val
17
+ }
14
18
  }
15
19
 
16
20
  type VariableIn = { val: string | number; name: string }
@@ -28,7 +28,6 @@ export const getSplitStyles = (
28
28
  const validStyleProps = staticConfig.isText ? stylePropsText : validStyles
29
29
  const viewProps: Record<string, any> = {}
30
30
  const style: any[] = []
31
- const blacklistProps = isSplittingDefaultProps ? blacklistDefaultProps : blacklistFinalProps
32
31
 
33
32
  let pseudos: { hoverStyle?: ViewStyle; pressStyle?: ViewStyle } | null = null
34
33
  let cur: ViewStyle | null = null
@@ -130,8 +129,9 @@ export const getSplitStyles = (
130
129
  cur[key] = val
131
130
  continue
132
131
  }
133
- // TODO this blacklist should be configurable + better set up
134
- if (!blacklistProps[key]) {
132
+
133
+ // pass to view props
134
+ if (!staticConfig.variants || !(key in staticConfig.variants)) {
135
135
  viewProps[key] = val
136
136
  }
137
137
  }
@@ -181,19 +181,6 @@ const getSubStyle = (
181
181
  return styleOut
182
182
  }
183
183
 
184
- const blacklistDefaultProps = {
185
- ...validStyles,
186
- ...stylePropsText,
187
- }
188
-
189
- const blacklistFinalProps = {
190
- ...blacklistDefaultProps,
191
- tag: true,
192
- debug: true,
193
- space: true,
194
- hitSlop: true,
195
- }
196
-
197
184
  const mapTransformKeys = {
198
185
  x: 'translateX',
199
186
  y: 'translateY',
@@ -0,0 +1,5 @@
1
+ import React, { isValidElement } from 'react'
2
+
3
+ export const isTamaguiElement = (child: any): child is React.ReactElement => {
4
+ return isValidElement(child) && !!child.type['staticConfig']?.parsed
5
+ }
@@ -0,0 +1,59 @@
1
+ // published a patched version that works on native
2
+ import ow from '@tamagui/ow'
3
+
4
+ export const validateConfig = (conf: any) => {
5
+ if (!conf) {
6
+ console.warn('no conf?')
7
+ return
8
+ }
9
+ try {
10
+ ow(conf, validConfig)
11
+ } catch (err: any) {
12
+ console.log('Given config:\n', JSON.stringify(conf, null, 2))
13
+ throw err
14
+ }
15
+ }
16
+
17
+ const validConfig = ow.object.exactShape({
18
+ defaultTheme: ow.optional.string,
19
+ disableRootThemeClass: ow.optional.boolean,
20
+ shorthands: ow.optional.object.valuesOfType(ow.string),
21
+ themes: ow.object.valuesOfType(ow.object),
22
+ tokens: ow.object.valuesOfType(ow.object),
23
+ media: ow.object.valuesOfType(ow.object),
24
+ })
25
+
26
+ const validFont = ow.object.exactShape({
27
+ family: ow.string,
28
+ size: ow.object.nonEmpty.valuesOfType(ow.number),
29
+ lineHeight: ow.object.nonEmpty.valuesOfType(ow.number),
30
+ weight: ow.object.nonEmpty.valuesOfType(ow.string),
31
+ letterSpacing: ow.object.nonEmpty.valuesOfType(ow.number),
32
+ })
33
+
34
+ const validTokens = ow.object.exactShape({
35
+ font: ow.object.valuesOfType(validFont),
36
+ size: ow.object.nonEmpty.valuesOfType(ow.number),
37
+ space: ow.object.nonEmpty.valuesOfType(ow.number),
38
+ zIndex: ow.object.nonEmpty.valuesOfType(ow.number),
39
+ radius: ow.object.nonEmpty.valuesOfType(ow.number),
40
+ color: ow.object.nonEmpty.valuesOfType(ow.string),
41
+ })
42
+
43
+ export const validateTokens = (tokens: any) => {
44
+ try {
45
+ ow(tokens, validTokens)
46
+ } catch (err: any) {
47
+ console.log('Given tokens:\n', JSON.stringify(tokens, null, 2))
48
+ throw err
49
+ }
50
+ }
51
+
52
+ export const validateFont = (font: any) => {
53
+ try {
54
+ ow(font, validFont)
55
+ } catch (err: any) {
56
+ console.log('Given font:\n', JSON.stringify(font, null, 2))
57
+ throw err
58
+ }
59
+ }
@@ -1,3 +1,4 @@
1
+ import { useForceUpdate } from '@tamagui/use-force-update'
1
2
  import { useRef } from 'react'
2
3
 
3
4
  import { useIsomorphicLayoutEffect } from '../constants/platform'
@@ -9,7 +10,6 @@ import {
9
10
  MediaQueryState,
10
11
  } from '../types'
11
12
  import { useConstant } from './useConstant'
12
- import { useForceUpdate } from './useForceUpdate'
13
13
 
14
14
  export const mediaState: { [key in keyof MediaQueryState]: boolean } = {} as any
15
15
  const mediaQueryListeners: { [key: string]: Set<Function> } = {}
@@ -1,3 +1,4 @@
1
+ import { useForceUpdate } from '@tamagui/use-force-update'
1
2
  import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'
2
3
 
3
4
  import { useIsomorphicLayoutEffect } from '../constants/platform'
@@ -6,7 +7,6 @@ import { ThemeName } from '../types'
6
7
  import { ThemeContext } from '../views/ThemeContext'
7
8
  import { ThemeManagerContext } from '../views/ThemeManagerContext'
8
9
  import { GET_DEFAULT_THEME } from '../views/ThemeProvider'
9
- import { useForceUpdate } from './useForceUpdate'
10
10
 
11
11
  type UseThemeState = {
12
12
  uuid: Object
package/src/index.ts CHANGED
@@ -17,9 +17,9 @@ export * from './helpers/isObj'
17
17
  export * from './helpers/getStylesAtomic'
18
18
  export * from './helpers/matchMedia'
19
19
  export * from './helpers/themeable'
20
+ export * from './helpers/isTamaguiElement'
20
21
 
21
22
  export * from './hooks/useConstant'
22
- export * from './hooks/useForceUpdate'
23
23
  export * from './hooks/useMedia'
24
24
  export * from './hooks/useTheme'
25
25
 
@@ -30,4 +30,3 @@ export * from './views/Theme'
30
30
  export * from './views/ThemeInverse'
31
31
  export * from './views/ThemeProvider'
32
32
  export * from './views/TextAncestorContext'
33
- export * from './views/SafeAreaProvider'
package/src/types.tsx CHANGED
@@ -110,6 +110,7 @@ export type TamaguiInternalConfig<
110
110
  tokensParsed: CreateTokens<Variable>
111
111
  themeConfig: any
112
112
  getCSS: () => string
113
+ parsed: boolean
113
114
  }
114
115
 
115
116
  // prevents const intersections from being clobbered into string, keeping the consts
@@ -3,7 +3,7 @@ import React, { useContext, useState } from 'react'
3
3
  import { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
4
4
  import { getThemeParentClassName } from '../createTamagui'
5
5
  import { useConstant } from '../hooks/useConstant'
6
- import { ThemeName, Themes } from '../types'
6
+ import { ThemeName } from '../types'
7
7
  import { ThemeContext } from './ThemeContext'
8
8
  import { ThemeManager, ThemeManagerContext } from './ThemeManagerContext'
9
9
 
@@ -18,30 +18,47 @@ export const Theme = (props: ThemeProps) => {
18
18
  const themes = useContext(ThemeContext)
19
19
  const [parentName, setParentName] = useState(parent.name || 'light')
20
20
  if (!themes) {
21
- console.warn('no themes???', props)
21
+ console.warn('Error, no themes in context', props)
22
22
  return props.children
23
23
  }
24
24
  const name = props.name as string
25
- const theme = themes[name] || themes[`${name}-${parentName}`]
26
- const themeManager = useConstant<ThemeManager>(() => {
25
+ const nextNameParent = `${name}-${parentName}`
26
+ const nextNameParentParent = `${name}-${parent.parentName}`
27
+ const activeName = !name
28
+ ? null
29
+ : name in themes
30
+ ? name
31
+ : nextNameParent in themes
32
+ ? nextNameParent
33
+ : nextNameParentParent in themes
34
+ ? nextNameParentParent
35
+ : null
36
+ const theme = activeName ? themes[activeName] : null
37
+ const themeManager = useConstant<ThemeManager | null>(() => {
38
+ if (!theme) {
39
+ return null
40
+ }
27
41
  const manager = new ThemeManager()
28
42
  if (name) {
29
- manager.setActiveTheme(name, themes[name])
43
+ manager.setActiveTheme({ name, theme: themes[name], parentName })
30
44
  }
31
45
  return manager
32
46
  })
33
47
 
34
48
  useIsomorphicLayoutEffect(() => {
35
- themeManager.setActiveTheme(name, theme)
49
+ if (!themeManager) {
50
+ return
51
+ }
52
+ themeManager.setActiveTheme({ name: activeName, theme, parentName })
36
53
  return parent.onChangeTheme((next) => {
37
54
  if (next) {
38
- themeManager.setActiveTheme(next, themes[next])
55
+ themeManager.setActiveTheme({ name: next, theme: themes[next], parentName })
39
56
  setParentName(next)
40
57
  }
41
58
  })
42
- }, [themes, name])
59
+ }, [themes, activeName, parentName])
43
60
 
44
- if (!name) {
61
+ if (!name || !theme) {
45
62
  return props.children
46
63
  }
47
64
 
@@ -18,6 +18,5 @@ export const ThemeInverse = (props: { children: any }) => {
18
18
  const themeName = useThemeName()
19
19
  const defaultTheme = useDefaultThemeName()
20
20
  const name = inversions[themeName] || inversions[defaultTheme] || null
21
- console.log('todo fixme invert', { themeName, defaultTheme, next: name })
22
21
  return <Theme name={name}>{props.children}</Theme>
23
22
  }