@tamagui/core 1.0.1-beta.153 → 1.0.1-beta.156

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 (99) hide show
  1. package/dist/cjs/constants/isDevTools.js +29 -0
  2. package/dist/cjs/constants/isDevTools.js.map +7 -0
  3. package/dist/cjs/createComponent.js +24 -23
  4. package/dist/cjs/createComponent.js.map +2 -2
  5. package/dist/cjs/helpers/createPropMapper.js +6 -5
  6. package/dist/cjs/helpers/createPropMapper.js.map +2 -2
  7. package/dist/cjs/helpers/createShallowUpdate.js +3 -3
  8. package/dist/cjs/helpers/createShallowUpdate.js.map +2 -2
  9. package/dist/cjs/helpers/getSplitStyles.js +14 -6
  10. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  11. package/dist/cjs/helpers/getStylesAtomic.js.map +1 -1
  12. package/dist/cjs/helpers/getThemeCSSRules.js +2 -1
  13. package/dist/cjs/helpers/getThemeCSSRules.js.map +2 -2
  14. package/dist/cjs/helpers/mergeTransform.js.map +1 -1
  15. package/dist/cjs/helpers/normalizeValueWithProperty.js +2 -1
  16. package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
  17. package/dist/cjs/helpers/{cssHash.js → useShallowSetState.js} +21 -28
  18. package/dist/cjs/helpers/useShallowSetState.js.map +7 -0
  19. package/dist/cjs/hooks/useTheme.js +11 -5
  20. package/dist/cjs/hooks/useTheme.js.map +2 -2
  21. package/dist/cjs/index.js +1 -1
  22. package/dist/cjs/index.js.map +2 -2
  23. package/dist/cjs/styled.js +16 -3
  24. package/dist/cjs/styled.js.map +2 -2
  25. package/dist/cjs/types.js.map +1 -1
  26. package/dist/esm/constants/isDevTools.js +5 -0
  27. package/dist/esm/constants/isDevTools.js.map +7 -0
  28. package/dist/esm/createComponent.js +25 -24
  29. package/dist/esm/createComponent.js.map +2 -2
  30. package/dist/esm/helpers/createPropMapper.js +6 -5
  31. package/dist/esm/helpers/createPropMapper.js.map +2 -2
  32. package/dist/esm/helpers/createShallowUpdate.js +2 -2
  33. package/dist/esm/helpers/createShallowUpdate.js.map +2 -2
  34. package/dist/esm/helpers/getSplitStyles.js +14 -6
  35. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  36. package/dist/esm/helpers/getStylesAtomic.js.map +1 -1
  37. package/dist/esm/helpers/getThemeCSSRules.js +2 -1
  38. package/dist/esm/helpers/getThemeCSSRules.js.map +2 -2
  39. package/dist/esm/helpers/mergeTransform.js.map +1 -1
  40. package/dist/esm/helpers/normalizeValueWithProperty.js +2 -1
  41. package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
  42. package/dist/esm/helpers/useShallowSetState.js +20 -0
  43. package/dist/esm/helpers/useShallowSetState.js.map +7 -0
  44. package/dist/esm/hooks/useTheme.js +11 -5
  45. package/dist/esm/hooks/useTheme.js.map +2 -2
  46. package/dist/esm/index.js +1 -1
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/styled.js +16 -3
  49. package/dist/esm/styled.js.map +2 -2
  50. package/package.json +11 -11
  51. package/src/constants/isDevTools.ts +6 -0
  52. package/src/createComponent.tsx +31 -27
  53. package/src/helpers/createPropMapper.ts +9 -5
  54. package/src/helpers/getSplitStyles.tsx +58 -38
  55. package/src/helpers/getStylesAtomic.ts +1 -1
  56. package/src/helpers/getThemeCSSRules.ts +2 -2
  57. package/src/helpers/mergeTransform.ts +1 -1
  58. package/src/helpers/normalizeValueWithProperty.ts +3 -1
  59. package/src/helpers/{createShallowUpdate.tsx → useShallowSetState.tsx} +1 -1
  60. package/src/hooks/useTheme.tsx +16 -7
  61. package/src/index.ts +1 -1
  62. package/src/styled.tsx +21 -5
  63. package/src/types.tsx +1 -1
  64. package/types/constants/isDevTools.d.ts +2 -0
  65. package/types/helpers/createShallowUpdate.d.ts +1 -1
  66. package/types/helpers/getSplitStyles.d.ts +1 -1
  67. package/types/helpers/getStylesAtomic.d.ts +1 -1
  68. package/types/helpers/mergeTransform.d.ts +1 -1
  69. package/types/helpers/useShallowSetState.d.ts +3 -0
  70. package/types/index.d.ts +1 -1
  71. package/types/styled.d.ts +2 -2
  72. package/types/types.d.ts +1 -1
  73. package/dist/cjs/conf.js +0 -70
  74. package/dist/cjs/conf.js.map +0 -7
  75. package/dist/cjs/createComponent.server.js +0 -431
  76. package/dist/cjs/createComponent.server.js.map +0 -7
  77. package/dist/cjs/helpers/cssHash.js.map +0 -7
  78. package/dist/cjs/helpers/useAnimationDriver.js +0 -2
  79. package/dist/cjs/helpers/useAnimationDriver.js.map +0 -7
  80. package/dist/cjs/hooks/useAnimationDriver.js +0 -2
  81. package/dist/cjs/hooks/useAnimationDriver.js.map +0 -7
  82. package/dist/cjs/hooks/useFeatures.js +0 -89
  83. package/dist/cjs/hooks/useFeatures.js.map +0 -7
  84. package/dist/cjs/hooks/useServerContext.js +0 -21
  85. package/dist/cjs/hooks/useServerContext.js.map +0 -7
  86. package/dist/esm/conf.js +0 -39
  87. package/dist/esm/conf.js.map +0 -7
  88. package/dist/esm/createComponent.server.js +0 -408
  89. package/dist/esm/createComponent.server.js.map +0 -7
  90. package/dist/esm/helpers/cssHash.js +0 -27
  91. package/dist/esm/helpers/cssHash.js.map +0 -7
  92. package/dist/esm/helpers/useAnimationDriver.js +0 -1
  93. package/dist/esm/helpers/useAnimationDriver.js.map +0 -7
  94. package/dist/esm/hooks/useAnimationDriver.js +0 -1
  95. package/dist/esm/hooks/useAnimationDriver.js.map +0 -7
  96. package/dist/esm/hooks/useFeatures.js +0 -62
  97. package/dist/esm/hooks/useFeatures.js.map +0 -7
  98. package/dist/esm/hooks/useServerContext.js +0 -4
  99. package/dist/esm/hooks/useServerContext.js.map +0 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/core",
3
- "version": "1.0.1-beta.153",
3
+ "version": "1.0.1-beta.156",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -17,7 +17,7 @@
17
17
  "watch": "tamagui-build --watch",
18
18
  "clean": "tamagui-build clean",
19
19
  "clean:build": "tamagui-build clean:build",
20
- "test": "vitest --run --config ../vite-plugin-internal/vite.config.ts"
20
+ "test": "vitest --run --config ../vite-plugin-internal/src/vite.config.ts"
21
21
  },
22
22
  "files": [
23
23
  "types",
@@ -27,14 +27,14 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "@expo/match-media": "^0.3.0",
30
- "@tamagui/compose-refs": "^1.0.1-beta.153",
31
- "@tamagui/helpers": "^1.0.1-beta.153",
32
- "@tamagui/normalize-css-color-lite": "^1.0.1-beta.153",
33
- "@tamagui/rnw": "^1.0.1-beta.153",
34
- "@tamagui/rnw-lite": "^1.0.1-beta.153",
35
- "@tamagui/use-debounce": "^1.0.1-beta.153",
36
- "@tamagui/use-event": "^1.0.1-beta.153",
37
- "@tamagui/use-force-update": "^1.0.1-beta.153",
30
+ "@tamagui/compose-refs": "^1.0.1-beta.156",
31
+ "@tamagui/helpers": "^1.0.1-beta.156",
32
+ "@tamagui/normalize-css-color-lite": "^1.0.1-beta.156",
33
+ "@tamagui/rnw": "^1.0.1-beta.156",
34
+ "@tamagui/rnw-lite": "^1.0.1-beta.156",
35
+ "@tamagui/use-debounce": "^1.0.1-beta.156",
36
+ "@tamagui/use-event": "^1.0.1-beta.156",
37
+ "@tamagui/use-force-update": "^1.0.1-beta.156",
38
38
  "expo-screen-orientation": "^4.3.0",
39
39
  "hyphenate-style-name": "^1.0.4"
40
40
  },
@@ -43,7 +43,7 @@
43
43
  "react-dom": "*"
44
44
  },
45
45
  "devDependencies": {
46
- "@tamagui/build": "^1.0.1-beta.153",
46
+ "@tamagui/build": "^1.0.1-beta.156",
47
47
  "@types/react": "^18.0.15",
48
48
  "csstype": "^3.0.10",
49
49
  "esbuild": "^0.14.49",
@@ -0,0 +1,6 @@
1
+ // for verbose logging outside node/cli
2
+
3
+ export const isDevTools =
4
+ process.env.NODE_ENV === 'development'
5
+ ? new Function('try {return this===window;}catch(e){ return false;}')()
6
+ : false
@@ -22,7 +22,7 @@ import React, {
22
22
  useContext,
23
23
  useEffect,
24
24
  } from 'react'
25
- import { StyleSheet, Text, View, ViewStyle } from 'react-native'
25
+ import { Text, View, ViewStyle } from 'react-native'
26
26
 
27
27
  import { getConfig, onConfiguredOnce } from './config'
28
28
  import { stackDefaultStyles } from './constants/constants'
@@ -31,7 +31,6 @@ import { FontLanguageContext } from './contexts/FontLanguageContext'
31
31
  import { TextAncestorContext } from './contexts/TextAncestorContext'
32
32
  import { assignNativePropsToWeb } from './helpers/assignNativePropsToWeb'
33
33
  import { getReturnVariablesAs } from './helpers/createPropMapper'
34
- import { createShallowUpdate } from './helpers/createShallowUpdate'
35
34
  import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'
36
35
  import {
37
36
  SplitStyleResult,
@@ -42,6 +41,7 @@ import {
42
41
  import { getAllSelectors } from './helpers/insertStyleRule'
43
42
  import { mergeProps } from './helpers/mergeProps'
44
43
  import { proxyThemeVariables } from './helpers/proxyThemeVariables'
44
+ import { useShallowSetState } from './helpers/useShallowSetState'
45
45
  import { addMediaQueryListener, mediaState, removeMediaQueryListener } from './hooks/useMedia'
46
46
  import { usePressable } from './hooks/usePressable'
47
47
  import { useServerRef, useServerState } from './hooks/useServerHooks'
@@ -98,7 +98,6 @@ function mergeShorthands({ defaultProps }: StaticConfigParsed, { shorthands }: T
98
98
 
99
99
  let initialTheme: any
100
100
  let config: TamaguiInternalConfig
101
- let mediaPropNames: string[] = []
102
101
 
103
102
  export function createComponent<
104
103
  ComponentPropTypes extends Object = {},
@@ -120,7 +119,6 @@ export function createComponent<
120
119
  let AnimatedView: any
121
120
  let avoidClasses = true
122
121
  let defaultNativeStyle: any
123
- let defaultNativeStyleSheet: StyleSheet.NamedStyles<{ base: {} }>
124
122
  let tamaguiDefaultProps: any
125
123
  let initialSplitStyles: SplitStyleResult
126
124
 
@@ -180,9 +178,9 @@ export function createComponent<
180
178
  props['debug']
181
179
  )
182
180
 
183
- const hostRef = useServerRef<HTMLElement | View>(null)
181
+ const hostRef = useServerRef<TamaguiElement>(null)
184
182
  const setState = states[1]
185
- const setStateShallow = createShallowUpdate(setState)
183
+ const setStateShallow = useShallowSetState(setState)
186
184
 
187
185
  if (process.env.NODE_ENV === 'development') {
188
186
  if (props['debug']) {
@@ -194,11 +192,17 @@ export function createComponent<
194
192
  // eslint-disable-next-line no-console
195
193
  console.group(`%c 🐛 ${banner}`, 'background: yellow;')
196
194
  // eslint-disable-next-line no-console
197
- console.log('props in', propsIn)
195
+ console.groupCollapsed('initial state')
196
+ // eslint-disable-next-line no-console
197
+ console.log('props', propsIn)
198
+ // eslint-disable-next-line no-console
199
+ console.log('splitStyles', splitStyles)
198
200
  if (typeof window !== 'undefined') {
199
201
  // eslint-disable-next-line no-console
200
202
  console.log('ref', hostRef, '(click to view)')
201
203
  }
204
+ // eslint-disable-next-line no-console
205
+ console.groupEnd()
202
206
  if (props['debug'] === 'break') {
203
207
  // eslint-disable-next-line no-debugger
204
208
  debugger
@@ -610,7 +614,7 @@ export function createComponent<
610
614
  }
611
615
  }
612
616
 
613
- if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
617
+ if (process.env.NODE_ENV === 'development' && !isText && isWeb && !staticConfig.isHOC) {
614
618
  Children.toArray(props.children).forEach((item) => {
615
619
  if (typeof item === 'string') {
616
620
  // eslint-disable-next-line no-console
@@ -619,12 +623,19 @@ export function createComponent<
619
623
  })
620
624
  }
621
625
 
626
+ const unPress = useCallback(() => {
627
+ setStateShallow({
628
+ press: false,
629
+ pressIn: false,
630
+ })
631
+ }, [setStateShallow])
632
+
622
633
  if (!isRSC) {
623
634
  useEffect(() => {
624
635
  return () => {
625
636
  mouseUps.delete(unPress)
626
637
  }
627
- }, [])
638
+ }, [unPress])
628
639
  }
629
640
 
630
641
  let styles: any[]
@@ -638,11 +649,7 @@ export function createComponent<
638
649
  ...medias,
639
650
  }
640
651
  } else {
641
- styles = [
642
- isWeb ? null : defaultNativeStyleSheet ? (defaultNativeStyleSheet.base as ViewStyle) : null,
643
- animationStyles ?? style,
644
- medias,
645
- ]
652
+ styles = [isWeb ? null : defaultNativeStyle, animationStyles ?? style, medias]
646
653
  if (!animationStyles && initialSplitStyles) {
647
654
  const initPseudos = initialSplitStyles.pseudos
648
655
  !state.mounted && addPseudoToStyles(styles, initPseudos, pseudos, 'enterStyle')
@@ -775,13 +782,6 @@ export function createComponent<
775
782
  'onMouseEnter' in props ||
776
783
  'onMouseLeave' in props)))
777
784
 
778
- const unPress = useCallback(() => {
779
- setStateShallow({
780
- press: false,
781
- pressIn: false,
782
- })
783
- }, [])
784
-
785
785
  const events =
786
786
  shouldAttach && !isRSC
787
787
  ? {
@@ -1142,10 +1142,6 @@ export function createComponent<
1142
1142
  }
1143
1143
  }
1144
1144
 
1145
- defaultNativeStyleSheet = StyleSheet.create({
1146
- base: defaultNativeStyle,
1147
- })
1148
-
1149
1145
  if (Object.keys(defaults).length) {
1150
1146
  tamaguiDefaultProps = defaults
1151
1147
  }
@@ -1184,7 +1180,7 @@ export function createComponent<
1184
1180
  Component,
1185
1181
  ...conf,
1186
1182
  neverFlatten: true,
1187
- isExtractable: true,
1183
+ isHOC: true,
1188
1184
  defaultProps: {
1189
1185
  ...Component.defaultProps,
1190
1186
  ...conf?.defaultProps,
@@ -1372,12 +1368,20 @@ function isUnspaced(child: React.ReactNode) {
1372
1368
 
1373
1369
  function AbsoluteFill(props: { children?: any }) {
1374
1370
  return (
1375
- <View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
1371
+ <View pointerEvents="box-none" style={absoluteFill}>
1376
1372
  {props.children}
1377
1373
  </View>
1378
1374
  )
1379
1375
  }
1380
1376
 
1377
+ const absoluteFill = {
1378
+ position: 'absolute',
1379
+ top: 0,
1380
+ left: 0,
1381
+ right: 0,
1382
+ bottom: 0,
1383
+ } as const
1384
+
1381
1385
  // this can be done with CSS entirely right?
1382
1386
  // const shouldWrapTextAncestor = isWeb && isText && !hasTextAncestor
1383
1387
  // if (shouldWrapTextAncestor) {
@@ -1,4 +1,5 @@
1
1
  import { getConfig } from '../config'
2
+ import { isDevTools } from '../constants/isDevTools'
2
3
  import { isWeb } from '../constants/platform'
3
4
  import { Variable, isVariable } from '../createVariable'
4
5
  import {
@@ -380,21 +381,24 @@ const getToken = (
380
381
  }
381
382
  }
382
383
  if (hasSet) {
384
+ if (process.env.NODE_ENV === 'development' && isDevTools && debug === 'verbose') {
385
+ // eslint-disable-next-line no-console
386
+ console.log(` ﹒ propMapper getToken`, key, valOrVar)
387
+ }
383
388
  return getVariableValue(key, valOrVar, resolveAs)
384
389
  }
385
390
  if (process.env.NODE_ENV === 'development') {
386
391
  if (value && value[0] === '$') {
392
+ // eslint-disable-next-line no-console
387
393
  console.trace(
388
394
  `⚠️ You've passed the value "${value}" to the style property "${key}", but there's no theme or token with the key "${value}". Using theme "${theme.name}".
389
395
 
390
396
  Set the debug prop to true to see more detailed debug information.`
391
397
  )
392
398
  if (debug) {
393
- if (typeof window !== 'undefined') {
394
- console.log('Looked in:')
395
- console.log('Theme:', theme)
396
- console.log('Tokens:', tokensParsed)
397
- console.log('Fonts:', fontsParsed)
399
+ if (isDevTools) {
400
+ // eslint-disable-next-line no-console
401
+ console.log('Looked in:', { theme, tokensParsed, fontsParsed })
398
402
  }
399
403
  }
400
404
  return null
@@ -1,8 +1,9 @@
1
1
  import { stylePropsText, stylePropsTransform, validPseudoKeys, validStyles } from '@tamagui/helpers'
2
- import { useInsertionEffect } from 'react'
3
- import { ViewStyle } from 'react-native'
2
+ import { useInsertionEffect, useMemo } from 'react'
3
+ import type { ViewStyle } from 'react-native'
4
4
 
5
5
  import { getConfig } from '../config'
6
+ import { isDevTools } from '../constants/isDevTools'
6
7
  import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from '../constants/platform'
7
8
  import { mediaQueryConfig, mediaState } from '../hooks/useMedia'
8
9
  import type {
@@ -255,6 +256,11 @@ export const getSplitStyles: StyleSplitter = (
255
256
  continue
256
257
  }
257
258
 
259
+ if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
260
+ // eslint-disable-next-line no-console
261
+ console.groupCollapsed(' 🔹 styles', keyInit, valInit)
262
+ }
263
+
258
264
  const expanded =
259
265
  isMedia || isPseudo
260
266
  ? [[keyInit, valInit]]
@@ -271,7 +277,11 @@ export const getSplitStyles: StyleSplitter = (
271
277
 
272
278
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
273
279
  // eslint-disable-next-line no-console
274
- console.log(' 🔹 getSplitStyles', keyInit, valInit, expanded)
280
+ console.log('expanded', expanded)
281
+ // eslint-disable-next-line no-console
282
+ console.log('usedKeys', [...usedKeys])
283
+ // eslint-disable-next-line no-console
284
+ console.groupEnd()
275
285
  }
276
286
 
277
287
  if (!expanded) {
@@ -456,46 +466,49 @@ export const getSplitStyles: StyleSplitter = (
456
466
  style[key] = atomicStyle.value
457
467
  }
458
468
  }
459
- } else {
460
- if (classNames && state.resolveVariablesAs === 'value') {
461
- // getting real values for colors for animations (reverse mapped from CSS)
462
- // this isn't beautiful, but will do relatively fine performance for now
463
- // has a bug still - try adding <Switch theme="bouncy" /> should animate bg color on active
464
- // const selectors = getAllSelectors()
465
- // for (const key in classNames) {
466
- // if (key.endsWith('Color')) {
467
- // const selector = classNames[key]
468
- // let value = selectorValuesCache[selector]
469
- // if (!value) {
470
- // const css = selectors[selector]
471
- // value = css.replace(/.*:/, '').replace(/;.*/, '')
472
- // if (value) {
473
- // const themeUnwrapped = getThemeUnwrapped(theme)
474
- // const map = themeToVariableToValueMap.get(themeUnwrapped)
475
- // if (map && value.startsWith('var(')) {
476
- // value = map[value]
477
- // }
478
- // if (value) {
479
- // selectorValuesCache[selector] = value
480
- // }
481
- // } else {
482
- // // err
483
- // continue
484
- // }
485
- // }
486
- // if (value) {
487
- // style[key] = value
488
- // }
489
- // }
490
- // }
491
- }
492
469
  }
493
470
 
471
+ // else {
472
+ // if (classNames && state.resolveVariablesAs === 'value') {
473
+ // getting real values for colors for animations (reverse mapped from CSS)
474
+ // this isn't beautiful, but will do relatively fine performance for now
475
+ // has a bug still - try adding <Switch theme="bouncy" /> should animate bg color on active
476
+ // const selectors = getAllSelectors()
477
+ // for (const key in classNames) {
478
+ // if (key.endsWith('Color')) {
479
+ // const selector = classNames[key]
480
+ // let value = selectorValuesCache[selector]
481
+ // if (!value) {
482
+ // const css = selectors[selector]
483
+ // value = css.replace(/.*:/, '').replace(/;.*/, '')
484
+ // if (value) {
485
+ // const themeUnwrapped = getThemeUnwrapped(theme)
486
+ // const map = themeToVariableToValueMap.get(themeUnwrapped)
487
+ // if (map && value.startsWith('var(')) {
488
+ // value = map[value]
489
+ // }
490
+ // if (value) {
491
+ // selectorValuesCache[selector] = value
492
+ // }
493
+ // } else {
494
+ // // err
495
+ // continue
496
+ // }
497
+ // }
498
+ // if (value) {
499
+ // style[key] = value
500
+ // }
501
+ // }
502
+ // }
503
+ // }
504
+ // }
505
+
494
506
  if (process.env.TAMAGUI_TARGET === 'web') {
495
507
  if (transforms) {
496
508
  for (const namespace in transforms) {
497
509
  if (!transforms[namespace]) {
498
510
  if (process.env.NODE_ENV === 'development') {
511
+ // eslint-disable-next-line no-console
499
512
  console.warn('Error no transform', transforms, namespace)
500
513
  }
501
514
  continue
@@ -518,10 +531,17 @@ export const getSplitStyles: StyleSplitter = (
518
531
  }
519
532
 
520
533
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
521
- if (typeof document !== 'undefined') {
534
+ if (isDevTools) {
522
535
  // prettier-ignore
523
536
  // eslint-disable-next-line no-console
524
- console.log(' 🔹 getSplitStyles out', { style, pseudos, medias, classNames, viewProps, state, rulesToInsert })
537
+ console.groupCollapsed(' 🔹 styles =>')
538
+ const logs = { style, pseudos, medias, classNames, viewProps, state, rulesToInsert }
539
+ for (const key in logs) {
540
+ // eslint-disable-next-line no-console
541
+ console.log(key, logs[key])
542
+ }
543
+ // eslint-disable-next-line no-console
544
+ console.groupEnd()
525
545
  }
526
546
  }
527
547
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { StyleObject, simpleHash } from '@tamagui/helpers'
7
7
  import hyphenateStyleName from 'hyphenate-style-name'
8
- import { TextStyle, ViewStyle } from 'react-native'
8
+ import type { TextStyle, ViewStyle } from 'react-native'
9
9
 
10
10
  import { getConfig } from '../config'
11
11
  import { TamaguiInternalConfig } from '../types'
@@ -1,5 +1,5 @@
1
1
  import { THEME_CLASSNAME_PREFIX } from '../constants/constants'
2
- import { Variable } from '../createVariable'
2
+ import { Variable, variableToString } from '../createVariable'
3
3
  import { CreateTamaguiProps, ThemeObject } from '../types'
4
4
  import { tokensValueToVariable } from './registerCSSVariable'
5
5
 
@@ -95,7 +95,7 @@ export function getThemeCSSRules({
95
95
  const isDark = themeName.startsWith('dark')
96
96
  cssRuleSets.push(
97
97
  `@media(prefers-color-scheme: ${isDark ? 'dark' : 'light'}) {
98
- body { background:${theme.background}; color: ${theme.color} }
98
+ body { background:${variableToString(theme.background)}; color: ${variableToString(theme.color)} }
99
99
  :root {${vars} }
100
100
  }`
101
101
  )
@@ -1,4 +1,4 @@
1
- import { ViewStyle } from 'react-native'
1
+ import type { ViewStyle } from 'react-native'
2
2
 
3
3
  export const mergeTransform = (obj: ViewStyle, key: string, val: any, backwards = false) => {
4
4
  obj.transform ||= []
@@ -9,7 +9,9 @@ const cache = {}
9
9
 
10
10
  export function normalizeValueWithProperty(value: any, property?: string): any {
11
11
  const cached = cache[value]
12
- if (cached) return cached
12
+ if (cached) {
13
+ return cached
14
+ }
13
15
  let res = value
14
16
  if (
15
17
  process.env.TAMAGUI_TARGET === 'web' &&
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback } from 'react'
2
2
 
3
- export function createShallowUpdate<State extends Object>(
3
+ export function useShallowSetState<State extends Object>(
4
4
  setter: React.Dispatch<React.SetStateAction<State>>
5
5
  ) {
6
6
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -2,6 +2,7 @@ import { useForceUpdate } from '@tamagui/use-force-update'
2
2
  import React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'
3
3
 
4
4
  import { getConfig } from '../config'
5
+ import { isDevTools } from '../constants/isDevTools'
5
6
  import { isRSC, isSSR, useIsomorphicLayoutEffect } from '../constants/platform'
6
7
  import { ThemeContext } from '../contexts/ThemeContext'
7
8
  import { areEqualSets } from '../helpers/areEqualSets'
@@ -55,7 +56,14 @@ export const useTheme = (
55
56
  if (process.env.NODE_ENV === 'development') {
56
57
  if (props?.debug === 'verbose') {
57
58
  // eslint-disable-next-line no-console
58
- console.log(' 🔹 useTheme', { themeName, componentName, name, className })
59
+ console.groupCollapsed(' 🔹 useTheme =>', name)
60
+ const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }
61
+ for (const key in logs) {
62
+ // eslint-disable-next-line no-console
63
+ console.log(' ', key, logs[key])
64
+ }
65
+ // eslint-disable-next-line no-console
66
+ console.groupEnd()
59
67
  }
60
68
  }
61
69
 
@@ -91,7 +99,7 @@ export const useTheme = (
91
99
 
92
100
  return useMemo(() => {
93
101
  return getThemeProxied(theme, name, className, themeManager, state, debugProp)
94
- }, [theme, name, themeManager, className, debugProp])
102
+ }, [theme, name, className, themeManager, state, debugProp])
95
103
  }
96
104
 
97
105
  function getThemeProxied(
@@ -224,20 +232,21 @@ export const useChangeThemeEffect = (
224
232
  return new ThemeManager(next.name, next.theme, parentManager, reset)
225
233
  })
226
234
 
227
- // if not SSR
235
+ // not concurrent safe for now but fixes bug in showing old value
236
+ if (next?.name !== themeManager.name || next?.className !== themeManager.className) {
237
+ themeManager.update(next)
238
+ }
239
+
228
240
  if (!isSSR) {
229
241
  useLayoutEffect(() => {
230
242
  activeThemeManagers.add(themeManager)
231
243
 
232
- if (next?.name) {
233
- themeManager.update(next)
234
- }
235
-
236
244
  const disposeParentOnChange = parentManager.onChangeTheme(() => {
237
245
  const next = parentManager.getNextTheme(getThemeProps, debug)
238
246
  if (!next) return
239
247
  if (themeManager.update(next)) {
240
248
  if (process.env.NODE_ENV === 'development' && debug) {
249
+ // eslint-disable-next-line no-console
241
250
  console.log('Changed theme', componentName, next, { props })
242
251
  }
243
252
  forceUpdate()
package/src/index.ts CHANGED
@@ -22,7 +22,7 @@ export * from './constants/platform'
22
22
  export { createDOMProps } from '@tamagui/rnw'
23
23
 
24
24
  export * from './helpers/calc'
25
- export * from './helpers/createShallowUpdate'
25
+ export * from './helpers/useShallowSetState'
26
26
  export * from './helpers/getStackSize'
27
27
  export * from './helpers/getVariantExtras'
28
28
  export * from './helpers/getAnimationDriver'
package/src/styled.tsx CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  StaticConfig,
11
11
  StylableComponent,
12
12
  TamaguiComponent,
13
+ TamaguiElement,
13
14
  VariantDefinitions,
14
15
  VariantSpreadFunction,
15
16
  } from './types'
@@ -38,6 +39,16 @@ export function styled<
38
39
  const staticConfigProps = (() => {
39
40
  const parentStaticConfig =
40
41
  'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null
42
+
43
+ if (process.env.NODE_ENV === 'development') {
44
+ if (parentStaticConfig?.isHOC) {
45
+ // eslint-disable-next-line no-console
46
+ console.warn(
47
+ `Warning: Parent component is a functional component, not a Tamagui styled() component. Extending with styled() will break and lead to incorrect styles.`
48
+ )
49
+ }
50
+ }
51
+
41
52
  if (options) {
42
53
  const { variants, name, defaultVariants, ...defaultProps } = options
43
54
  if (defaultVariants) {
@@ -63,9 +74,15 @@ export function styled<
63
74
  : null
64
75
  const isTamagui = !isReactNativeWeb && !!parentStaticConfig
65
76
  const Comp = reactNativeWebComponent || (Component as any)
66
- const isImage = !!(defaultProps.isImage || (!isTamagui ? Comp === Image : false))
67
- const isInput = !!(defaultProps.isInput || (!isTamagui ? Comp === TextInput : false))
68
- const isText = !!(defaultProps.isText || (!isTamagui ? isInput || Comp === Text : false))
77
+ const isImage = Boolean(
78
+ staticExtractionOptions?.isImage || parentStaticConfig?.isImage || Comp === Image
79
+ )
80
+ const isInput = Boolean(
81
+ staticExtractionOptions?.isInput || parentStaticConfig?.isInput || Comp === TextInput
82
+ )
83
+ const isText = Boolean(
84
+ isInput || staticExtractionOptions?.isText || parentStaticConfig?.isText || Comp === Text
85
+ )
69
86
 
70
87
  const conf: Partial<StaticConfig> = {
71
88
  ...staticExtractionOptions,
@@ -122,8 +139,7 @@ export function styled<
122
139
 
123
140
  return component as TamaguiComponent<
124
141
  Props,
125
- // TODO infer ref
126
- any,
142
+ TamaguiElement,
127
143
  ParentPropsBase,
128
144
  ParentVariants & OurVariants
129
145
  >
package/src/types.tsx CHANGED
@@ -766,7 +766,7 @@ export type StaticConfig = {
766
766
  /**
767
767
  * Used internally to handle extractable HoC separate
768
768
  */
769
- isExtractable?: boolean
769
+ isHOC?: boolean
770
770
 
771
771
  /**
772
772
  * Used insternally to attach default props to names
@@ -0,0 +1,2 @@
1
+ export declare const isDevTools: any;
2
+ //# sourceMappingURL=isDevTools.d.ts.map
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- export declare function createShallowUpdate<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>): (next: Partial<State>) => void;
2
+ export declare function useShallowSetState<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>): (next: Partial<State>) => void;
3
3
  //# sourceMappingURL=createShallowUpdate.d.ts.map
@@ -1,4 +1,4 @@
1
- import { ViewStyle } from 'react-native';
1
+ import type { ViewStyle } from 'react-native';
2
2
  import type { DebugProp, MediaQueryKey, PseudoStyles, SplitStyleState, StackProps, StaticConfigParsed, TamaguiInternalConfig, ThemeObject } from '../types';
3
3
  import { FontLanguageProps, LanguageContextType } from '../views/FontLanguage.types';
4
4
  import { RulesToInsert } from './insertStyleRule';
@@ -1,5 +1,5 @@
1
1
  import { StyleObject } from '@tamagui/helpers';
2
- import { TextStyle, ViewStyle } from 'react-native';
2
+ import type { TextStyle, ViewStyle } from 'react-native';
3
3
  import { PseudoDescriptor } from './pseudoDescriptors';
4
4
  declare type ViewOrTextStyle = ViewStyle | TextStyle;
5
5
  export declare type ViewStyleWithPseudos = ViewOrTextStyle & {
@@ -1,4 +1,4 @@
1
- import { ViewStyle } from 'react-native';
1
+ import type { ViewStyle } from 'react-native';
2
2
  export declare const mergeTransform: (obj: ViewStyle, key: string, val: any, backwards?: boolean) => void;
3
3
  export declare const invertMapTransformKeys: {
4
4
  translateX: string;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare function useShallowSetState<State extends Object>(setter: React.Dispatch<React.SetStateAction<State>>): (next: Partial<State>) => void;
3
+ //# sourceMappingURL=useShallowSetState.d.ts.map
package/types/index.d.ts CHANGED
@@ -18,7 +18,7 @@ export * from './constants/constants';
18
18
  export * from './constants/platform';
19
19
  export { createDOMProps } from '@tamagui/rnw';
20
20
  export * from './helpers/calc';
21
- export * from './helpers/createShallowUpdate';
21
+ export * from './helpers/useShallowSetState';
22
22
  export * from './helpers/getStackSize';
23
23
  export * from './helpers/getVariantExtras';
24
24
  export * from './helpers/getAnimationDriver';
package/types/styled.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { GetProps, GetVariantValues, MediaProps, PseudoProps, StaticConfig, StylableComponent, TamaguiComponent, VariantDefinitions, VariantSpreadFunction } from './types';
1
+ import { GetProps, GetVariantValues, MediaProps, PseudoProps, StaticConfig, StylableComponent, TamaguiComponent, TamaguiElement, VariantDefinitions, VariantSpreadFunction } from './types';
2
2
  export declare type StyledOptions<ParentComponent extends StylableComponent> = GetProps<ParentComponent> & {
3
3
  name?: string;
4
4
  variants?: VariantDefinitions<ParentComponent> | undefined;
@@ -12,5 +12,5 @@ export declare function styled<ParentComponent extends StylableComponent, Varian
12
12
  defaultVariants?: {
13
13
  [key: string]: any;
14
14
  };
15
- }, staticExtractionOptions?: Partial<StaticConfig>): TamaguiComponent<Variants extends void ? GetProps<ParentComponent> : (ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>) & Omit<ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}, keyof (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })> & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; }) & MediaProps<Partial<(ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>) & Omit<ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}, keyof (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })> & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })>> & PseudoProps<Partial<(ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>) & Omit<ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}, keyof (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })> & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })>>, any, ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>, (ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}) & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })>;
15
+ }, staticExtractionOptions?: Partial<StaticConfig>): TamaguiComponent<Variants extends void ? GetProps<ParentComponent> : (ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>) & Omit<ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}, keyof (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })> & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; }) & MediaProps<Partial<(ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>) & Omit<ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}, keyof (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })> & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })>> & PseudoProps<Partial<(ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>) & Omit<ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}, keyof (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })> & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })>>, TamaguiElement, ParentComponent extends TamaguiComponent<any, any, infer P, {}> ? P : GetProps<ParentComponent>, (ParentComponent extends TamaguiComponent<any, any, any, infer V> ? V : {}) & (Variants extends void ? {} : { [Key in keyof Variants]?: (Variants[Key] extends VariantSpreadFunction<any, infer Val> ? Val : GetVariantValues<keyof Variants[Key]>) | undefined; })>;
16
16
  //# sourceMappingURL=styled.d.ts.map