@tamagui/core 1.0.1-beta.141 → 1.0.1-beta.142
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/Tamagui.js +2 -2
- package/dist/cjs/Tamagui.js.map +2 -2
- package/dist/cjs/addTheme.js +28 -22
- package/dist/cjs/addTheme.js.map +2 -2
- package/dist/cjs/config.js +75 -0
- package/dist/cjs/config.js.map +7 -0
- package/dist/cjs/constants/platform.js +7 -1
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/constants/platform.native.js +62 -0
- package/dist/cjs/constants/platform.native.js.map +7 -0
- package/dist/cjs/createComponent.js +71 -58
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createComponent.server.js +431 -0
- package/dist/cjs/createComponent.server.js.map +7 -0
- package/dist/cjs/createTamagui.js +10 -8
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createVariable.js +6 -12
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariables.js +5 -2
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/RNComponents.js +11 -11
- package/dist/cjs/helpers/RNComponents.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +7 -9
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/assignNativePropsToWeb.js +0 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +3 -3
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/expandStyles.js +4 -4
- package/dist/cjs/helpers/expandStyles.js.map +2 -2
- package/dist/cjs/helpers/getAnimationDriver.js +32 -0
- package/dist/cjs/helpers/getAnimationDriver.js.map +7 -0
- package/dist/cjs/helpers/getExpandedShorthands.js +3 -3
- package/dist/cjs/helpers/getExpandedShorthands.js.map +2 -2
- package/dist/cjs/helpers/getFont.js +1 -1
- package/dist/cjs/helpers/getFont.js.map +2 -2
- package/dist/cjs/helpers/getSize.js +2 -2
- package/dist/cjs/helpers/getSize.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +12 -13
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.js +6 -4
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/getVariantExtras.js +2 -2
- package/dist/cjs/helpers/getVariantExtras.js.map +2 -2
- package/dist/cjs/helpers/normalizeColor.js +2 -2
- package/dist/cjs/helpers/normalizeColor.js.map +2 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/useAnimationDriver.js +2 -0
- package/dist/cjs/helpers/useAnimationDriver.js.map +7 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js +2 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js.map +2 -2
- package/dist/cjs/hooks/useAnimationDriver.js +2 -0
- package/dist/cjs/hooks/useAnimationDriver.js.map +7 -0
- package/dist/cjs/hooks/useFeatures.js +2 -2
- package/dist/cjs/hooks/useFeatures.js.map +2 -2
- package/dist/cjs/hooks/useServerContext.js +21 -0
- package/dist/cjs/hooks/useServerContext.js.map +7 -0
- package/dist/cjs/hooks/useServerHooks.js +36 -0
- package/dist/cjs/hooks/useServerHooks.js.map +7 -0
- package/dist/cjs/hooks/useTheme.js +71 -41
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/injectStyles.js +40 -0
- package/dist/cjs/injectStyles.js.map +7 -0
- package/dist/cjs/insertFont.js +2 -2
- package/dist/cjs/insertFont.js.map +2 -2
- package/dist/cjs/styled.js +11 -1
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/views/TamaguiProvider.js +6 -1
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +9 -5
- package/dist/cjs/views/ThemeProvider.js.map +2 -2
- package/dist/esm/Tamagui.js +1 -1
- package/dist/esm/Tamagui.js.map +1 -1
- package/dist/esm/addTheme.js +27 -21
- package/dist/esm/addTheme.js.map +2 -2
- package/dist/esm/config.js +43 -0
- package/dist/esm/config.js.map +7 -0
- package/dist/esm/constants/platform.js +5 -1
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/constants/platform.native.js +28 -0
- package/dist/esm/constants/platform.native.js.map +7 -0
- package/dist/esm/createComponent.js +71 -60
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createComponent.server.js +408 -0
- package/dist/esm/createComponent.server.js.map +7 -0
- package/dist/esm/createTamagui.js +7 -5
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createVariable.js +6 -12
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariables.js +5 -2
- package/dist/esm/createVariables.js.map +2 -2
- package/dist/esm/helpers/RNComponents.js +11 -8
- package/dist/esm/helpers/RNComponents.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +6 -8
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/assignNativePropsToWeb.js +0 -1
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +2 -2
- package/dist/esm/helpers/createPropMapper.js +2 -2
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/expandStyles.js +3 -3
- package/dist/esm/helpers/expandStyles.js.map +2 -2
- package/dist/esm/helpers/getAnimationDriver.js +8 -0
- package/dist/esm/helpers/getAnimationDriver.js.map +7 -0
- package/dist/esm/helpers/getExpandedShorthands.js +2 -2
- package/dist/esm/helpers/getExpandedShorthands.js.map +2 -2
- package/dist/esm/helpers/getFont.js +1 -1
- package/dist/esm/helpers/getFont.js.map +2 -2
- package/dist/esm/helpers/getSize.js +1 -1
- package/dist/esm/helpers/getSize.js.map +1 -1
- package/dist/esm/helpers/getSplitStyles.js +12 -13
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.js +5 -3
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/getVariantExtras.js +1 -1
- package/dist/esm/helpers/getVariantExtras.js.map +1 -1
- package/dist/esm/helpers/normalizeColor.js +1 -1
- package/dist/esm/helpers/normalizeColor.js.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/useAnimationDriver.js +1 -0
- package/dist/esm/helpers/useAnimationDriver.js.map +7 -0
- package/dist/esm/hooks/getThemeUnwrapped.js +2 -0
- package/dist/esm/hooks/getThemeUnwrapped.js.map +2 -2
- package/dist/esm/hooks/useAnimationDriver.js +1 -0
- package/dist/esm/hooks/useAnimationDriver.js.map +7 -0
- package/dist/esm/hooks/useFeatures.js +1 -1
- package/dist/esm/hooks/useFeatures.js.map +2 -2
- package/dist/esm/hooks/useServerContext.js +4 -0
- package/dist/esm/hooks/useServerContext.js.map +7 -0
- package/dist/esm/hooks/useServerHooks.js +11 -0
- package/dist/esm/hooks/useServerHooks.js.map +7 -0
- package/dist/esm/hooks/useTheme.js +72 -42
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/injectStyles.js +16 -0
- package/dist/esm/injectStyles.js.map +7 -0
- package/dist/esm/insertFont.js +1 -1
- package/dist/esm/insertFont.js.map +1 -1
- package/dist/esm/styled.js +11 -1
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +7 -2
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +9 -5
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/package.json +35 -14
- package/src/Tamagui.ts +1 -1
- package/src/addTheme.ts +33 -21
- package/src/{conf.ts → config.ts} +4 -0
- package/src/constants/platform.native.ts +14 -0
- package/src/constants/platform.ts +12 -1
- package/src/createComponent.tsx +164 -148
- package/src/createTamagui.ts +11 -5
- package/src/createVariable.ts +8 -25
- package/src/createVariables.ts +5 -2
- package/src/helpers/RNComponents.tsx +13 -13
- package/src/helpers/ThemeManager.tsx +15 -12
- package/src/helpers/assignNativePropsToWeb.tsx +0 -1
- package/src/helpers/createPropMapper.ts +2 -2
- package/src/helpers/expandStyles.ts +4 -3
- package/src/helpers/getAnimationDriver.tsx +5 -0
- package/src/helpers/getExpandedShorthands.ts +2 -2
- package/src/helpers/getFont.tsx +1 -1
- package/src/helpers/getSize.ts +1 -1
- package/src/helpers/getSplitStyles.tsx +12 -13
- package/src/helpers/getStylesAtomic.ts +6 -3
- package/src/helpers/getVariantExtras.tsx +2 -2
- package/src/helpers/normalizeColor.ts +1 -1
- package/src/helpers/normalizeValueWithProperty.ts +2 -0
- package/src/hooks/getThemeUnwrapped.tsx +1 -0
- package/src/hooks/useFeatures.tsx +2 -1
- package/src/hooks/useServerHooks.tsx +13 -0
- package/src/hooks/useTheme.tsx +94 -48
- package/src/index.ts +2 -1
- package/src/injectStyles.ts +20 -0
- package/src/insertFont.ts +1 -1
- package/src/styled.tsx +15 -1
- package/src/types.tsx +33 -0
- package/src/views/TamaguiProvider.tsx +11 -4
- package/src/views/ThemeProvider.tsx +9 -6
- package/types/config.d.ts +27 -0
- package/types/constants/platform.d.ts +1 -0
- package/types/constants/platform.native.d.ts +13 -0
- package/types/createComponent.server.d.ts +36 -0
- package/types/createVariable.d.ts +1 -2
- package/types/helpers/RNComponents.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts +2 -8
- package/types/helpers/getAnimationDriver.d.ts +6 -0
- package/types/helpers/useAnimationDriver.d.ts +1 -0
- package/types/hooks/useAnimationDriver.d.ts +1 -0
- package/types/hooks/useServerContext.d.ts +2 -0
- package/types/hooks/useServerHooks.d.ts +4 -0
- package/types/hooks/useTheme.d.ts +5 -21
- package/types/index.d.ts +2 -1
- package/types/injectStyles.d.ts +7 -0
- package/types/types.d.ts +23 -0
- package/types/views/TamaguiProvider.d.ts +1 -1
- package/types/views/ThemeProvider.d.ts +0 -1
package/src/addTheme.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getConfig } from './
|
|
1
|
+
import { getConfig, updateConfig } from './config'
|
|
2
2
|
import { isWeb } from './constants/platform'
|
|
3
3
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
4
4
|
import { ensureThemeVariable, proxyThemeToParents } from './helpers/themes'
|
|
@@ -16,37 +16,49 @@ export function addTheme({
|
|
|
16
16
|
update?: boolean
|
|
17
17
|
}) {
|
|
18
18
|
const config = getConfig()
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
if (process.env.NODE_ENV === 'development') {
|
|
20
|
+
if (!config) {
|
|
21
|
+
throw new Error(`Must run createTamagui once before loading theme`)
|
|
22
|
+
}
|
|
23
|
+
if (!update && config.themes[themeName]) {
|
|
24
|
+
throw new Error(`Already defined theme "${themeName}", use updateTheme to change values`)
|
|
25
|
+
}
|
|
24
26
|
}
|
|
27
|
+
|
|
25
28
|
const theme = { ...themeIn }
|
|
26
29
|
for (const key in theme) {
|
|
27
30
|
ensureThemeVariable(theme, key)
|
|
28
31
|
}
|
|
29
|
-
|
|
30
|
-
config,
|
|
31
|
-
themeName,
|
|
32
|
-
names: [themeName],
|
|
33
|
-
theme,
|
|
34
|
-
})
|
|
32
|
+
|
|
35
33
|
const themeProxied = proxyThemeToParents(themeName, theme, config.themes)
|
|
36
34
|
config.themes[themeName] = themeProxied
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
let cssRules: string[] = []
|
|
37
|
+
|
|
38
|
+
if (isWeb) {
|
|
39
|
+
if (insertCSS) {
|
|
40
|
+
cssRules = getThemeCSSRules({
|
|
41
|
+
config,
|
|
42
|
+
themeName,
|
|
43
|
+
names: [themeName],
|
|
44
|
+
theme,
|
|
45
|
+
})
|
|
46
|
+
const id = `tamagui_theme_style_${themeName}`
|
|
47
|
+
const existing = document.querySelector(`#${id}`)
|
|
48
|
+
const style = document.createElement('style')
|
|
49
|
+
style.id = id
|
|
50
|
+
style.appendChild(document.createTextNode(cssRules.join('\n')))
|
|
51
|
+
document.head.appendChild(style)
|
|
52
|
+
if (existing) {
|
|
53
|
+
existing.parentElement?.removeChild(existing)
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
}
|
|
49
57
|
|
|
58
|
+
updateConfig('themes', { ...config.themes, [themeName]: themeProxied })
|
|
59
|
+
|
|
60
|
+
// trigger updates in components
|
|
61
|
+
|
|
50
62
|
return {
|
|
51
63
|
theme: themeProxied,
|
|
52
64
|
cssRules,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useLayoutEffect } from 'react'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
|
|
4
|
+
export const isAndroid = Platform?.OS === 'android'
|
|
5
|
+
export const isIOS = Platform?.OS === 'ios'
|
|
6
|
+
export const isWeb = false
|
|
7
|
+
export const isWindowDefined = false
|
|
8
|
+
export const isSSR = false
|
|
9
|
+
export const isClient = false
|
|
10
|
+
export const isRSC = false
|
|
11
|
+
export const useIsomorphicLayoutEffect = useLayoutEffect
|
|
12
|
+
export const isChrome = false
|
|
13
|
+
export const isWebTouchable = false
|
|
14
|
+
export const isTouchable = true
|
|
@@ -7,7 +7,18 @@ export const isWeb = process.env.TAMAGUI_TARGET === 'web'
|
|
|
7
7
|
export const isWindowDefined = typeof window !== 'undefined'
|
|
8
8
|
export const isSSR = isWeb && !isWindowDefined
|
|
9
9
|
export const isClient = isWeb && isWindowDefined
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
export const isRSC = process.env.ENABLE_RSC
|
|
12
|
+
? // note this is statically analyzed so no funny business, just access it without optional chaining
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
import.meta.env
|
|
15
|
+
? // @ts-ignore
|
|
16
|
+
import.meta.env.SSR
|
|
17
|
+
: false
|
|
18
|
+
: false
|
|
19
|
+
|
|
20
|
+
const idFn = () => {}
|
|
21
|
+
export const useIsomorphicLayoutEffect = isRSC ? idFn : isSSR ? useEffect : useLayoutEffect
|
|
11
22
|
export const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent || '')
|
|
12
23
|
export const isWebTouchable = isClient && 'ontouchstart' in window
|
|
13
24
|
export const isTouchable = !isWeb || isWebTouchable
|
package/src/createComponent.tsx
CHANGED
|
@@ -20,14 +20,12 @@ import React, {
|
|
|
20
20
|
memo,
|
|
21
21
|
useCallback,
|
|
22
22
|
useContext,
|
|
23
|
-
useRef,
|
|
24
|
-
useState,
|
|
25
23
|
} from 'react'
|
|
26
24
|
import { StyleSheet, Text, View, ViewStyle } from 'react-native'
|
|
27
25
|
|
|
28
|
-
import { getConfig, onConfiguredOnce } from './
|
|
26
|
+
import { getConfig, onConfiguredOnce } from './config'
|
|
29
27
|
import { stackDefaultStyles } from './constants/constants'
|
|
30
|
-
import { isClient, isWeb, useIsomorphicLayoutEffect } from './constants/platform'
|
|
28
|
+
import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from './constants/platform'
|
|
31
29
|
import { FontLanguageContext } from './contexts/FontLanguageContext'
|
|
32
30
|
import { TextAncestorContext } from './contexts/TextAncestorContext'
|
|
33
31
|
import { assignNativePropsToWeb } from './helpers/assignNativePropsToWeb'
|
|
@@ -41,6 +39,7 @@ import { proxyThemeVariables } from './helpers/proxyThemeVariables'
|
|
|
41
39
|
import { useFeatures } from './hooks/useFeatures'
|
|
42
40
|
import { mediaState } from './hooks/useMedia'
|
|
43
41
|
import { usePressable } from './hooks/usePressable'
|
|
42
|
+
import { useServerRef, useServerState } from './hooks/useServerHooks'
|
|
44
43
|
import { getThemeManager, useTheme } from './hooks/useTheme'
|
|
45
44
|
import {
|
|
46
45
|
SpaceDirection,
|
|
@@ -86,7 +85,7 @@ if (typeof document !== 'undefined') {
|
|
|
86
85
|
// mutates
|
|
87
86
|
function mergeShorthands({ defaultProps }: StaticConfigParsed, { shorthands }: TamaguiConfig) {
|
|
88
87
|
// they are defined in correct order already { ...parent, ...child }
|
|
89
|
-
for (const key
|
|
88
|
+
for (const key of Object.keys(defaultProps)) {
|
|
90
89
|
defaultProps[shorthands[key] || key] = defaultProps[key]
|
|
91
90
|
}
|
|
92
91
|
}
|
|
@@ -129,7 +128,6 @@ export function createComponent<
|
|
|
129
128
|
props = propsIn
|
|
130
129
|
}
|
|
131
130
|
|
|
132
|
-
const hostRef = useRef<HTMLElement | View>(null)
|
|
133
131
|
const { Component, isText, isZStack } = staticConfig
|
|
134
132
|
const componentName = props.componentName || staticConfig.componentName
|
|
135
133
|
const componentClassName = props.asChild
|
|
@@ -138,32 +136,12 @@ export function createComponent<
|
|
|
138
136
|
? `is_${props.componentName}`
|
|
139
137
|
: defaultComponentClassName
|
|
140
138
|
|
|
141
|
-
if (process.env.NODE_ENV === 'development') {
|
|
142
|
-
if (props['debug']) {
|
|
143
|
-
const name = `${
|
|
144
|
-
componentName || Component?.displayName || Component?.name || '[Unnamed Component]'
|
|
145
|
-
}`
|
|
146
|
-
const banner = `${name} ${propsIn['data-is'] || ''}`
|
|
147
|
-
// eslint-disable-next-line no-console
|
|
148
|
-
console.group(`%c 🐛 ${banner}`, 'background: yellow;')
|
|
149
|
-
// eslint-disable-next-line no-console
|
|
150
|
-
console.log('props', propsIn)
|
|
151
|
-
// eslint-disable-next-line no-console
|
|
152
|
-
console.log('ref', hostRef, '(click to view)')
|
|
153
|
-
if (props['debug'] === 'break') {
|
|
154
|
-
// eslint-disable-next-line no-debugger
|
|
155
|
-
debugger
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
139
|
const forceUpdate = useForceUpdate()
|
|
140
|
+
config = config || getConfig()
|
|
161
141
|
const theme = useTheme(props.theme, componentName, props, forceUpdate)
|
|
162
|
-
|
|
142
|
+
|
|
143
|
+
const states = useServerState<TamaguiComponentState>(defaultComponentState)
|
|
163
144
|
const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]
|
|
164
|
-
const setState = states[1]
|
|
165
|
-
const setStateShallow = createShallowUpdate(setState)
|
|
166
|
-
const languageContext = useContext(FontLanguageContext)
|
|
167
145
|
|
|
168
146
|
const shouldAvoidClasses = !!(props.animation && avoidClasses)
|
|
169
147
|
const shouldForcePseudo = !!propsIn.forceStyle
|
|
@@ -184,18 +162,46 @@ export function createComponent<
|
|
|
184
162
|
resolveVariablesAs: 'value',
|
|
185
163
|
} as const)
|
|
186
164
|
|
|
165
|
+
const languageContext = isRSC ? null : useContext(FontLanguageContext)
|
|
166
|
+
|
|
187
167
|
const splitStyles = useSplitStyles(
|
|
188
168
|
props,
|
|
189
169
|
staticConfig,
|
|
190
170
|
theme,
|
|
191
171
|
splitStyleState,
|
|
192
|
-
props.asChild ? null : initialSplitStyles
|
|
172
|
+
props.asChild ? null : initialSplitStyles?.classNames,
|
|
193
173
|
languageContext || undefined,
|
|
194
174
|
props['debug']
|
|
195
175
|
)
|
|
196
176
|
|
|
177
|
+
const hostRef = useServerRef<HTMLElement | View>(null)
|
|
178
|
+
const setState = states[1]
|
|
179
|
+
const setStateShallow = createShallowUpdate(setState)
|
|
180
|
+
|
|
181
|
+
if (process.env.NODE_ENV === 'development') {
|
|
182
|
+
if (props['debug']) {
|
|
183
|
+
const name = `${
|
|
184
|
+
componentName || Component?.displayName || Component?.name || '[Unnamed Component]'
|
|
185
|
+
}`
|
|
186
|
+
const type = staticConfig.isReactNativeWeb ? 'rnw' : 'tamagui'
|
|
187
|
+
const banner = `${name} ${propsIn['data-is'] || ''} ${type}`
|
|
188
|
+
// eslint-disable-next-line no-console
|
|
189
|
+
console.group(`%c 🐛 ${banner}`, 'background: yellow;')
|
|
190
|
+
// eslint-disable-next-line no-console
|
|
191
|
+
console.log('props in', propsIn)
|
|
192
|
+
if (typeof window !== 'undefined') {
|
|
193
|
+
// eslint-disable-next-line no-console
|
|
194
|
+
console.log('ref', hostRef, '(click to view)')
|
|
195
|
+
}
|
|
196
|
+
if (props['debug'] === 'break') {
|
|
197
|
+
// eslint-disable-next-line no-debugger
|
|
198
|
+
debugger
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
197
203
|
const { viewProps: viewPropsIn, pseudos, medias, style, classNames } = splitStyles
|
|
198
|
-
const useAnimations = tamaguiConfig
|
|
204
|
+
const useAnimations = tamaguiConfig?.animations?.useAnimations as UseAnimationHook | undefined
|
|
199
205
|
const isAnimated = !!(useAnimations && props.animation)
|
|
200
206
|
const hasEnterStyle = !!props.enterStyle
|
|
201
207
|
|
|
@@ -404,33 +410,34 @@ export function createComponent<
|
|
|
404
410
|
|
|
405
411
|
assignNativePropsToWeb(elementType, viewProps, nonTamaguiProps)
|
|
406
412
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// from react-native-web
|
|
430
|
-
const platformMethodsRef = usePlatformMethods(viewProps)
|
|
413
|
+
if (!isRSC) {
|
|
414
|
+
useElementLayout(hostRef, onLayout)
|
|
415
|
+
|
|
416
|
+
// from react-native-web
|
|
417
|
+
useResponderEvents(hostRef, {
|
|
418
|
+
onMoveShouldSetResponder,
|
|
419
|
+
onMoveShouldSetResponderCapture,
|
|
420
|
+
onResponderEnd,
|
|
421
|
+
onResponderGrant,
|
|
422
|
+
onResponderMove,
|
|
423
|
+
onResponderReject,
|
|
424
|
+
onResponderRelease,
|
|
425
|
+
onResponderStart,
|
|
426
|
+
onResponderTerminate,
|
|
427
|
+
onResponderTerminationRequest,
|
|
428
|
+
onScrollShouldSetResponder,
|
|
429
|
+
onScrollShouldSetResponderCapture,
|
|
430
|
+
onSelectionChangeShouldSetResponder,
|
|
431
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
432
|
+
onStartShouldSetResponder,
|
|
433
|
+
onStartShouldSetResponderCapture,
|
|
434
|
+
})
|
|
431
435
|
|
|
432
|
-
|
|
433
|
-
|
|
436
|
+
// from react-native-web
|
|
437
|
+
const platformMethodsRef = usePlatformMethods(viewProps)
|
|
438
|
+
const setRef = useMergeRefs(hostRef, platformMethodsRef, forwardedRef as any)
|
|
439
|
+
viewProps.ref = setRef
|
|
440
|
+
}
|
|
434
441
|
|
|
435
442
|
if (props.href != undefined && hrefAttrs != undefined) {
|
|
436
443
|
const { download, rel, target } = hrefAttrs
|
|
@@ -498,7 +505,7 @@ export function createComponent<
|
|
|
498
505
|
}
|
|
499
506
|
|
|
500
507
|
// isMounted
|
|
501
|
-
const internal =
|
|
508
|
+
const internal = useServerRef<{ isMounted: boolean; unmountEffects?: Function[] }>()
|
|
502
509
|
if (!internal.current) {
|
|
503
510
|
internal.current = {
|
|
504
511
|
isMounted: true,
|
|
@@ -538,7 +545,7 @@ export function createComponent<
|
|
|
538
545
|
animationStyles ?? style,
|
|
539
546
|
medias,
|
|
540
547
|
]
|
|
541
|
-
if (!animationStyles) {
|
|
548
|
+
if (!animationStyles && initialSplitStyles) {
|
|
542
549
|
const initPseudos = initialSplitStyles.pseudos
|
|
543
550
|
const force = shouldForcePseudo
|
|
544
551
|
!state.mounted && addPseudoToStyles(styles, initPseudos, pseudos, 'enterStyle')
|
|
@@ -586,8 +593,14 @@ export function createComponent<
|
|
|
586
593
|
className,
|
|
587
594
|
id: props.id,
|
|
588
595
|
}
|
|
589
|
-
if (
|
|
590
|
-
|
|
596
|
+
if (process.env.NODE_ENV === 'development') {
|
|
597
|
+
// turn debug data- props into dataSet in dev mode
|
|
598
|
+
Object.keys(viewProps).forEach((key) => {
|
|
599
|
+
if (key.startsWith('data-')) {
|
|
600
|
+
viewProps.dataSet[key.replace('data-', '')] = viewProps[key]
|
|
601
|
+
delete viewProps[key]
|
|
602
|
+
}
|
|
603
|
+
})
|
|
591
604
|
}
|
|
592
605
|
} else {
|
|
593
606
|
viewProps.className = className
|
|
@@ -599,7 +612,7 @@ export function createComponent<
|
|
|
599
612
|
}
|
|
600
613
|
|
|
601
614
|
// TODO need to loop active variants and see if they have matchin pseudos and apply as well
|
|
602
|
-
const initialPseudos = initialSplitStyles
|
|
615
|
+
const initialPseudos = initialSplitStyles?.pseudos
|
|
603
616
|
const attachPress = !!(
|
|
604
617
|
pseudos?.pressStyle ||
|
|
605
618
|
initialPseudos?.pressStyle ||
|
|
@@ -643,86 +656,88 @@ export function createComponent<
|
|
|
643
656
|
})
|
|
644
657
|
}, [])
|
|
645
658
|
|
|
646
|
-
const events =
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
unPress()
|
|
651
|
-
onPressOut?.(e)
|
|
652
|
-
onMouseUp?.(e)
|
|
653
|
-
}
|
|
654
|
-
: undefined,
|
|
655
|
-
...(isHoverable && {
|
|
656
|
-
onMouseEnter: attachHover
|
|
659
|
+
const events =
|
|
660
|
+
shouldAttach && !isRSC
|
|
661
|
+
? {
|
|
662
|
+
[pressOutKey]: attachPress
|
|
657
663
|
? (e) => {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
662
|
-
if (state.pressIn) {
|
|
663
|
-
next.press = true
|
|
664
|
-
}
|
|
665
|
-
if (Object.keys(next).length) {
|
|
666
|
-
setStateShallow(next)
|
|
667
|
-
}
|
|
668
|
-
onHoverIn?.(e)
|
|
669
|
-
onMouseEnter?.(e)
|
|
664
|
+
unPress()
|
|
665
|
+
onPressOut?.(e)
|
|
666
|
+
onMouseUp?.(e)
|
|
670
667
|
}
|
|
671
668
|
: undefined,
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
669
|
+
...(isHoverable && {
|
|
670
|
+
onMouseEnter: attachHover
|
|
671
|
+
? (e) => {
|
|
672
|
+
const next: Partial<typeof state> = {}
|
|
673
|
+
if (attachHover) {
|
|
674
|
+
next.hover = true
|
|
675
|
+
}
|
|
676
|
+
if (state.pressIn) {
|
|
677
|
+
next.press = true
|
|
678
|
+
}
|
|
679
|
+
if (Object.keys(next).length) {
|
|
680
|
+
setStateShallow(next)
|
|
681
|
+
}
|
|
682
|
+
onHoverIn?.(e)
|
|
683
|
+
onMouseEnter?.(e)
|
|
678
684
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
685
|
+
: undefined,
|
|
686
|
+
onMouseLeave: attachHover
|
|
687
|
+
? (e) => {
|
|
688
|
+
const next: Partial<typeof state> = {}
|
|
689
|
+
mouseUps.add(unPress)
|
|
690
|
+
if (attachHover) {
|
|
691
|
+
next.hover = false
|
|
692
|
+
}
|
|
693
|
+
if (state.pressIn) {
|
|
694
|
+
next.press = false
|
|
695
|
+
next.pressIn = false
|
|
696
|
+
}
|
|
697
|
+
if (Object.keys(next).length) {
|
|
698
|
+
setStateShallow(next)
|
|
699
|
+
}
|
|
700
|
+
onHoverOut?.(e)
|
|
701
|
+
onMouseLeave?.(e)
|
|
682
702
|
}
|
|
683
|
-
|
|
684
|
-
|
|
703
|
+
: undefined,
|
|
704
|
+
}),
|
|
705
|
+
[pressInKey]: attachPress
|
|
706
|
+
? (e) => {
|
|
707
|
+
setStateShallow({
|
|
708
|
+
press: true,
|
|
709
|
+
pressIn: true,
|
|
710
|
+
hover: false,
|
|
711
|
+
})
|
|
712
|
+
onPressIn?.(e)
|
|
713
|
+
onMouseDown?.(e)
|
|
714
|
+
if (isWeb) {
|
|
715
|
+
mouseUps.add(unPress)
|
|
685
716
|
}
|
|
686
|
-
onHoverOut?.(e)
|
|
687
|
-
onMouseLeave?.(e)
|
|
688
717
|
}
|
|
689
|
-
:
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
pressIn: true,
|
|
696
|
-
hover: false,
|
|
697
|
-
})
|
|
698
|
-
onPressIn?.(e)
|
|
699
|
-
onMouseDown?.(e)
|
|
700
|
-
if (isWeb) {
|
|
701
|
-
mouseUps.add(unPress)
|
|
718
|
+
: null,
|
|
719
|
+
[pressKey]: attachPress
|
|
720
|
+
? (e) => {
|
|
721
|
+
unPress()
|
|
722
|
+
onClick?.(e)
|
|
723
|
+
onPress?.(e)
|
|
702
724
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
delayPressIn: props.delayPressIn,
|
|
720
|
-
delayPressOut: props.delayPressOut,
|
|
721
|
-
focusable: viewProps.focusable ?? true,
|
|
722
|
-
minPressDuration: 0,
|
|
723
|
-
}),
|
|
724
|
-
}
|
|
725
|
-
: null
|
|
725
|
+
: null,
|
|
726
|
+
|
|
727
|
+
// replicating TouchableWithoutFeedback
|
|
728
|
+
...(!isWeb && {
|
|
729
|
+
cancelable: !props.rejectResponderTermination,
|
|
730
|
+
disabled:
|
|
731
|
+
props.disabled !== null ? props.disabled : props.accessibilityState?.disabled,
|
|
732
|
+
hitSlop: props.hitSlop,
|
|
733
|
+
delayLongPress: props.delayLongPress,
|
|
734
|
+
delayPressIn: props.delayPressIn,
|
|
735
|
+
delayPressOut: props.delayPressOut,
|
|
736
|
+
focusable: viewProps.focusable ?? true,
|
|
737
|
+
minPressDuration: 0,
|
|
738
|
+
}),
|
|
739
|
+
}
|
|
740
|
+
: null
|
|
726
741
|
|
|
727
742
|
let space = spaceProp
|
|
728
743
|
// find space by media query
|
|
@@ -773,7 +788,7 @@ export function createComponent<
|
|
|
773
788
|
}
|
|
774
789
|
|
|
775
790
|
// EVENTS: web
|
|
776
|
-
if (isWeb) {
|
|
791
|
+
if (!isRSC && isWeb) {
|
|
777
792
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
778
793
|
const [pressableProps] = usePressable(
|
|
779
794
|
events
|
|
@@ -841,7 +856,7 @@ export function createComponent<
|
|
|
841
856
|
const isAnimatedRNWView = isAnimated && typeof elementType !== 'string' // assuming for now as reanimated is only driver
|
|
842
857
|
const shouldWrapWithComponentTheme =
|
|
843
858
|
isAnimatedRNWView && getReturnVariablesAs(props, splitStyleState) === 'non-color-value'
|
|
844
|
-
const shouldWrapWithHover = events && attachHover
|
|
859
|
+
const shouldWrapWithHover = Boolean(events || isRSC) && attachHover
|
|
845
860
|
|
|
846
861
|
if (shouldWrapWithHover || shouldWrapWithComponentTheme) {
|
|
847
862
|
const themeClassName = shouldWrapWithComponentTheme ? `${theme.className}` : ''
|
|
@@ -852,10 +867,11 @@ export function createComponent<
|
|
|
852
867
|
style={{
|
|
853
868
|
display: 'contents',
|
|
854
869
|
}}
|
|
855
|
-
{...(
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
870
|
+
{...(events &&
|
|
871
|
+
shouldWrapWithHover && {
|
|
872
|
+
onMouseEnter: events.onMouseEnter,
|
|
873
|
+
onMouseLeave: events.onMouseLeave,
|
|
874
|
+
})}
|
|
859
875
|
>
|
|
860
876
|
{content}
|
|
861
877
|
</span>
|
|
@@ -865,9 +881,9 @@ export function createComponent<
|
|
|
865
881
|
|
|
866
882
|
if (process.env.NODE_ENV === 'development') {
|
|
867
883
|
if (props['debug']) {
|
|
868
|
-
|
|
884
|
+
const element = typeof elementType === 'string' ? elementType : 'Component'
|
|
869
885
|
// eslint-disable-next-line no-console
|
|
870
|
-
console.groupCollapsed(
|
|
886
|
+
console.groupCollapsed(`render <${element} /> with props`, viewProps)
|
|
871
887
|
for (const key in viewProps) {
|
|
872
888
|
// eslint-disable-next-line no-console
|
|
873
889
|
console.log(key, viewProps[key])
|
|
@@ -886,7 +902,7 @@ export function createComponent<
|
|
|
886
902
|
}
|
|
887
903
|
}
|
|
888
904
|
|
|
889
|
-
return features.elements.length ? (
|
|
905
|
+
return !isRSC && features.elements.length ? (
|
|
890
906
|
<>
|
|
891
907
|
{features.elements}
|
|
892
908
|
{content}
|
|
@@ -903,11 +919,9 @@ export function createComponent<
|
|
|
903
919
|
// Once configuration is run and all components are registered
|
|
904
920
|
// get default props + className and analyze styles
|
|
905
921
|
onConfiguredOnce((conf) => {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
return
|
|
910
|
-
}
|
|
922
|
+
// in static mode we just use these to lookup configuration
|
|
923
|
+
// ... we likely want this? need to test
|
|
924
|
+
if (process.env.IS_STATIC === 'is_static') return
|
|
911
925
|
|
|
912
926
|
tamaguiConfig = conf
|
|
913
927
|
|
|
@@ -1077,6 +1091,8 @@ export const Spacer = createComponent<SpacerProps>({
|
|
|
1077
1091
|
validStyles,
|
|
1078
1092
|
defaultProps: {
|
|
1079
1093
|
...stackDefaultStyles,
|
|
1094
|
+
// avoid nesting issues
|
|
1095
|
+
tag: 'span',
|
|
1080
1096
|
size: true,
|
|
1081
1097
|
},
|
|
1082
1098
|
variants: {
|
package/src/createTamagui.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { configListeners, setConfig } from './
|
|
2
|
-
import { isWeb } from './constants/platform'
|
|
1
|
+
import { configListeners, setConfig } from './config'
|
|
2
|
+
import { isRSC, isWeb } from './constants/platform'
|
|
3
3
|
import { createVariables } from './createVariables'
|
|
4
4
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
5
5
|
import { getAllRules } from './helpers/insertStyleRule'
|
|
@@ -41,7 +41,12 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
41
41
|
defaultActive: configIn.mediaQueryDefaultActive,
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
const fontTokens =
|
|
44
|
+
const fontTokens = Object.fromEntries(
|
|
45
|
+
Object.entries(configIn.fonts!).map(([k, v]) => {
|
|
46
|
+
return [k, createVariables(v, 'f', true)]
|
|
47
|
+
})
|
|
48
|
+
)
|
|
49
|
+
|
|
45
50
|
const fontsParsed = (() => {
|
|
46
51
|
const res = {} as typeof fontTokens
|
|
47
52
|
for (const familyName in fontTokens) {
|
|
@@ -139,7 +144,7 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
139
144
|
}
|
|
140
145
|
|
|
141
146
|
// then, generate CSS from de-duped
|
|
142
|
-
if (isWeb) {
|
|
147
|
+
if (isWeb || isRSC) {
|
|
143
148
|
for (const themeName in dedupedThemes) {
|
|
144
149
|
cssRuleSets = [
|
|
145
150
|
...cssRuleSets,
|
|
@@ -183,7 +188,8 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
183
188
|
animations: {} as any,
|
|
184
189
|
media: {},
|
|
185
190
|
...configIn,
|
|
186
|
-
|
|
191
|
+
// vite made this into a function if it wasn't set
|
|
192
|
+
shorthands: { ...shorthands },
|
|
187
193
|
inverseShorthands: shorthands
|
|
188
194
|
? Object.fromEntries(Object.entries(shorthands).map(([k, v]) => [v, k]))
|
|
189
195
|
: {},
|