@tamagui/core 1.0.0-alpha.5 → 1.0.0-alpha.6

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/index.js CHANGED
@@ -15,6 +15,7 @@ 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
20
  export * from "./hooks/useMedia";
20
21
  export * from "./hooks/useTheme";
@@ -25,7 +26,6 @@ export * from "./views/Theme";
25
26
  export * from "./views/ThemeInverse";
26
27
  export * from "./views/ThemeProvider";
27
28
  export * from "./views/TextAncestorContext";
28
- export * from "./views/SafeAreaProvider";
29
29
  export {
30
30
  createTokens
31
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/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;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
  }
@@ -15,8 +15,12 @@ const Theme = /* @__PURE__ */ __name((props) => {
15
15
  return props.children;
16
16
  }
17
17
  const name = props.name;
18
- const theme = themes[name] || themes[`${name}-${parentName}`];
18
+ const activeName = !name ? null : name in themes ? name : `${name}-${parentName}`;
19
+ const theme = activeName ? themes[activeName] : null;
19
20
  const themeManager = useConstant(() => {
21
+ if (!theme) {
22
+ return null;
23
+ }
20
24
  const manager = new ThemeManager();
21
25
  if (name) {
22
26
  manager.setActiveTheme(name, themes[name]);
@@ -24,15 +28,18 @@ const Theme = /* @__PURE__ */ __name((props) => {
24
28
  return manager;
25
29
  });
26
30
  useIsomorphicLayoutEffect(() => {
27
- themeManager.setActiveTheme(name, theme);
31
+ if (!themeManager) {
32
+ return;
33
+ }
34
+ themeManager.setActiveTheme(activeName, theme);
28
35
  return parent.onChangeTheme((next) => {
29
36
  if (next) {
30
37
  themeManager.setActiveTheme(next, themes[next]);
31
38
  setParentName(next);
32
39
  }
33
40
  });
34
- }, [themes, name]);
35
- if (!name) {
41
+ }, [themes, activeName]);
42
+ if (!name || !theme) {
36
43
  return props.children;
37
44
  }
38
45
  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, 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 activeName = !name ? null : name in themes ? name : `${name}-${parentName}`\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, themes[name])\n }\n return manager\n })\n\n useIsomorphicLayoutEffect(() => {\n if (!themeManager) {\n return\n }\n themeManager.setActiveTheme(activeName, theme)\n return parent.onChangeTheme((next) => {\n if (next) {\n themeManager.setActiveTheme(next, themes[next])\n setParentName(next)\n }\n })\n }, [themes, activeName])\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,gBAAgB;AAC7B,WAAO,MAAM;AAAA;AAEf,QAAM,OAAO,MAAM;AACnB,QAAM,aAAa,CAAC,OAAO,OAAO,QAAQ,SAAS,OAAO,GAAG,QAAQ;AACrE,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,MAAM,OAAO;AAAA;AAEtC,WAAO;AAAA;AAGT,4BAA0B,MAAM;AAC9B,QAAI,CAAC,cAAc;AACjB;AAAA;AAEF,iBAAa,eAAe,YAAY;AACxC,WAAO,OAAO,cAAc,CAAC,SAAS;AACpC,UAAI,MAAM;AACR,qBAAa,eAAe,MAAM,OAAO;AACzC,sBAAc;AAAA;AAAA;AAAA,KAGjB,CAAC,QAAQ;AAEZ,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,GA/DY;",
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.0-alpha.5",
3
+ "version": "1.0.0-alpha.6",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -16,11 +16,10 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@tamagui/helpers": "^1.0.0-alpha.5",
19
- "@tamagui/use-debounce": "^1.0.0-alpha.5",
19
+ "@tamagui/use-debounce": "^1.0.0-alpha.6",
20
20
  "@tamagui/use-force-update": "^1.0.0-alpha.5",
21
21
  "react": "*",
22
- "react-dom": "*",
23
- "react-native-safe-area-context": "^3.3.0"
22
+ "react-dom": "*"
24
23
  },
25
24
  "peerDependencies": {
26
25
  "react-native-web": "*"
@@ -37,5 +36,5 @@
37
36
  "engines": {
38
37
  "node": ">=16"
39
38
  },
40
- "gitHead": "e12f14aa087c41ea5ba3933a05f33fada0be03c0"
39
+ "gitHead": "18a942d7a08109c8f5b8692a2adb20c69d56a7e1"
41
40
  }
@@ -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) {
@@ -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
+ }
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ 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
23
  export * from './hooks/useMedia'
@@ -29,4 +30,3 @@ export * from './views/Theme'
29
30
  export * from './views/ThemeInverse'
30
31
  export * from './views/ThemeProvider'
31
32
  export * from './views/TextAncestorContext'
32
- export * from './views/SafeAreaProvider'
@@ -22,8 +22,12 @@ export const Theme = (props: ThemeProps) => {
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 activeName = !name ? null : name in themes ? name : `${name}-${parentName}`
26
+ const theme = activeName ? themes[activeName] : null
27
+ const themeManager = useConstant<ThemeManager | null>(() => {
28
+ if (!theme) {
29
+ return null
30
+ }
27
31
  const manager = new ThemeManager()
28
32
  if (name) {
29
33
  manager.setActiveTheme(name, themes[name])
@@ -32,16 +36,19 @@ export const Theme = (props: ThemeProps) => {
32
36
  })
33
37
 
34
38
  useIsomorphicLayoutEffect(() => {
35
- themeManager.setActiveTheme(name, theme)
39
+ if (!themeManager) {
40
+ return
41
+ }
42
+ themeManager.setActiveTheme(activeName, theme)
36
43
  return parent.onChangeTheme((next) => {
37
44
  if (next) {
38
45
  themeManager.setActiveTheme(next, themes[next])
39
46
  setParentName(next)
40
47
  }
41
48
  })
42
- }, [themes, name])
49
+ }, [themes, activeName])
43
50
 
44
- if (!name) {
51
+ if (!name || !theme) {
45
52
  return props.children
46
53
  }
47
54
 
@@ -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
  }
package/types.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare class Variable {
11
11
  val: string | number;
12
12
  variable: string | number;
13
13
  constructor({ val, name }: VariableIn);
14
+ toString(): string | number;
14
15
  }
15
16
  export declare type VariableIn = {
16
17
  val: string | number;
@@ -491,6 +492,7 @@ export declare const themeable: ThemeableHOC;
491
492
  export interface ThemeableHOC {
492
493
  <R extends ReactElement<any, any> | null, P extends ThemeableProps = {}>(component: (props: P) => R): (props: P) => R;
493
494
  }
495
+ export declare const isTamaguiElement: (child: any) => child is React.ReactElement<any, string | React.JSXElementConstructor<any>>;
494
496
  export declare function useConstant<T>(fn: () => T): T;
495
497
  export declare const mediaState: {
496
498
  [key in keyof MediaQueryState]: boolean;
@@ -549,9 +551,5 @@ export declare const ThemeInverse: (props: {
549
551
  }) => JSX.Element;
550
552
  export declare const TextAncestorContext: any;
551
553
  export declare const TextAncestorProvider: (props: any) => any;
552
- export declare const SafeAreaProvider: ({ initialWindowMetrics, children, }: {
553
- children?: any;
554
- initialWindowMetrics?: any;
555
- }) => JSX.Element;
556
554
 
557
555
  export {};
@@ -1,33 +0,0 @@
1
- import React from 'react'
2
- import { Platform } from 'react-native'
3
- import {
4
- Metrics,
5
- SafeAreaProvider as RNSafeAreaProvider,
6
- initialWindowMetrics as defaultInitialWindowMetrics,
7
- } from 'react-native-safe-area-context'
8
-
9
- let defaultMetrics: Metrics | null = null
10
-
11
- export const SafeAreaProvider = ({
12
- initialWindowMetrics,
13
- children,
14
- }: {
15
- children?: any
16
- initialWindowMetrics?: any
17
- }) => {
18
- if (!initialWindowMetrics && !defaultMetrics) {
19
- defaultMetrics = Platform.select({
20
- web: {
21
- frame: { x: 0, y: 0, width: 0, height: 0 },
22
- insets: { top: 0, left: 0, right: 0, bottom: 0 },
23
- },
24
- default: defaultInitialWindowMetrics,
25
- })
26
- }
27
-
28
- return (
29
- <RNSafeAreaProvider initialMetrics={initialWindowMetrics ?? defaultMetrics}>
30
- {children}
31
- </RNSafeAreaProvider>
32
- )
33
- }