@tamagui/core 1.0.1-beta.155 → 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.
- package/dist/cjs/constants/isDevTools.js +29 -0
- package/dist/cjs/constants/isDevTools.js.map +7 -0
- package/dist/cjs/createComponent.js +15 -16
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +6 -5
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/createShallowUpdate.js +3 -3
- package/dist/cjs/helpers/createShallowUpdate.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +14 -6
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js +2 -1
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/useShallowSetState.js +44 -0
- package/dist/cjs/helpers/useShallowSetState.js.map +7 -0
- package/dist/cjs/hooks/useTheme.js +11 -5
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/styled.js +15 -3
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/constants/isDevTools.js +5 -0
- package/dist/esm/constants/isDevTools.js.map +7 -0
- package/dist/esm/createComponent.js +15 -16
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/helpers/createPropMapper.js +6 -5
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/createShallowUpdate.js +2 -2
- package/dist/esm/helpers/createShallowUpdate.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +14 -6
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/normalizeValueWithProperty.js +2 -1
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/useShallowSetState.js +20 -0
- package/dist/esm/helpers/useShallowSetState.js.map +7 -0
- package/dist/esm/hooks/useTheme.js +11 -5
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/styled.js +15 -3
- package/dist/esm/styled.js.map +2 -2
- package/package.json +10 -10
- package/src/constants/isDevTools.ts +6 -0
- package/src/createComponent.tsx +19 -18
- package/src/helpers/createPropMapper.ts +9 -5
- package/src/helpers/getSplitStyles.tsx +57 -37
- package/src/helpers/normalizeValueWithProperty.ts +3 -1
- package/src/helpers/{createShallowUpdate.tsx → useShallowSetState.tsx} +1 -1
- package/src/hooks/useTheme.tsx +16 -7
- package/src/index.ts +1 -1
- package/src/styled.tsx +21 -5
- package/src/types.tsx +1 -1
- package/types/constants/isDevTools.d.ts +2 -0
- package/types/helpers/createShallowUpdate.d.ts +1 -1
- package/types/helpers/useShallowSetState.d.ts +3 -0
- package/types/index.d.ts +1 -1
- package/types/styled.d.ts +2 -2
- package/types/types.d.ts +1 -1
package/src/createComponent.tsx
CHANGED
|
@@ -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
|
-
const mediaPropNames: string[] = []
|
|
102
101
|
|
|
103
102
|
export function createComponent<
|
|
104
103
|
ComponentPropTypes extends Object = {},
|
|
@@ -181,7 +180,7 @@ export function createComponent<
|
|
|
181
180
|
|
|
182
181
|
const hostRef = useServerRef<TamaguiElement>(null)
|
|
183
182
|
const setState = states[1]
|
|
184
|
-
const setStateShallow =
|
|
183
|
+
const setStateShallow = useShallowSetState(setState)
|
|
185
184
|
|
|
186
185
|
if (process.env.NODE_ENV === 'development') {
|
|
187
186
|
if (props['debug']) {
|
|
@@ -193,11 +192,17 @@ export function createComponent<
|
|
|
193
192
|
// eslint-disable-next-line no-console
|
|
194
193
|
console.group(`%c 🐛 ${banner}`, 'background: yellow;')
|
|
195
194
|
// eslint-disable-next-line no-console
|
|
196
|
-
console.
|
|
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)
|
|
197
200
|
if (typeof window !== 'undefined') {
|
|
198
201
|
// eslint-disable-next-line no-console
|
|
199
202
|
console.log('ref', hostRef, '(click to view)')
|
|
200
203
|
}
|
|
204
|
+
// eslint-disable-next-line no-console
|
|
205
|
+
console.groupEnd()
|
|
201
206
|
if (props['debug'] === 'break') {
|
|
202
207
|
// eslint-disable-next-line no-debugger
|
|
203
208
|
debugger
|
|
@@ -609,7 +614,7 @@ export function createComponent<
|
|
|
609
614
|
}
|
|
610
615
|
}
|
|
611
616
|
|
|
612
|
-
if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
|
|
617
|
+
if (process.env.NODE_ENV === 'development' && !isText && isWeb && !staticConfig.isHOC) {
|
|
613
618
|
Children.toArray(props.children).forEach((item) => {
|
|
614
619
|
if (typeof item === 'string') {
|
|
615
620
|
// eslint-disable-next-line no-console
|
|
@@ -618,12 +623,19 @@ export function createComponent<
|
|
|
618
623
|
})
|
|
619
624
|
}
|
|
620
625
|
|
|
626
|
+
const unPress = useCallback(() => {
|
|
627
|
+
setStateShallow({
|
|
628
|
+
press: false,
|
|
629
|
+
pressIn: false,
|
|
630
|
+
})
|
|
631
|
+
}, [setStateShallow])
|
|
632
|
+
|
|
621
633
|
if (!isRSC) {
|
|
622
634
|
useEffect(() => {
|
|
623
635
|
return () => {
|
|
624
636
|
mouseUps.delete(unPress)
|
|
625
637
|
}
|
|
626
|
-
}, [])
|
|
638
|
+
}, [unPress])
|
|
627
639
|
}
|
|
628
640
|
|
|
629
641
|
let styles: any[]
|
|
@@ -669,10 +681,6 @@ export function createComponent<
|
|
|
669
681
|
fontFamily = fontFamily.slice(1)
|
|
670
682
|
}
|
|
671
683
|
|
|
672
|
-
if (props['debug']) {
|
|
673
|
-
console.log('???', fontFamily, isText)
|
|
674
|
-
}
|
|
675
|
-
|
|
676
684
|
const classList = [
|
|
677
685
|
componentName ? componentClassName : '',
|
|
678
686
|
fontFamily ? `font_${fontFamily}` : '',
|
|
@@ -774,13 +782,6 @@ export function createComponent<
|
|
|
774
782
|
'onMouseEnter' in props ||
|
|
775
783
|
'onMouseLeave' in props)))
|
|
776
784
|
|
|
777
|
-
const unPress = useCallback(() => {
|
|
778
|
-
setStateShallow({
|
|
779
|
-
press: false,
|
|
780
|
-
pressIn: false,
|
|
781
|
-
})
|
|
782
|
-
}, [])
|
|
783
|
-
|
|
784
785
|
const events =
|
|
785
786
|
shouldAttach && !isRSC
|
|
786
787
|
? {
|
|
@@ -1179,7 +1180,7 @@ export function createComponent<
|
|
|
1179
1180
|
Component,
|
|
1180
1181
|
...conf,
|
|
1181
1182
|
neverFlatten: true,
|
|
1182
|
-
|
|
1183
|
+
isHOC: true,
|
|
1183
1184
|
defaultProps: {
|
|
1184
1185
|
...Component.defaultProps,
|
|
1185
1186
|
...conf?.defaultProps,
|
|
@@ -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 (
|
|
394
|
-
console
|
|
395
|
-
console.log('
|
|
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'
|
|
2
|
+
import { useInsertionEffect, useMemo } from 'react'
|
|
3
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('
|
|
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 (
|
|
534
|
+
if (isDevTools) {
|
|
522
535
|
// prettier-ignore
|
|
523
536
|
// eslint-disable-next-line no-console
|
|
524
|
-
console.
|
|
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
|
|
|
@@ -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)
|
|
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
|
|
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
|
package/src/hooks/useTheme.tsx
CHANGED
|
@@ -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.
|
|
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,
|
|
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
|
-
//
|
|
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/
|
|
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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Image, Text, TextInput } from 'react-native'
|
|
2
|
+
|
|
1
3
|
import { createComponent } from './createComponent'
|
|
2
4
|
import { RNComponents } from './helpers/RNComponents'
|
|
3
5
|
import {
|
|
@@ -8,6 +10,7 @@ import {
|
|
|
8
10
|
StaticConfig,
|
|
9
11
|
StylableComponent,
|
|
10
12
|
TamaguiComponent,
|
|
13
|
+
TamaguiElement,
|
|
11
14
|
VariantDefinitions,
|
|
12
15
|
VariantSpreadFunction,
|
|
13
16
|
} from './types'
|
|
@@ -36,6 +39,16 @@ export function styled<
|
|
|
36
39
|
const staticConfigProps = (() => {
|
|
37
40
|
const parentStaticConfig =
|
|
38
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
|
+
|
|
39
52
|
if (options) {
|
|
40
53
|
const { variants, name, defaultVariants, ...defaultProps } = options
|
|
41
54
|
if (defaultVariants) {
|
|
@@ -61,10 +74,14 @@ export function styled<
|
|
|
61
74
|
: null
|
|
62
75
|
const isTamagui = !isReactNativeWeb && !!parentStaticConfig
|
|
63
76
|
const Comp = reactNativeWebComponent || (Component as any)
|
|
64
|
-
const isImage = Boolean(
|
|
65
|
-
|
|
77
|
+
const isImage = Boolean(
|
|
78
|
+
staticExtractionOptions?.isImage || parentStaticConfig?.isImage || Comp === Image
|
|
79
|
+
)
|
|
80
|
+
const isInput = Boolean(
|
|
81
|
+
staticExtractionOptions?.isInput || parentStaticConfig?.isInput || Comp === TextInput
|
|
82
|
+
)
|
|
66
83
|
const isText = Boolean(
|
|
67
|
-
isInput ||
|
|
84
|
+
isInput || staticExtractionOptions?.isText || parentStaticConfig?.isText || Comp === Text
|
|
68
85
|
)
|
|
69
86
|
|
|
70
87
|
const conf: Partial<StaticConfig> = {
|
|
@@ -122,8 +139,7 @@ export function styled<
|
|
|
122
139
|
|
|
123
140
|
return component as TamaguiComponent<
|
|
124
141
|
Props,
|
|
125
|
-
|
|
126
|
-
any,
|
|
142
|
+
TamaguiElement,
|
|
127
143
|
ParentPropsBase,
|
|
128
144
|
ParentVariants & OurVariants
|
|
129
145
|
>
|
package/src/types.tsx
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export declare function
|
|
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
|
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/
|
|
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; })>>,
|
|
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
|
package/types/types.d.ts
CHANGED
|
@@ -390,7 +390,7 @@ export declare type StaticConfig = {
|
|
|
390
390
|
reactNativeWebComponent?: any;
|
|
391
391
|
memo?: boolean;
|
|
392
392
|
isTamagui?: boolean;
|
|
393
|
-
|
|
393
|
+
isHOC?: boolean;
|
|
394
394
|
parentNames?: string[];
|
|
395
395
|
};
|
|
396
396
|
export declare type StylableComponent = TamaguiComponent | React.Component | React.ForwardRefExoticComponent<any> | ReactComponentWithRef<any, any> | (new (props: any) => any) | typeof View | typeof Text | typeof TextInput | typeof Image;
|