@tamagui/web 1.46.2 → 1.47.0
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/constants.js +15 -15
- package/dist/cjs/constants/constants.js.map +1 -1
- package/dist/cjs/createComponent.js +83 -106
- package/dist/cjs/createComponent.js.map +1 -1
- package/dist/cjs/createTamagui.js +0 -1
- package/dist/cjs/createTamagui.js.map +1 -1
- package/dist/cjs/helpers/ThemeManager.js +6 -5
- package/dist/cjs/helpers/ThemeManager.js.map +1 -1
- package/dist/cjs/helpers/getSplitStyles.js +75 -98
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +7 -7
- package/dist/cjs/helpers/getStylesAtomic.js.map +1 -1
- package/dist/cjs/helpers/getVariantExtras.js +2 -10
- package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
- package/dist/cjs/helpers/isTamaguiComponent.js +1 -1
- package/dist/cjs/helpers/isTamaguiComponent.js.map +1 -1
- package/dist/cjs/helpers/mergeProps.js +6 -14
- package/dist/cjs/helpers/mergeProps.js.map +1 -1
- package/dist/cjs/helpers/normalizeColor.js +2 -1
- package/dist/cjs/helpers/normalizeColor.js.map +1 -1
- package/dist/cjs/helpers/normalizeValueWithProperty.js +5 -56
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +1 -1
- package/dist/cjs/helpers/{createPropMapper.js → propMapper.js} +63 -139
- package/dist/cjs/helpers/propMapper.js.map +6 -0
- package/dist/cjs/helpers/pseudoDescriptors.js +0 -1
- package/dist/cjs/helpers/pseudoDescriptors.js.map +1 -1
- package/dist/cjs/helpers/useShallowSetState.js +9 -17
- package/dist/cjs/helpers/useShallowSetState.js.map +1 -1
- package/dist/cjs/helpers/withStaticProperties.js +9 -0
- package/dist/cjs/helpers/withStaticProperties.js.map +1 -1
- package/dist/cjs/hooks/useMedia.js +7 -9
- package/dist/cjs/hooks/useMedia.js.map +1 -1
- package/dist/cjs/hooks/useStyle.js +5 -2
- package/dist/cjs/hooks/useStyle.js.map +1 -1
- package/dist/cjs/hooks/useTheme.js +28 -32
- package/dist/cjs/hooks/useTheme.js.map +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/views/Stack.js +1 -4
- package/dist/cjs/views/Stack.js.map +1 -1
- package/dist/cjs/views/Theme.js +2 -2
- package/dist/cjs/views/Theme.js.map +1 -1
- package/dist/cjs/views/ThemeDebug.js +2 -2
- package/dist/cjs/views/ThemeDebug.js.map +1 -1
- package/dist/esm/constants/constants.js +14 -13
- package/dist/esm/constants/constants.js.map +1 -1
- package/dist/esm/createComponent.js +83 -106
- package/dist/esm/createComponent.js.map +1 -1
- package/dist/esm/createTamagui.js +0 -1
- package/dist/esm/createTamagui.js.map +1 -1
- package/dist/esm/helpers/ThemeManager.js +6 -5
- package/dist/esm/helpers/ThemeManager.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +74 -97
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +7 -7
- package/dist/esm/helpers/getStylesAtomic.js.map +1 -1
- package/dist/esm/helpers/getVariantExtras.js +2 -10
- package/dist/esm/helpers/getVariantExtras.js.map +1 -1
- package/dist/esm/helpers/isTamaguiComponent.js +1 -1
- package/dist/esm/helpers/isTamaguiComponent.js.map +1 -1
- package/dist/esm/helpers/mergeProps.js +6 -14
- package/dist/esm/helpers/mergeProps.js.map +1 -1
- package/dist/esm/helpers/normalizeColor.js +2 -1
- package/dist/esm/helpers/normalizeColor.js.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.js +5 -56
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +1 -1
- package/dist/esm/helpers/{createPropMapper.js → propMapper.js} +56 -132
- package/dist/esm/helpers/propMapper.js.map +6 -0
- package/dist/esm/helpers/pseudoDescriptors.js +0 -1
- package/dist/esm/helpers/pseudoDescriptors.js.map +1 -1
- package/dist/esm/helpers/useShallowSetState.js +9 -17
- package/dist/esm/helpers/useShallowSetState.js.map +1 -1
- package/dist/esm/helpers/withStaticProperties.js +9 -0
- package/dist/esm/helpers/withStaticProperties.js.map +1 -1
- package/dist/esm/hooks/useMedia.js +8 -10
- package/dist/esm/hooks/useMedia.js.map +1 -1
- package/dist/esm/hooks/useStyle.js +5 -2
- package/dist/esm/hooks/useStyle.js.map +1 -1
- package/dist/esm/hooks/useTheme.js +28 -32
- package/dist/esm/hooks/useTheme.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/views/Stack.js +1 -4
- package/dist/esm/views/Stack.js.map +1 -1
- package/dist/esm/views/Theme.js +2 -2
- package/dist/esm/views/Theme.js.map +1 -1
- package/dist/esm/views/ThemeDebug.js +2 -2
- package/dist/esm/views/ThemeDebug.js.map +1 -1
- package/package.json +9 -9
- package/src/constants/constants.ts +15 -11
- package/src/createComponent.tsx +143 -140
- package/src/createTamagui.ts +0 -1
- package/src/helpers/ThemeManager.tsx +10 -6
- package/src/helpers/getSplitStyles.tsx +139 -172
- package/src/helpers/getStylesAtomic.ts +7 -7
- package/src/helpers/getVariantExtras.tsx +15 -31
- package/src/helpers/isTamaguiComponent.tsx +3 -3
- package/src/helpers/mergeProps.ts +5 -20
- package/src/helpers/normalizeColor.ts +2 -1
- package/src/helpers/normalizeValueWithProperty.ts +8 -64
- package/src/helpers/{createPropMapper.ts → propMapper.ts} +71 -165
- package/src/helpers/pseudoDescriptors.ts +0 -1
- package/src/helpers/useShallowSetState.tsx +10 -16
- package/src/helpers/withStaticProperties.tsx +13 -0
- package/src/hooks/useMedia.tsx +15 -10
- package/src/hooks/useStyle.tsx +7 -4
- package/src/hooks/useTheme.tsx +36 -47
- package/src/index.ts +1 -1
- package/src/types.tsx +20 -33
- package/src/views/Stack.tsx +1 -4
- package/src/views/Theme.tsx +3 -3
- package/src/views/ThemeDebug.tsx +2 -2
- package/types/constants/constants.d.ts +0 -15
- package/types/constants/constants.d.ts.map +1 -1
- package/types/createComponent.d.ts +5 -8
- package/types/createComponent.d.ts.map +1 -1
- package/types/createTamagui.d.ts.map +1 -1
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts +3 -7
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/getVariantExtras.d.ts +1 -1
- package/types/helpers/getVariantExtras.d.ts.map +1 -1
- package/types/helpers/isTamaguiComponent.d.ts.map +1 -1
- package/types/helpers/mergeProps.d.ts +1 -1
- package/types/helpers/mergeProps.d.ts.map +1 -1
- package/types/helpers/normalizeColor.d.ts.map +1 -1
- package/types/helpers/normalizeValueWithProperty.d.ts.map +1 -1
- package/types/helpers/{createPropMapper.d.ts → propMapper.d.ts} +3 -3
- package/types/helpers/propMapper.d.ts.map +1 -0
- package/types/helpers/pseudoDescriptors.d.ts.map +1 -1
- package/types/helpers/useShallowSetState.d.ts.map +1 -1
- package/types/helpers/withStaticProperties.d.ts.map +1 -1
- package/types/hooks/useMedia.d.ts.map +1 -1
- package/types/hooks/useStyle.d.ts +2 -2
- package/types/hooks/useStyle.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts +7 -13
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/styled.d.ts +1 -1
- package/types/types.d.ts +17 -25
- package/types/types.d.ts.map +1 -1
- package/types/views/Stack.d.ts.map +1 -1
- package/dist/cjs/helpers/createPropMapper.js.map +0 -6
- package/dist/cjs/helpers/parseStaticConfig.js +0 -40
- package/dist/cjs/helpers/parseStaticConfig.js.map +0 -6
- package/dist/cjs/helpers/swapFontFaceOnWeight.js +0 -63
- package/dist/cjs/helpers/swapFontFaceOnWeight.js.map +0 -6
- package/dist/cjs/hooks/useSafeRef.js +0 -59
- package/dist/cjs/hooks/useSafeRef.js.map +0 -6
- package/dist/cjs/hooks/useServerHooks.js +0 -36
- package/dist/cjs/hooks/useServerHooks.js.map +0 -6
- package/dist/esm/helpers/createPropMapper.js.map +0 -6
- package/dist/esm/helpers/parseStaticConfig.js +0 -16
- package/dist/esm/helpers/parseStaticConfig.js.map +0 -6
- package/dist/esm/helpers/swapFontFaceOnWeight.js +0 -39
- package/dist/esm/helpers/swapFontFaceOnWeight.js.map +0 -6
- package/dist/esm/hooks/useSafeRef.js +0 -35
- package/dist/esm/hooks/useSafeRef.js.map +0 -6
- package/dist/esm/hooks/useServerHooks.js +0 -11
- package/dist/esm/hooks/useServerHooks.js.map +0 -6
- package/src/helpers/parseStaticConfig.ts +0 -14
- package/src/hooks/useSafeRef.ts +0 -45
- package/types/helpers/createPropMapper.d.ts.map +0 -1
- package/types/helpers/parseStaticConfig.d.ts +0 -3
- package/types/helpers/parseStaticConfig.d.ts.map +0 -1
- package/types/helpers/swapFontFaceOnWeight.d.ts +0 -4
- package/types/helpers/swapFontFaceOnWeight.d.ts.map +0 -1
- package/types/hooks/useSafeRef.d.ts +0 -4
- package/types/hooks/useSafeRef.d.ts.map +0 -1
- package/types/hooks/useServerHooks.d.ts +0 -4
- package/types/hooks/useServerHooks.d.ts.map +0 -1
package/src/createComponent.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
2
2
|
import { isClient, isServer, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
3
3
|
import { validStyles } from '@tamagui/helpers'
|
|
4
|
+
import { useDidFinishSSR } from '@tamagui/use-did-finish-ssr'
|
|
4
5
|
import React, {
|
|
5
6
|
Children,
|
|
6
7
|
Fragment,
|
|
@@ -9,6 +10,7 @@ import React, {
|
|
|
9
10
|
memo,
|
|
10
11
|
useCallback,
|
|
11
12
|
useContext,
|
|
13
|
+
useEffect,
|
|
12
14
|
useId,
|
|
13
15
|
useRef,
|
|
14
16
|
useState,
|
|
@@ -21,7 +23,6 @@ import { TextAncestorContext } from './contexts/TextAncestorContext'
|
|
|
21
23
|
import { didGetVariableValue, setDidGetVariableValue } from './createVariable'
|
|
22
24
|
import { useSplitStyles } from './helpers/getSplitStyles'
|
|
23
25
|
import { mergeProps } from './helpers/mergeProps'
|
|
24
|
-
import { parseStaticConfig } from './helpers/parseStaticConfig'
|
|
25
26
|
import { proxyThemeVariables } from './helpers/proxyThemeVariables'
|
|
26
27
|
import { themeable } from './helpers/themeable'
|
|
27
28
|
import { useShallowSetState } from './helpers/useShallowSetState'
|
|
@@ -35,7 +36,6 @@ import {
|
|
|
35
36
|
SpaceValue,
|
|
36
37
|
SpacerProps,
|
|
37
38
|
StaticConfig,
|
|
38
|
-
StaticConfigParsed,
|
|
39
39
|
TamaguiComponent,
|
|
40
40
|
TamaguiComponentEvents,
|
|
41
41
|
TamaguiComponentState,
|
|
@@ -48,17 +48,7 @@ import { Slot } from './views/Slot'
|
|
|
48
48
|
import { useThemedChildren } from './views/Theme'
|
|
49
49
|
import { ThemeDebug } from './views/ThemeDebug'
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
// import { timer } from '@tamagui/timer'
|
|
53
|
-
// if (true || process.env.ANALYZE) {
|
|
54
|
-
// t = require().timer()
|
|
55
|
-
// setTimeout(() => {
|
|
56
|
-
// const out = t.print()
|
|
57
|
-
// if (isClient) {
|
|
58
|
-
// alert(out)
|
|
59
|
-
// }
|
|
60
|
-
// }, 2000)
|
|
61
|
-
// }
|
|
51
|
+
const timer = require('@tamagui/timer').timer()
|
|
62
52
|
|
|
63
53
|
// this appears to fix expo / babel not picking this up sometimes? really odd
|
|
64
54
|
process.env.TAMAGUI_TARGET
|
|
@@ -118,9 +108,7 @@ export function createComponent<
|
|
|
118
108
|
ComponentPropTypes extends Object = {},
|
|
119
109
|
Ref = TamaguiElement,
|
|
120
110
|
BaseProps = never
|
|
121
|
-
>(
|
|
122
|
-
const staticConfig = parseStaticConfig(staticConfigIn)
|
|
123
|
-
|
|
111
|
+
>(staticConfig: StaticConfig) {
|
|
124
112
|
onConfiguredOnce((conf) => {
|
|
125
113
|
// one time only setup
|
|
126
114
|
if (!tamaguiConfig) {
|
|
@@ -151,18 +139,22 @@ export function createComponent<
|
|
|
151
139
|
const defaultComponentClassName = `is_${staticConfig.componentName}`
|
|
152
140
|
const defaultProps = staticConfig.defaultProps
|
|
153
141
|
|
|
154
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
142
|
+
if (process.env.NODE_ENV === 'development' && staticConfig.defaultProps?.['debug']) {
|
|
155
143
|
if (process.env.IS_STATIC !== 'is_static') {
|
|
156
144
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
157
145
|
console.log(`🐛 [${staticConfig.componentName || 'Component'}]`, {
|
|
158
146
|
staticConfig,
|
|
159
147
|
defaultProps,
|
|
160
|
-
defaultPropsKeyOrder: Object.keys(defaultProps),
|
|
148
|
+
defaultPropsKeyOrder: defaultProps ? Object.keys(defaultProps) : [],
|
|
161
149
|
})
|
|
162
150
|
}
|
|
163
151
|
}
|
|
164
152
|
|
|
165
153
|
const component = forwardRef<Ref, ComponentPropTypes>((propsIn: any, forwardedRef) => {
|
|
154
|
+
// const shouldTime = staticConfig.defaultProps?.padding === 5
|
|
155
|
+
// let time: any
|
|
156
|
+
// if (shouldTime) time = timer.start()
|
|
157
|
+
|
|
166
158
|
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
167
159
|
// todo this could be moved to a cleaner location
|
|
168
160
|
if (!hasSetupBaseViews) {
|
|
@@ -182,7 +174,6 @@ export function createComponent<
|
|
|
182
174
|
propsIn['data-test-renders']['current'] += 1
|
|
183
175
|
}
|
|
184
176
|
}
|
|
185
|
-
// const time = t.start({ quiet: true })
|
|
186
177
|
|
|
187
178
|
// set variants through context
|
|
188
179
|
// order is after default props but before props
|
|
@@ -197,8 +188,8 @@ export function createComponent<
|
|
|
197
188
|
// because its after default props but before props this annoying amount of checks
|
|
198
189
|
propsIn[key] ||
|
|
199
190
|
propsIn[inverseShorthands[key]] ||
|
|
200
|
-
defaultProps[key] ||
|
|
201
|
-
defaultProps[inverseShorthands[key]]
|
|
191
|
+
defaultProps?.[key] ||
|
|
192
|
+
defaultProps?.[inverseShorthands[key]]
|
|
202
193
|
// if not set, use context
|
|
203
194
|
if (propVal === undefined) {
|
|
204
195
|
if (contextValue) {
|
|
@@ -225,9 +216,8 @@ export function createComponent<
|
|
|
225
216
|
// React inserts default props after your props for some reason...
|
|
226
217
|
// order important so we do loops, you can't just spread because JS does weird things
|
|
227
218
|
let props: any
|
|
228
|
-
|
|
229
219
|
if (curDefaultProps) {
|
|
230
|
-
props = mergeProps(curDefaultProps, propsIn)
|
|
220
|
+
props = mergeProps(curDefaultProps, propsIn)
|
|
231
221
|
} else {
|
|
232
222
|
props = propsIn
|
|
233
223
|
}
|
|
@@ -235,6 +225,8 @@ export function createComponent<
|
|
|
235
225
|
const debugProp = props['debug'] as DebugProp
|
|
236
226
|
const componentName = props.componentName || staticConfig.componentName
|
|
237
227
|
|
|
228
|
+
const isHydrated = useDidFinishSSR()
|
|
229
|
+
|
|
238
230
|
// conditional but if ever true stays true
|
|
239
231
|
// [animated, inversed]
|
|
240
232
|
const stateRef = useRef(
|
|
@@ -246,6 +238,8 @@ export function createComponent<
|
|
|
246
238
|
)
|
|
247
239
|
stateRef.current ||= {}
|
|
248
240
|
|
|
241
|
+
// if (shouldTime) time`stateref`
|
|
242
|
+
|
|
249
243
|
const hostRef = useRef<TamaguiElement>(null)
|
|
250
244
|
|
|
251
245
|
/**
|
|
@@ -259,8 +253,11 @@ export function createComponent<
|
|
|
259
253
|
props.animation || (props.style && hasAnimatedStyleValue(props.style))
|
|
260
254
|
)
|
|
261
255
|
|
|
256
|
+
// disable for now still ssr issues
|
|
257
|
+
const supportsCSSVars = animationsConfig?.supportsCSSVars
|
|
258
|
+
|
|
262
259
|
const willBeAnimated = (() => {
|
|
263
|
-
if (isServer) return false
|
|
260
|
+
if (isServer && !supportsCSSVars) return false
|
|
264
261
|
const curState = stateRef.current
|
|
265
262
|
const next = !!(hasAnimationProp && !isHOC && useAnimations)
|
|
266
263
|
return Boolean(next || curState.hasAnimated)
|
|
@@ -270,19 +267,16 @@ export function createComponent<
|
|
|
270
267
|
const presence = (willBeAnimated && usePresence?.()) || null
|
|
271
268
|
|
|
272
269
|
const hasEnterStyle = !!props.enterStyle
|
|
270
|
+
const needsMount = Boolean((isWeb ? isClient : true) && willBeAnimated)
|
|
273
271
|
|
|
274
|
-
//
|
|
275
|
-
const supportsCSSVariables = false // ?? animationsConfig?.supportsCSSVariables
|
|
276
|
-
|
|
277
|
-
const needsMount = Boolean(
|
|
278
|
-
(isWeb ? willBeAnimated && isClient : true) && willBeAnimated
|
|
279
|
-
)
|
|
272
|
+
// if (shouldTime) time`pre-use-state`
|
|
280
273
|
|
|
281
|
-
const initialState =
|
|
282
|
-
?
|
|
274
|
+
const initialState = willBeAnimated
|
|
275
|
+
? supportsCSSVars
|
|
283
276
|
? defaultComponentStateShouldEnter!
|
|
284
277
|
: defaultComponentState!
|
|
285
278
|
: defaultComponentStateMounted!
|
|
279
|
+
|
|
286
280
|
const states = useState<TamaguiComponentState>(initialState)
|
|
287
281
|
|
|
288
282
|
const state = propsIn.forceStyle
|
|
@@ -293,26 +287,23 @@ export function createComponent<
|
|
|
293
287
|
// TODO performance optimization could avoid useCallback and just have this be setStateShallow(setState, state) at call-sites
|
|
294
288
|
const setStateShallow = useShallowSetState(setState, debugProp, componentName)
|
|
295
289
|
|
|
290
|
+
// if (shouldTime) time`use-state`
|
|
291
|
+
|
|
296
292
|
let isAnimated = willBeAnimated
|
|
297
293
|
|
|
298
|
-
if (willBeAnimated && !
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
let hasHydrated = false
|
|
302
|
-
numRenderedOfType[componentName] ??= 0
|
|
303
|
-
if (willBeAnimated) {
|
|
304
|
-
if (++numRenderedOfType[componentName] > HYDRATION_CUTOFF) {
|
|
305
|
-
hasHydrated = true
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const hasPresenceIsHydrated = presence && hasHydrated
|
|
309
|
-
if (!hasPresenceIsHydrated) {
|
|
310
|
-
if (isAnimated && (isServer || state.unmounted === true)) {
|
|
294
|
+
if (willBeAnimated && !supportsCSSVars) {
|
|
295
|
+
if (!presence && isHydrated) {
|
|
296
|
+
if (isServer || state.unmounted === true) {
|
|
311
297
|
isAnimated = false
|
|
312
298
|
}
|
|
313
299
|
}
|
|
314
300
|
}
|
|
315
301
|
|
|
302
|
+
// once animated, always animated to preserve hooks
|
|
303
|
+
if (willBeAnimated && !stateRef.current.hasAnimated) {
|
|
304
|
+
stateRef.current.hasAnimated = true
|
|
305
|
+
}
|
|
306
|
+
|
|
316
307
|
const componentClassName = props.asChild
|
|
317
308
|
? ''
|
|
318
309
|
: props.componentName
|
|
@@ -322,6 +313,8 @@ export function createComponent<
|
|
|
322
313
|
const languageContext = useContext(FontLanguageContext)
|
|
323
314
|
const isDisabled = props.disabled ?? props.accessibilityState?.disabled
|
|
324
315
|
|
|
316
|
+
// if (shouldTime) time`use-context`
|
|
317
|
+
|
|
325
318
|
const isTaggable = !Component || typeof Component === 'string'
|
|
326
319
|
// default to tag, fallback to component (when both strings)
|
|
327
320
|
const element = isWeb ? (isTaggable ? props.tag || Component : Component) : Component
|
|
@@ -366,6 +359,8 @@ export function createComponent<
|
|
|
366
359
|
const disableThemeProp = props['data-disable-theme']
|
|
367
360
|
const disableTheme = (disableThemeProp && !willBeAnimated) || isHOC
|
|
368
361
|
|
|
362
|
+
// if (shouldTime) time`theme-props`
|
|
363
|
+
|
|
369
364
|
const themeStateProps = {
|
|
370
365
|
name: props.theme,
|
|
371
366
|
componentName,
|
|
@@ -405,17 +400,21 @@ export function createComponent<
|
|
|
405
400
|
)
|
|
406
401
|
// prettier-ignore
|
|
407
402
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
408
|
-
console.log({ props, state, staticConfig, elementType, themeStateProps, styledContext: { contextProps: styledContextProps, overriddenContextProps }, presence, isAnimated, isHOC, hasAnimationProp, useAnimations, propsInOrder: Object.keys(propsIn), propsOrder: Object.keys(props)
|
|
403
|
+
console.log({ props, state, staticConfig, elementType, themeStateProps, styledContext: { contextProps: styledContextProps, overriddenContextProps }, presence, isAnimated, isHOC, hasAnimationProp, useAnimations, propsInOrder: Object.keys(propsIn), propsOrder: Object.keys(props) })
|
|
409
404
|
console.groupEnd()
|
|
410
405
|
}
|
|
411
406
|
}
|
|
412
407
|
}
|
|
413
408
|
|
|
414
|
-
|
|
409
|
+
// if (shouldTime) time`pre-theme-media`
|
|
410
|
+
|
|
411
|
+
const [themeState, theme] = useThemeWithState(themeStateProps)
|
|
415
412
|
|
|
416
413
|
elementType = Component || elementType
|
|
417
414
|
const isStringElement = typeof elementType === 'string'
|
|
418
415
|
|
|
416
|
+
// if (shouldTime) time`theme`
|
|
417
|
+
|
|
419
418
|
const mediaState = useMedia(
|
|
420
419
|
// @ts-ignore, we just pass a stable object so we can get it later with
|
|
421
420
|
// should match to the one used in `setMediaShouldUpdate` below
|
|
@@ -423,6 +422,8 @@ export function createComponent<
|
|
|
423
422
|
debugProp ? { props, staticConfig } : null
|
|
424
423
|
)
|
|
425
424
|
|
|
425
|
+
// if (shouldTime) time`media`
|
|
426
|
+
|
|
426
427
|
setDidGetVariableValue(false)
|
|
427
428
|
|
|
428
429
|
const resolveVariablesAs =
|
|
@@ -434,26 +435,31 @@ export function createComponent<
|
|
|
434
435
|
// temp: once we fix above we can disable this
|
|
435
436
|
const keepStyleSSR = willBeAnimated && animationsConfig?.keepStyleSSR
|
|
436
437
|
|
|
438
|
+
const styleProps = {
|
|
439
|
+
mediaState,
|
|
440
|
+
noClassNames,
|
|
441
|
+
hasTextAncestor,
|
|
442
|
+
resolveVariablesAs,
|
|
443
|
+
isExiting,
|
|
444
|
+
isAnimated,
|
|
445
|
+
keepStyleSSR,
|
|
446
|
+
} as const
|
|
447
|
+
|
|
437
448
|
const splitStyles = useSplitStyles(
|
|
438
449
|
props,
|
|
439
450
|
staticConfig,
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
noClassNames,
|
|
445
|
-
hasTextAncestor,
|
|
446
|
-
resolveVariablesAs,
|
|
447
|
-
isExiting,
|
|
448
|
-
isAnimated,
|
|
449
|
-
keepStyleSSR,
|
|
450
|
-
},
|
|
451
|
+
theme,
|
|
452
|
+
themeState.state.name,
|
|
453
|
+
state,
|
|
454
|
+
styleProps,
|
|
451
455
|
null,
|
|
452
456
|
languageContext || undefined,
|
|
453
457
|
elementType,
|
|
454
458
|
debugProp
|
|
455
459
|
)
|
|
456
460
|
|
|
461
|
+
// if (shouldTime) time`split-styles`
|
|
462
|
+
|
|
457
463
|
stateRef.current.isListeningToTheme = splitStyles.dynamicThemeAccess
|
|
458
464
|
|
|
459
465
|
// only listen for changes if we are using raw theme values or media space, or dynamic media (native)
|
|
@@ -523,21 +529,17 @@ export function createComponent<
|
|
|
523
529
|
style: splitStylesStyle,
|
|
524
530
|
// style: splitStylesStyle,
|
|
525
531
|
presence,
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
},
|
|
530
|
-
theme: themeState.theme,
|
|
532
|
+
componentState: state,
|
|
533
|
+
styleProps,
|
|
534
|
+
theme: themeState.state.theme!,
|
|
531
535
|
pseudos: pseudos || null,
|
|
532
536
|
onDidAnimate: props.onDidAnimate,
|
|
533
537
|
hostRef,
|
|
534
538
|
staticConfig,
|
|
535
539
|
})
|
|
536
540
|
|
|
537
|
-
if (isAnimated) {
|
|
538
|
-
|
|
539
|
-
animationStyles = animations.style
|
|
540
|
-
}
|
|
541
|
+
if (isAnimated && animations) {
|
|
542
|
+
animationStyles = animations.style
|
|
541
543
|
}
|
|
542
544
|
}
|
|
543
545
|
|
|
@@ -569,6 +571,8 @@ export function createComponent<
|
|
|
569
571
|
...nonTamaguiProps
|
|
570
572
|
} = viewPropsIn
|
|
571
573
|
|
|
574
|
+
// if (shouldTime) time`destructure`
|
|
575
|
+
|
|
572
576
|
const disabled = props.accessibilityState?.disabled || props.accessibilityDisabled
|
|
573
577
|
|
|
574
578
|
// these can ultimately be for DOM, react-native-web views, or animated views
|
|
@@ -594,7 +598,7 @@ export function createComponent<
|
|
|
594
598
|
viewProps.ref = useComposedRefs(hostRef as any, forwardedRef)
|
|
595
599
|
|
|
596
600
|
if (process.env.NODE_ENV === 'development') {
|
|
597
|
-
if (!isText && isWeb && !isHOC) {
|
|
601
|
+
if (!isReactNative && !isText && isWeb && !isHOC) {
|
|
598
602
|
Children.toArray(props.children).forEach((item) => {
|
|
599
603
|
// allow newlines because why not its annoying with mdx
|
|
600
604
|
if (typeof item === 'string' && item !== '\n') {
|
|
@@ -606,22 +610,19 @@ export function createComponent<
|
|
|
606
610
|
}
|
|
607
611
|
}
|
|
608
612
|
|
|
613
|
+
// if (shouldTime) time`events-hooks`
|
|
614
|
+
|
|
609
615
|
const unPress = useCallback(() => {
|
|
610
616
|
setStateShallow({
|
|
611
617
|
press: false,
|
|
612
618
|
pressIn: false,
|
|
613
619
|
})
|
|
614
|
-
}, [
|
|
620
|
+
}, [])
|
|
615
621
|
|
|
616
622
|
const shouldSetMounted = needsMount && state.unmounted
|
|
617
623
|
|
|
618
624
|
// combined multiple effects into one for performance so be careful with logic
|
|
619
625
|
useIsomorphicLayoutEffect(() => {
|
|
620
|
-
// once animated, always animated to preserve hooks
|
|
621
|
-
if (willBeAnimated && !stateRef.current.hasAnimated) {
|
|
622
|
-
stateRef.current.hasAnimated = true
|
|
623
|
-
}
|
|
624
|
-
|
|
625
626
|
if (shouldSetMounted) {
|
|
626
627
|
const unmounted =
|
|
627
628
|
state.unmounted === true && hasEnterStyle ? 'should-enter' : false
|
|
@@ -637,50 +638,31 @@ export function createComponent<
|
|
|
637
638
|
}
|
|
638
639
|
}, [shouldSetMounted, state.unmounted])
|
|
639
640
|
|
|
640
|
-
|
|
641
|
-
const avoidStyle = keepStyleSSR && state.unmounted === true
|
|
642
|
-
|
|
643
|
-
if (!avoidStyle) {
|
|
644
|
-
if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {
|
|
645
|
-
styles = {
|
|
646
|
-
...(animationStyles ?? splitStylesStyle),
|
|
647
|
-
}
|
|
648
|
-
} else {
|
|
649
|
-
styles = [animationStyles ?? splitStylesStyle]
|
|
650
|
-
|
|
651
|
-
// ugly but for now...
|
|
652
|
-
if (shouldForcePseudo) {
|
|
653
|
-
const next = {}
|
|
654
|
-
styles.forEach((style) => Object.assign(next, style))
|
|
655
|
-
// @ts-ignore
|
|
656
|
-
Object.assign(splitStyles.style, next)
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
641
|
+
const avoidAnimationStyle = keepStyleSSR && state.unmounted === true
|
|
660
642
|
|
|
661
643
|
let fontFamily = isText
|
|
662
|
-
? splitStyles.fontFamily || staticConfig.defaultProps
|
|
644
|
+
? splitStyles.fontFamily || staticConfig.defaultProps?.fontFamily
|
|
663
645
|
: null
|
|
664
646
|
if (fontFamily && fontFamily[0] === '$') {
|
|
665
647
|
fontFamily = fontFamily.slice(1)
|
|
666
648
|
}
|
|
667
649
|
const fontFamilyClassName = fontFamily ? `font_${fontFamily}` : ''
|
|
668
650
|
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
: '',
|
|
673
|
-
componentName ? componentClassName : '',
|
|
674
|
-
fontFamilyClassName,
|
|
675
|
-
classNames ? Object.values(classNames).join(' ') : '',
|
|
676
|
-
]
|
|
651
|
+
const style = avoidAnimationStyle
|
|
652
|
+
? splitStyles.style
|
|
653
|
+
: animationStyles || splitStyles.style
|
|
677
654
|
|
|
678
|
-
|
|
655
|
+
let className: string | undefined
|
|
679
656
|
|
|
680
657
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
658
|
+
const classList = [
|
|
659
|
+
componentName ? componentClassName : '',
|
|
660
|
+
fontFamilyClassName,
|
|
661
|
+
classNames ? Object.values(classNames).join(' ') : '',
|
|
662
|
+
]
|
|
663
|
+
className = classList.join(' ')
|
|
664
|
+
|
|
665
|
+
if (isAnimatedReactNativeWeb && !avoidAnimationStyle) {
|
|
684
666
|
viewProps.style = style
|
|
685
667
|
} else if (isReactNative) {
|
|
686
668
|
// TODO these shouldn't really return from getSplitStyles when in Native mode
|
|
@@ -689,9 +671,14 @@ export function createComponent<
|
|
|
689
671
|
cnStyles[name] = name
|
|
690
672
|
}
|
|
691
673
|
viewProps.style = [...(Array.isArray(style) ? style : [style]), cnStyles]
|
|
674
|
+
} else {
|
|
675
|
+
viewProps.className = className
|
|
676
|
+
viewProps.style = style
|
|
677
|
+
}
|
|
692
678
|
|
|
679
|
+
// turn debug data- props into dataSet in dev mode
|
|
680
|
+
if (isReactNative) {
|
|
693
681
|
if (process.env.NODE_ENV === 'development') {
|
|
694
|
-
// turn debug data- props into dataSet in dev mode
|
|
695
682
|
Object.keys(viewProps).forEach((key) => {
|
|
696
683
|
if (key.startsWith('data-')) {
|
|
697
684
|
viewProps.dataSet ??= {}
|
|
@@ -700,13 +687,10 @@ export function createComponent<
|
|
|
700
687
|
}
|
|
701
688
|
})
|
|
702
689
|
}
|
|
703
|
-
} else {
|
|
704
|
-
viewProps.className = className
|
|
705
|
-
viewProps.style = style
|
|
706
690
|
}
|
|
707
691
|
} else {
|
|
708
692
|
// native assign styles
|
|
709
|
-
viewProps.style =
|
|
693
|
+
viewProps.style = style
|
|
710
694
|
}
|
|
711
695
|
|
|
712
696
|
const runtimePressStyle = !disabled && noClassNames && pseudos?.pressStyle
|
|
@@ -729,6 +713,8 @@ export function createComponent<
|
|
|
729
713
|
(isWeb && noClassNames && 'hoverStyle' in props)
|
|
730
714
|
)
|
|
731
715
|
|
|
716
|
+
// if (shouldTime) time`events-setup`
|
|
717
|
+
|
|
732
718
|
const events: TamaguiComponentEvents | null =
|
|
733
719
|
shouldAttach && !isDisabled && !asChild
|
|
734
720
|
? {
|
|
@@ -795,22 +781,22 @@ export function createComponent<
|
|
|
795
781
|
}
|
|
796
782
|
: null
|
|
797
783
|
|
|
798
|
-
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
})
|
|
811
|
-
}
|
|
784
|
+
if (process.env.TAMAGUI_TARGET === 'native' && events) {
|
|
785
|
+
// replicating TouchableWithoutFeedback
|
|
786
|
+
Object.assign(events, {
|
|
787
|
+
cancelable: !viewProps.rejectResponderTermination,
|
|
788
|
+
disabled: isDisabled,
|
|
789
|
+
hitSlop: viewProps.hitSlop,
|
|
790
|
+
delayLongPress: viewProps.delayLongPress,
|
|
791
|
+
delayPressIn: viewProps.delayPressIn,
|
|
792
|
+
delayPressOut: viewProps.delayPressOut,
|
|
793
|
+
focusable: viewProps.focusable ?? true,
|
|
794
|
+
minPressDuration: 0,
|
|
795
|
+
})
|
|
812
796
|
}
|
|
813
797
|
|
|
798
|
+
// if (shouldTime) time`events`
|
|
799
|
+
|
|
814
800
|
if (process.env.NODE_ENV === 'development' && debugProp === 'verbose') {
|
|
815
801
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
816
802
|
console.log(`events`, { events, isHoverable, attachPress })
|
|
@@ -826,6 +812,8 @@ export function createComponent<
|
|
|
826
812
|
|
|
827
813
|
const direction = props.spaceDirection || 'both'
|
|
828
814
|
|
|
815
|
+
// if (shouldTime) time`hooks`
|
|
816
|
+
|
|
829
817
|
// since we re-render without changing children often for animations or on mount
|
|
830
818
|
// we memo children here. tested this on the site homepage which has hundreds of components
|
|
831
819
|
// and i see no difference in startup performance, but i do see it memoing often
|
|
@@ -843,13 +831,12 @@ export function createComponent<
|
|
|
843
831
|
|
|
844
832
|
if (asChild) {
|
|
845
833
|
elementType = Slot
|
|
846
|
-
viewProps
|
|
847
|
-
...viewProps,
|
|
834
|
+
Object.assign(viewProps, {
|
|
848
835
|
onPress,
|
|
849
836
|
onLongPress,
|
|
850
837
|
onPressIn,
|
|
851
838
|
onPressOut,
|
|
852
|
-
}
|
|
839
|
+
})
|
|
853
840
|
}
|
|
854
841
|
|
|
855
842
|
content = createElement(elementType, viewProps, content)
|
|
@@ -862,14 +849,12 @@ export function createComponent<
|
|
|
862
849
|
// passPropsToChildren: true,
|
|
863
850
|
})
|
|
864
851
|
|
|
865
|
-
if (process.env.NODE_ENV === 'development') {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
)
|
|
872
|
-
}
|
|
852
|
+
if (process.env.NODE_ENV === 'development' && props['debug'] === 'visualize') {
|
|
853
|
+
content = (
|
|
854
|
+
<ThemeDebug themeState={themeState} themeProps={props}>
|
|
855
|
+
{content}
|
|
856
|
+
</ThemeDebug>
|
|
857
|
+
)
|
|
873
858
|
}
|
|
874
859
|
|
|
875
860
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
@@ -901,7 +886,11 @@ export function createComponent<
|
|
|
901
886
|
if (process.env.NODE_ENV === 'development') {
|
|
902
887
|
if (debugProp) {
|
|
903
888
|
const element = typeof elementType === 'string' ? elementType : 'Component'
|
|
904
|
-
console.groupCollapsed(
|
|
889
|
+
console.groupCollapsed(
|
|
890
|
+
`render <${element} /> with props`,
|
|
891
|
+
initialState,
|
|
892
|
+
willBeAnimated
|
|
893
|
+
)
|
|
905
894
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
906
895
|
console.log('viewProps', viewProps)
|
|
907
896
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
@@ -915,16 +904,28 @@ export function createComponent<
|
|
|
915
904
|
if (typeof window !== 'undefined') {
|
|
916
905
|
// prettier-ignore
|
|
917
906
|
// rome-ignore lint/nursery/noConsoleLog: <explanation>
|
|
918
|
-
console.log({ state, themeState, isAnimated, isAnimatedReactNativeWeb, defaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach,
|
|
907
|
+
console.log({ state, themeState, isAnimated, isAnimatedReactNativeWeb, defaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach, pseudos, content, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, staticConfig, tamaguiConfig, shouldForcePseudo, elementType, initialState })
|
|
919
908
|
}
|
|
920
909
|
console.groupEnd()
|
|
921
910
|
console.groupEnd()
|
|
922
911
|
}
|
|
923
912
|
}
|
|
924
913
|
|
|
914
|
+
// if (shouldTime) {
|
|
915
|
+
// time`rest`
|
|
916
|
+
// setTimeout(() => {
|
|
917
|
+
// if (!hasLogged) {
|
|
918
|
+
// timer.print()
|
|
919
|
+
// }
|
|
920
|
+
// hasLogged = true
|
|
921
|
+
// }, 1000)
|
|
922
|
+
// }
|
|
923
|
+
|
|
925
924
|
return content
|
|
926
925
|
})
|
|
927
926
|
|
|
927
|
+
// let hasLogged = false
|
|
928
|
+
|
|
928
929
|
if (staticConfig.componentName) {
|
|
929
930
|
component.displayName = staticConfig.componentName
|
|
930
931
|
}
|
|
@@ -973,7 +974,9 @@ export function createComponent<
|
|
|
973
974
|
}
|
|
974
975
|
|
|
975
976
|
// for elements to avoid spacing
|
|
976
|
-
export
|
|
977
|
+
export function Unspaced(props: { children?: any }) {
|
|
978
|
+
return props.children
|
|
979
|
+
}
|
|
977
980
|
Unspaced['isUnspaced'] = true
|
|
978
981
|
|
|
979
982
|
// dont used styled() here to avoid circular deps
|
package/src/createTamagui.ts
CHANGED
|
@@ -251,7 +251,6 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
const designSystem = `._ovs-contain {overscroll-behavior:contain;}
|
|
254
|
-
.t_unmounted .t_will-mount {opacity:0;visibility:hidden;}
|
|
255
254
|
.is_Text .is_Text {display:inline-flex;}
|
|
256
255
|
._dsp_contents {display:contents;}
|
|
257
256
|
${themeConfig.cssRuleSets.join(separator)}`
|
|
@@ -28,7 +28,7 @@ export type ThemeManagerState = {
|
|
|
28
28
|
const emptyState: ThemeManagerState = { name: '' }
|
|
29
29
|
|
|
30
30
|
export function getHasThemeUpdatingProps(props: ThemeProps) {
|
|
31
|
-
return props.name || props.componentName || props.inverse || props.reset
|
|
31
|
+
return Boolean(props.name || props.componentName || props.inverse || props.reset)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let uid = 0
|
|
@@ -139,10 +139,10 @@ export class ThemeManager {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
getState(props = this.props, parentManager = this.parentManager) {
|
|
142
|
-
|
|
142
|
+
const next =
|
|
143
143
|
getState(props, parentManager) ||
|
|
144
144
|
(process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)
|
|
145
|
-
|
|
145
|
+
return next
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
_allKeys: Set<string> | null = null
|
|
@@ -155,9 +155,9 @@ export class ThemeManager {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// gets value going up to parents
|
|
158
|
-
getValue(key: string, state
|
|
158
|
+
getValue(key: string, state: ThemeManagerState = this.state) {
|
|
159
159
|
if (!key) return
|
|
160
|
-
let theme =
|
|
160
|
+
let theme = state.theme
|
|
161
161
|
let manager = this as ThemeManager | null
|
|
162
162
|
while (theme && manager) {
|
|
163
163
|
if (key in theme) {
|
|
@@ -334,7 +334,11 @@ function getState(
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
if (
|
|
337
|
+
if (
|
|
338
|
+
process.env.NODE_ENV === 'development' &&
|
|
339
|
+
typeof props.debug === 'string' &&
|
|
340
|
+
typeof window !== 'undefined'
|
|
341
|
+
) {
|
|
338
342
|
console.warn('ThemeManager.getState():', {
|
|
339
343
|
result,
|
|
340
344
|
})
|