@tamagui/core 1.0.1-beta.99 → 1.0.1-rc.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/Tamagui.js +12 -6
- package/dist/cjs/Tamagui.js.map +2 -2
- package/dist/cjs/addTheme.js +77 -0
- package/dist/cjs/addTheme.js.map +7 -0
- package/dist/cjs/{conf.js → config.js} +25 -13
- package/dist/cjs/config.js.map +7 -0
- package/dist/cjs/constants/constants.js +16 -23
- package/dist/cjs/constants/constants.js.map +2 -2
- package/dist/cjs/constants/isDevTools.js +37 -0
- package/dist/cjs/constants/isDevTools.js.map +7 -0
- package/dist/cjs/constants/platform.js +16 -9
- 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/contexts/ButtonInsideButtonContext.js +1 -0
- package/dist/cjs/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/cjs/contexts/ButtonNestingContext.js +30 -0
- package/dist/cjs/contexts/ButtonNestingContext.js.map +7 -0
- package/dist/cjs/contexts/FontLanguageContext.js +30 -0
- package/dist/cjs/contexts/FontLanguageContext.js.map +7 -0
- package/dist/cjs/contexts/TextAncestorContext.js +30 -0
- package/dist/cjs/contexts/TextAncestorContext.js.map +7 -0
- package/dist/cjs/{ThemeContext.js → contexts/ThemeContext.js} +1 -0
- package/dist/cjs/contexts/ThemeContext.js.map +7 -0
- package/dist/cjs/createComponent.js +583 -644
- package/dist/cjs/createComponent.js.map +3 -3
- package/dist/cjs/createFont.js +39 -19
- package/dist/cjs/createFont.js.map +2 -2
- package/dist/cjs/createFont.test.js +125 -0
- package/dist/cjs/createFont.test.js.map +7 -0
- package/dist/cjs/createShorthands.js +1 -0
- package/dist/cjs/createShorthands.js.map +2 -2
- package/dist/cjs/createTamagui.js +98 -193
- package/dist/cjs/createTamagui.js.map +3 -3
- package/dist/cjs/createTheme.js +1 -0
- package/dist/cjs/createTheme.js.map +2 -2
- package/dist/cjs/createTokens.js +1 -4
- package/dist/cjs/createTokens.js.map +2 -2
- package/dist/cjs/createTokens.test.js +27 -0
- package/dist/cjs/createTokens.test.js.map +7 -0
- package/dist/cjs/createVariable.js +36 -40
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariable.test.js +7 -0
- package/dist/cjs/createVariable.test.js.map +7 -0
- package/dist/cjs/createVariables.js +15 -19
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/RNComponents.js +12 -11
- package/dist/cjs/helpers/RNComponents.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +230 -0
- package/dist/cjs/helpers/ThemeManager.js.map +7 -0
- package/dist/cjs/helpers/ThemeManager.test.js +465 -0
- package/dist/cjs/helpers/ThemeManager.test.js.map +7 -0
- package/dist/cjs/helpers/ThemeManagerContext.js +30 -0
- package/dist/cjs/helpers/ThemeManagerContext.js.map +7 -0
- package/dist/cjs/helpers/areEqualSets.js +1 -0
- package/dist/cjs/helpers/areEqualSets.js.map +1 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.js +1 -0
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.native.js +1 -0
- package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/cjs/helpers/cache.js +43 -0
- package/dist/cjs/helpers/cache.js.map +7 -0
- package/dist/cjs/helpers/calc.js +1 -0
- package/dist/cjs/helpers/calc.js.map +3 -3
- package/dist/cjs/helpers/createMediaStyle.js +23 -9
- package/dist/cjs/helpers/createMediaStyle.js.map +2 -2
- package/dist/cjs/helpers/createPropMapper.js +185 -57
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/createProxy.js +43 -0
- package/dist/cjs/helpers/createProxy.js.map +7 -0
- package/dist/cjs/helpers/createShallowUpdate.js +13 -23
- package/dist/cjs/helpers/createShallowUpdate.js.map +2 -2
- package/dist/cjs/helpers/expandStyle.js +9 -30
- package/dist/cjs/helpers/expandStyle.js.map +3 -3
- package/dist/cjs/helpers/expandStyles.js +26 -37
- package/dist/cjs/helpers/expandStyles.js.map +2 -2
- package/dist/cjs/helpers/extendStaticConfig.js +35 -34
- package/dist/cjs/helpers/extendStaticConfig.js.map +2 -2
- package/dist/cjs/helpers/fixNativeShadow.js +1 -0
- package/dist/cjs/helpers/fixNativeShadow.js.map +1 -1
- package/dist/cjs/helpers/getAnimationDriver.js +32 -0
- package/dist/cjs/helpers/getAnimationDriver.js.map +7 -0
- package/dist/cjs/helpers/getBoundingClientRect.js +37 -0
- package/dist/cjs/helpers/getBoundingClientRect.js.map +7 -0
- package/dist/cjs/helpers/getExpandedShorthands.js +4 -3
- package/dist/cjs/helpers/getExpandedShorthands.js.map +2 -2
- package/dist/cjs/helpers/getFont.js +7 -2
- package/dist/cjs/helpers/getFont.js.map +2 -2
- package/dist/cjs/helpers/getFontLanguage.js +29 -0
- package/dist/cjs/helpers/getFontLanguage.js.map +7 -0
- package/dist/cjs/helpers/getRect.js +36 -0
- package/dist/cjs/helpers/getRect.js.map +7 -0
- package/dist/cjs/helpers/getSize.js +3 -2
- package/dist/cjs/helpers/getSize.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +538 -228
- package/dist/cjs/helpers/getSplitStyles.js.map +3 -3
- package/dist/cjs/helpers/getStackSize.js +1 -0
- package/dist/cjs/helpers/getStackSize.js.map +1 -1
- package/dist/cjs/helpers/getStylesAtomic.js +53 -65
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/getStylesAtomic.native.js +1 -0
- package/dist/cjs/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/cjs/helpers/getThemeCSSRules.js +107 -0
- package/dist/cjs/helpers/getThemeCSSRules.js.map +7 -0
- package/dist/cjs/helpers/getThemeCSSRules.native.js +31 -0
- package/dist/cjs/helpers/getThemeCSSRules.native.js.map +7 -0
- package/dist/cjs/helpers/getVariantExtras.js +50 -7
- package/dist/cjs/helpers/getVariantExtras.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +53 -28
- package/dist/cjs/helpers/insertStyleRule.js.map +3 -3
- package/dist/cjs/helpers/isObj.js +1 -0
- package/dist/cjs/helpers/isObj.js.map +1 -1
- package/dist/cjs/helpers/isTamaguiComponent.js +1 -0
- package/dist/cjs/helpers/isTamaguiComponent.js.map +2 -2
- package/dist/cjs/helpers/isTamaguiElement.js +1 -0
- package/dist/cjs/helpers/isTamaguiElement.js.map +2 -2
- package/dist/cjs/helpers/matchMedia.js +7 -5
- package/dist/cjs/helpers/matchMedia.js.map +2 -2
- package/dist/cjs/helpers/matchMedia.native.js +5 -1
- package/dist/cjs/helpers/matchMedia.native.js.map +2 -2
- package/dist/cjs/helpers/mergeProps.js +19 -14
- package/dist/cjs/helpers/mergeProps.js.map +2 -2
- package/dist/cjs/helpers/mergeTransform.js +12 -8
- package/dist/cjs/helpers/mergeTransform.js.map +2 -2
- package/dist/cjs/helpers/normalizeColor.js +5 -1
- package/dist/cjs/helpers/normalizeColor.js.map +2 -2
- package/dist/cjs/helpers/normalizeValueWithProperty.js +47 -5
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/proxyThemeVariables.js +3 -1
- package/dist/cjs/helpers/proxyThemeVariables.js.map +2 -2
- package/dist/cjs/helpers/pseudoDescriptors.js +12 -0
- package/dist/cjs/helpers/pseudoDescriptors.js.map +2 -2
- package/dist/cjs/helpers/registerCSSVariable.js +8 -8
- package/dist/cjs/helpers/registerCSSVariable.js.map +2 -2
- package/dist/cjs/{constants/rnw.js → helpers/startTransition.js} +13 -9
- package/dist/cjs/helpers/startTransition.js.map +7 -0
- package/dist/cjs/helpers/themeable.js +17 -43
- package/dist/cjs/helpers/themeable.js.map +3 -3
- package/dist/cjs/helpers/themes.js +79 -0
- package/dist/cjs/helpers/themes.js.map +7 -0
- package/dist/cjs/{constants/rnw.native.js → helpers/timer.js} +14 -7
- package/dist/cjs/helpers/timer.js.map +7 -0
- package/dist/cjs/helpers/useShallowSetState.js +49 -0
- package/dist/cjs/helpers/useShallowSetState.js.map +7 -0
- package/dist/cjs/helpers/validate.js +1 -124
- package/dist/cjs/helpers/validate.js.map +3 -3
- package/dist/cjs/helpers/withStaticProperties.js +1 -0
- package/dist/cjs/helpers/withStaticProperties.js.map +1 -1
- package/dist/cjs/hooks/getThemeUnwrapped.js +37 -0
- package/dist/cjs/hooks/getThemeUnwrapped.js.map +7 -0
- package/dist/cjs/hooks/useConstant.js +4 -0
- package/dist/cjs/hooks/useConstant.js.map +2 -2
- package/dist/cjs/hooks/useElementLayout.js +84 -0
- package/dist/cjs/hooks/useElementLayout.js.map +7 -0
- package/dist/cjs/hooks/useId.js +3 -32
- package/dist/cjs/hooks/useId.js.map +2 -2
- package/dist/cjs/hooks/useIsMounted.js +1 -0
- package/dist/cjs/hooks/useIsMounted.js.map +1 -1
- package/dist/cjs/hooks/useIsSSR.js +46 -0
- package/dist/cjs/hooks/useIsSSR.js.map +7 -0
- package/dist/cjs/hooks/useIsTouchDevice.js +4 -9
- package/dist/cjs/hooks/useIsTouchDevice.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +165 -120
- package/dist/cjs/hooks/useMedia.js.map +3 -3
- package/dist/cjs/hooks/usePressable.js +2 -15
- package/dist/cjs/hooks/usePressable.js.map +1 -1
- package/dist/cjs/hooks/useSafeRef.js +58 -0
- package/dist/cjs/hooks/useSafeRef.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 +182 -163
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/hooks/useThemeName.js +52 -0
- package/dist/cjs/hooks/useThemeName.js.map +7 -0
- package/dist/cjs/hooks/useUnmountEffect.js +1 -0
- package/dist/cjs/hooks/useUnmountEffect.js.map +1 -1
- package/dist/cjs/index.js +41 -30
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/inject-styles.js +40 -0
- package/dist/cjs/inject-styles.js.map +7 -0
- package/dist/cjs/injectStyles.js +40 -0
- package/dist/cjs/injectStyles.js.map +7 -0
- package/dist/cjs/insertFont.js +19 -15
- package/dist/cjs/insertFont.js.map +2 -2
- package/dist/cjs/setupReactNative.js +50 -0
- package/dist/cjs/setupReactNative.js.map +7 -0
- package/dist/cjs/static.js +2 -17
- package/dist/cjs/static.js.map +2 -2
- package/dist/cjs/styled.js +30 -49
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types-rnw.js +1 -0
- package/dist/cjs/types-rnw.js.map +1 -1
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/{helpers/cssHash.js → updateTheme.js} +23 -26
- package/dist/cjs/updateTheme.js.map +7 -0
- package/dist/cjs/{Pressability.js → vendor/Pressability.js} +6 -2
- package/dist/cjs/vendor/Pressability.js.map +7 -0
- package/dist/cjs/{Pressability.native.js → vendor/Pressability.native.js} +6 -2
- package/dist/cjs/vendor/Pressability.native.js.map +7 -0
- package/dist/cjs/views/FontLanguage.js +38 -0
- package/dist/cjs/views/FontLanguage.js.map +7 -0
- package/dist/cjs/views/FontLanguage.native.js +38 -0
- package/dist/cjs/views/FontLanguage.native.js.map +7 -0
- package/dist/cjs/{helpers/nativeGestureHandler.native.js → views/FontLanguage.types.js} +4 -5
- package/dist/cjs/views/FontLanguage.types.js.map +7 -0
- package/dist/cjs/views/Slot.js +49 -52
- package/dist/cjs/views/Slot.js.map +2 -2
- package/dist/cjs/views/Stack.js +4 -19
- package/dist/cjs/views/Stack.js.map +2 -2
- package/dist/cjs/views/TamaguiProvider.js +83 -0
- package/dist/cjs/views/TamaguiProvider.js.map +7 -0
- package/dist/cjs/views/Text.js +32 -29
- package/dist/cjs/views/Text.js.map +2 -2
- package/dist/cjs/views/Theme.js +55 -23
- package/dist/cjs/views/Theme.js.map +3 -3
- package/dist/cjs/views/ThemeInverse.js +22 -20
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +14 -27
- package/dist/cjs/views/ThemeProvider.js.map +3 -3
- package/dist/cjs/views/ThemeReset.js +11 -5
- package/dist/cjs/views/ThemeReset.js.map +3 -3
- package/dist/esm/Tamagui.js +7 -5
- package/dist/esm/Tamagui.js.map +2 -2
- package/dist/esm/addTheme.js +53 -0
- package/dist/esm/addTheme.js.map +7 -0
- package/dist/esm/{conf.js → config.js} +18 -8
- package/dist/esm/config.js.map +7 -0
- package/dist/esm/constants/constants.js +13 -24
- package/dist/esm/constants/constants.js.map +2 -2
- package/dist/esm/constants/isDevTools.js +13 -0
- package/dist/esm/constants/isDevTools.js.map +7 -0
- package/dist/esm/constants/platform.js +11 -7
- 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/contexts/ButtonInsideButtonContext.js +0 -0
- package/dist/esm/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/esm/contexts/ButtonNestingContext.js +6 -0
- package/dist/esm/contexts/ButtonNestingContext.js.map +7 -0
- package/dist/esm/contexts/FontLanguageContext.js +6 -0
- package/dist/esm/contexts/FontLanguageContext.js.map +7 -0
- package/dist/esm/contexts/TextAncestorContext.js +6 -0
- package/dist/esm/contexts/TextAncestorContext.js.map +7 -0
- package/dist/esm/{ThemeContext.js → contexts/ThemeContext.js} +0 -0
- package/dist/esm/contexts/ThemeContext.js.map +7 -0
- package/dist/esm/createComponent.js +583 -648
- package/dist/esm/createComponent.js.map +3 -3
- package/dist/esm/createFont.js +38 -19
- package/dist/esm/createFont.js.map +2 -2
- package/dist/esm/createFont.test.js +124 -0
- package/dist/esm/createFont.test.js.map +7 -0
- package/dist/esm/createShorthands.js +0 -0
- package/dist/esm/createShorthands.js.map +2 -2
- package/dist/esm/createTamagui.js +95 -192
- package/dist/esm/createTamagui.js.map +3 -3
- package/dist/esm/createTheme.js +0 -0
- package/dist/esm/createTheme.js.map +2 -2
- package/dist/esm/createTokens.js +0 -4
- package/dist/esm/createTokens.js.map +2 -2
- package/dist/esm/createTokens.test.js +26 -0
- package/dist/esm/createTokens.test.js.map +7 -0
- package/dist/esm/createVariable.js +32 -38
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariable.test.js +6 -0
- package/dist/esm/createVariable.test.js.map +7 -0
- package/dist/esm/createVariables.js +14 -19
- 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 +186 -0
- package/dist/esm/helpers/ThemeManager.js.map +7 -0
- package/dist/esm/helpers/ThemeManager.test.js +464 -0
- package/dist/esm/helpers/ThemeManager.test.js.map +7 -0
- package/dist/esm/helpers/ThemeManagerContext.js +6 -0
- package/dist/esm/helpers/ThemeManagerContext.js.map +7 -0
- package/dist/esm/helpers/areEqualSets.js +0 -0
- package/dist/esm/helpers/areEqualSets.js.map +0 -0
- package/dist/esm/helpers/assignNativePropsToWeb.js +0 -0
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/esm/helpers/assignNativePropsToWeb.native.js +0 -0
- package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/esm/helpers/cache.js +18 -0
- package/dist/esm/helpers/cache.js.map +7 -0
- package/dist/esm/helpers/calc.js +0 -0
- package/dist/esm/helpers/calc.js.map +3 -3
- package/dist/esm/helpers/createMediaStyle.js +22 -9
- package/dist/esm/helpers/createMediaStyle.js.map +2 -2
- package/dist/esm/helpers/createPropMapper.js +180 -55
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/createProxy.js +19 -0
- package/dist/esm/helpers/createProxy.js.map +7 -0
- package/dist/esm/helpers/createShallowUpdate.js +12 -25
- package/dist/esm/helpers/createShallowUpdate.js.map +2 -2
- package/dist/esm/helpers/expandStyle.js +8 -32
- package/dist/esm/helpers/expandStyle.js.map +3 -3
- package/dist/esm/helpers/expandStyles.js +25 -39
- package/dist/esm/helpers/expandStyles.js.map +2 -2
- package/dist/esm/helpers/extendStaticConfig.js +34 -36
- package/dist/esm/helpers/extendStaticConfig.js.map +2 -2
- package/dist/esm/helpers/fixNativeShadow.js +0 -0
- package/dist/esm/helpers/fixNativeShadow.js.map +0 -0
- package/dist/esm/helpers/getAnimationDriver.js +8 -0
- package/dist/esm/helpers/getAnimationDriver.js.map +7 -0
- package/dist/esm/helpers/getBoundingClientRect.js +13 -0
- package/dist/esm/helpers/getBoundingClientRect.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 +6 -2
- package/dist/esm/helpers/getFont.js.map +2 -2
- package/dist/esm/helpers/getFontLanguage.js +5 -0
- package/dist/esm/helpers/getFontLanguage.js.map +7 -0
- package/dist/esm/helpers/getRect.js +12 -0
- package/dist/esm/helpers/getRect.js.map +7 -0
- package/dist/esm/helpers/getSize.js +2 -2
- package/dist/esm/helpers/getSize.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +551 -229
- package/dist/esm/helpers/getSplitStyles.js.map +3 -3
- package/dist/esm/helpers/getStackSize.js +0 -0
- package/dist/esm/helpers/getStackSize.js.map +1 -1
- package/dist/esm/helpers/getStylesAtomic.js +49 -59
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/getStylesAtomic.native.js +0 -0
- package/dist/esm/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/esm/helpers/getThemeCSSRules.js +83 -0
- package/dist/esm/helpers/getThemeCSSRules.js.map +7 -0
- package/dist/esm/helpers/getThemeCSSRules.native.js +7 -0
- package/dist/esm/helpers/getThemeCSSRules.native.js.map +7 -0
- package/dist/esm/helpers/getVariantExtras.js +47 -6
- package/dist/esm/helpers/getVariantExtras.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +48 -25
- package/dist/esm/helpers/insertStyleRule.js.map +3 -3
- package/dist/esm/helpers/isObj.js +0 -0
- package/dist/esm/helpers/isObj.js.map +0 -0
- package/dist/esm/helpers/isTamaguiComponent.js +0 -0
- package/dist/esm/helpers/isTamaguiComponent.js.map +2 -2
- package/dist/esm/helpers/isTamaguiElement.js +0 -0
- package/dist/esm/helpers/isTamaguiElement.js.map +2 -2
- package/dist/esm/helpers/matchMedia.js +6 -5
- package/dist/esm/helpers/matchMedia.js.map +2 -2
- package/dist/esm/helpers/matchMedia.native.js +0 -0
- package/dist/esm/helpers/matchMedia.native.js.map +1 -1
- package/dist/esm/helpers/mergeProps.js +18 -14
- package/dist/esm/helpers/mergeProps.js.map +2 -2
- package/dist/esm/helpers/mergeTransform.js +8 -6
- package/dist/esm/helpers/mergeTransform.js.map +2 -2
- package/dist/esm/helpers/normalizeColor.js +0 -0
- package/dist/esm/helpers/normalizeColor.js.map +1 -1
- package/dist/esm/helpers/normalizeValueWithProperty.js +44 -4
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/proxyThemeVariables.js +2 -1
- package/dist/esm/helpers/proxyThemeVariables.js.map +2 -2
- package/dist/esm/helpers/pseudoDescriptors.js +11 -0
- package/dist/esm/helpers/pseudoDescriptors.js.map +2 -2
- package/dist/esm/helpers/registerCSSVariable.js +5 -6
- package/dist/esm/helpers/registerCSSVariable.js.map +2 -2
- package/dist/esm/helpers/startTransition.js +6 -0
- package/dist/esm/helpers/startTransition.js.map +7 -0
- package/dist/esm/helpers/themeable.js +12 -44
- package/dist/esm/helpers/themeable.js.map +2 -2
- package/dist/esm/helpers/themes.js +54 -0
- package/dist/esm/helpers/themes.js.map +7 -0
- package/dist/esm/helpers/timer.js +11 -0
- package/dist/esm/helpers/timer.js.map +7 -0
- package/dist/esm/helpers/useShallowSetState.js +25 -0
- package/dist/esm/helpers/useShallowSetState.js.map +7 -0
- package/dist/esm/helpers/validate.js +0 -98
- package/dist/esm/helpers/validate.js.map +3 -3
- package/dist/esm/helpers/withStaticProperties.js +0 -0
- package/dist/esm/helpers/withStaticProperties.js.map +0 -0
- package/dist/esm/hooks/getThemeUnwrapped.js +12 -0
- package/dist/esm/hooks/getThemeUnwrapped.js.map +7 -0
- package/dist/esm/hooks/useConstant.js +4 -1
- package/dist/esm/hooks/useConstant.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +59 -0
- package/dist/esm/hooks/useElementLayout.js.map +7 -0
- package/dist/esm/hooks/useId.js +1 -28
- package/dist/esm/hooks/useId.js.map +2 -2
- package/dist/esm/hooks/useIsMounted.js +0 -0
- package/dist/esm/hooks/useIsMounted.js.map +1 -1
- package/dist/esm/hooks/useIsSSR.js +22 -0
- package/dist/esm/hooks/useIsSSR.js.map +7 -0
- package/dist/esm/hooks/useIsTouchDevice.js +3 -9
- package/dist/esm/hooks/useIsTouchDevice.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +159 -122
- package/dist/esm/hooks/useMedia.js.map +3 -3
- package/dist/esm/hooks/usePressable.js +1 -16
- package/dist/esm/hooks/usePressable.js.map +1 -1
- package/dist/esm/hooks/useSafeRef.js +34 -0
- package/dist/esm/hooks/useSafeRef.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 +178 -162
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/hooks/useThemeName.js +28 -0
- package/dist/esm/hooks/useThemeName.js.map +7 -0
- package/dist/esm/hooks/useUnmountEffect.js +0 -0
- package/dist/esm/hooks/useUnmountEffect.js.map +1 -1
- package/dist/esm/index.js +37 -22
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/inject-styles.js +16 -0
- package/dist/esm/inject-styles.js.map +7 -0
- package/dist/esm/injectStyles.js +16 -0
- package/dist/esm/injectStyles.js.map +7 -0
- package/dist/esm/insertFont.js +18 -15
- package/dist/esm/insertFont.js.map +2 -2
- package/dist/esm/setupReactNative.js +24 -0
- package/dist/esm/setupReactNative.js.map +7 -0
- package/dist/esm/static.js +1 -17
- package/dist/esm/static.js.map +2 -2
- package/dist/esm/styled.js +29 -51
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/types-rnw.js +0 -0
- package/dist/esm/types-rnw.js.map +0 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/types.js.map +0 -0
- package/dist/esm/updateTheme.js +23 -0
- package/dist/esm/updateTheme.js.map +7 -0
- package/dist/esm/{Pressability.js → vendor/Pressability.js} +3 -1
- package/dist/esm/vendor/Pressability.js.map +7 -0
- package/dist/esm/{Pressability.native.js → vendor/Pressability.native.js} +3 -1
- package/dist/esm/vendor/Pressability.native.js.map +7 -0
- package/dist/esm/views/FontLanguage.js +14 -0
- package/dist/esm/views/FontLanguage.js.map +7 -0
- package/dist/esm/views/FontLanguage.native.js +14 -0
- package/dist/esm/views/FontLanguage.native.js.map +7 -0
- package/dist/esm/views/FontLanguage.types.js +1 -0
- package/dist/{cjs/defaultComponentState.js.map → esm/views/FontLanguage.types.js.map} +0 -0
- package/dist/esm/views/Slot.js +47 -50
- package/dist/esm/views/Slot.js.map +2 -2
- package/dist/esm/views/Stack.js +3 -21
- package/dist/esm/views/Stack.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +53 -0
- package/dist/esm/views/TamaguiProvider.js.map +7 -0
- package/dist/esm/views/Text.js +29 -29
- package/dist/esm/views/Text.js.map +2 -2
- package/dist/esm/views/Theme.js +48 -21
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/ThemeInverse.js +20 -15
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +11 -22
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/dist/esm/views/ThemeReset.js +6 -4
- package/dist/esm/views/ThemeReset.js.map +2 -2
- package/package.json +51 -19
- package/reset.css +1 -9
- package/src/Tamagui.ts +48 -0
- package/src/__snapshots__/createTokens.test.ts.snap +877 -0
- package/src/addTheme.ts +65 -0
- package/src/config.ts +52 -0
- package/src/constants/constants.ts +19 -0
- package/src/constants/isDevTools.ts +12 -0
- package/src/contexts/ButtonNestingContext.tsx +3 -0
- package/src/contexts/FontLanguageContext.tsx +5 -0
- package/src/contexts/TextAncestorContext.tsx +3 -0
- package/src/createComponent.tsx +1280 -0
- package/src/createFont.test.ts +129 -0
- package/src/createFont.ts +52 -0
- package/src/createShorthands.ts +7 -0
- package/src/createTamagui.ts +230 -0
- package/src/createTheme.ts +13 -0
- package/src/createTokens.test.ts +29 -0
- package/src/createTokens.ts +35 -0
- package/src/createVariable.test.ts +7 -0
- package/src/createVariable.ts +79 -0
- package/src/createVariables.ts +42 -0
- package/src/helpers/RNComponents.tsx +14 -0
- package/src/helpers/ThemeManager.test.tsx +497 -0
- package/src/helpers/ThemeManager.tsx +252 -0
- package/src/helpers/ThemeManagerContext.tsx +5 -0
- package/src/helpers/cache.ts +18 -0
- package/src/helpers/createMediaStyle.ts +55 -0
- package/src/helpers/createPropMapper.ts +526 -0
- package/src/helpers/createProxy.ts +16 -0
- package/src/helpers/expandStyle.ts +81 -0
- package/src/helpers/expandStyles.ts +106 -0
- package/src/helpers/extendStaticConfig.ts +75 -0
- package/src/helpers/fixNativeShadow.tsx +2 -0
- package/src/helpers/getAnimationDriver.tsx +5 -0
- package/src/helpers/getBoundingClientRect.tsx +7 -0
- package/src/helpers/getExpandedShorthands.ts +15 -0
- package/src/helpers/getFontLanguage.ts +2 -0
- package/src/helpers/getRect.tsx +8 -0
- package/src/helpers/getSize.ts +22 -0
- package/src/helpers/getSplitStyles.tsx +980 -0
- package/src/helpers/getStylesAtomic.native.ts +4 -0
- package/src/helpers/getStylesAtomic.ts +275 -0
- package/src/helpers/getThemeCSSRules.native.ts +3 -0
- package/src/helpers/getThemeCSSRules.ts +112 -0
- package/src/helpers/getVariantExtras.tsx +85 -0
- package/src/helpers/insertStyleRule.tsx +163 -0
- package/src/helpers/isObj.ts +1 -0
- package/src/helpers/isTamaguiComponent.tsx +15 -0
- package/src/helpers/isTamaguiElement.tsx +12 -0
- package/src/helpers/matchMedia.native.ts +6 -0
- package/src/helpers/matchMedia.ts +17 -0
- package/src/helpers/mergeProps.ts +56 -0
- package/src/helpers/mergeTransform.ts +23 -0
- package/src/helpers/normalizeColor.ts +53 -0
- package/src/helpers/normalizeValueWithProperty.ts +123 -0
- package/src/helpers/proxyThemeVariables.tsx +15 -0
- package/src/helpers/pseudoDescriptors.ts +40 -0
- package/src/helpers/registerCSSVariable.ts +11 -0
- package/src/helpers/themeable.tsx +44 -0
- package/src/helpers/themes.ts +69 -0
- package/src/helpers/timer.ts +9 -0
- package/src/helpers/useShallowSetState.tsx +29 -0
- package/src/helpers/withStaticProperties.tsx +7 -0
- package/src/hooks/getThemeUnwrapped.tsx +7 -0
- package/src/hooks/useElementLayout.tsx +85 -0
- package/src/hooks/useId.tsx +1 -0
- package/src/hooks/useIsTouchDevice.tsx +6 -0
- package/src/hooks/useMedia.tsx +265 -0
- package/src/hooks/useSafeRef.ts +48 -0
- package/src/hooks/useServerHooks.tsx +12 -0
- package/src/hooks/useTheme.tsx +243 -0
- package/src/hooks/useThemeName.tsx +27 -0
- package/src/index.ts +73 -0
- package/src/inject-styles.ts +20 -0
- package/src/insertFont.ts +70 -0
- package/src/setupReactNative.ts +20 -0
- package/src/static.ts +5 -0
- package/src/styled.tsx +172 -0
- package/src/types-rnw.tsx +162 -0
- package/src/types.tsx +1350 -0
- package/src/updateTheme.ts +26 -0
- package/src/vendor/Pressability.native.tsx +3 -0
- package/src/vendor/Pressability.tsx +2 -0
- package/src/views/FontLanguage.native.tsx +10 -0
- package/src/views/FontLanguage.tsx +18 -0
- package/src/views/FontLanguage.types.ts +13 -0
- package/src/views/Slot.tsx +147 -0
- package/src/views/Stack.tsx +24 -0
- package/src/views/TamaguiProvider.tsx +59 -0
- package/src/views/Text.tsx +87 -0
- package/src/views/Theme.tsx +77 -0
- package/src/views/ThemeProvider.tsx +41 -0
- package/types/Tamagui.d.ts +9 -7
- package/types/addTheme.d.ts +32 -0
- package/types/config.d.ts +46 -0
- package/types/constants/constants.d.ts +14 -3
- package/types/constants/isDevTools.d.ts +2 -0
- package/types/contexts/ButtonNestingContext.d.ts +3 -0
- package/types/contexts/FontLanguageContext.d.ts +5 -0
- package/types/contexts/TextAncestorContext.d.ts +3 -0
- package/types/createComponent.d.ts +1 -24
- package/types/createFont.d.ts +0 -0
- package/types/createFont.test.d.ts +2 -0
- package/types/createShorthands.d.ts +2 -1
- package/types/createTamagui.d.ts +2 -25
- package/types/createTheme.d.ts +1 -1
- package/types/createTokens.d.ts +5 -5
- package/types/createTokens.test.d.ts +2 -0
- package/types/createVariable.d.ts +15 -10
- package/types/createVariable.test.d.ts +2 -0
- package/types/createVariables.d.ts +1 -1
- package/types/helpers/RNComponents.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts +36 -0
- package/types/helpers/ThemeManager.test.d.ts +2 -0
- package/types/helpers/ThemeManagerContext.d.ts +4 -0
- package/types/helpers/cache.d.ts +12 -0
- package/types/helpers/createMediaStyle.d.ts +2 -4
- package/types/helpers/createPropMapper.d.ts +3 -1
- package/types/helpers/createProxy.d.ts +2 -0
- package/types/helpers/expandStyle.d.ts +4 -0
- package/types/helpers/expandStyles.d.ts +20 -1
- package/types/helpers/extendStaticConfig.d.ts +0 -0
- package/types/helpers/fixNativeShadow.d.ts +0 -0
- package/types/helpers/getAnimationDriver.d.ts +6 -0
- package/types/helpers/getBoundingClientRect.d.ts +2 -0
- package/types/helpers/getExpandedShorthands.d.ts +0 -0
- package/types/helpers/getFontLanguage.d.ts +2 -0
- package/types/helpers/getRect.d.ts +9 -0
- package/types/helpers/getSize.d.ts +0 -0
- package/types/helpers/getSplitStyles.d.ts +32 -16
- package/types/helpers/getStylesAtomic.d.ts +11 -10
- package/types/helpers/getStylesAtomic.native.d.ts +0 -0
- package/types/helpers/getThemeCSSRules.d.ts +8 -0
- package/types/helpers/getThemeCSSRules.native.d.ts +2 -0
- package/types/helpers/getVariantExtras.d.ts +4 -6
- package/types/helpers/insertStyleRule.d.ts +8 -4
- package/types/helpers/isObj.d.ts +0 -0
- package/types/helpers/isTamaguiComponent.d.ts +1 -1
- package/types/helpers/isTamaguiElement.d.ts +5 -1
- package/types/helpers/matchMedia.d.ts +1 -1
- package/types/helpers/matchMedia.native.d.ts +0 -0
- package/types/helpers/mergeProps.d.ts +16 -1
- package/types/helpers/mergeTransform.d.ts +6 -4
- package/types/helpers/normalizeColor.d.ts +0 -0
- package/types/helpers/normalizeValueWithProperty.d.ts +5 -0
- package/types/helpers/proxyThemeVariables.d.ts +0 -0
- package/types/helpers/pseudoDescriptors.d.ts +8 -14
- package/types/helpers/registerCSSVariable.d.ts +3 -3
- package/types/helpers/themeable.d.ts +7 -7
- package/types/helpers/themes.d.ts +4 -0
- package/types/helpers/timer.d.ts +2 -0
- package/types/helpers/useShallowSetState.d.ts +4 -0
- package/types/helpers/withStaticProperties.d.ts +0 -0
- package/types/hooks/getThemeUnwrapped.d.ts +3 -0
- package/types/hooks/useElementLayout.d.ts +19 -0
- package/types/hooks/useId.d.ts +1 -8
- package/types/hooks/useIsTouchDevice.d.ts +0 -0
- package/types/hooks/useMedia.d.ts +22 -6
- package/types/hooks/useSafeRef.d.ts +4 -0
- package/types/hooks/useServerHooks.d.ts +4 -0
- package/types/hooks/useTheme.d.ts +11 -41
- package/types/hooks/useThemeName.d.ts +5 -0
- package/types/index.d.ts +17 -17
- package/types/inject-styles.d.ts +7 -0
- package/types/insertFont.d.ts +4 -1
- package/types/setupReactNative.d.ts +5 -0
- package/types/static.d.ts +1 -17
- package/types/styled.d.ts +6 -2
- package/types/types-rnw.d.ts +0 -0
- package/types/types.d.ts +298 -89
- package/types/updateTheme.d.ts +30 -0
- package/types/vendor/Pressability.d.ts +3 -0
- package/types/vendor/Pressability.native.d.ts +3 -0
- package/types/views/FontLanguage.d.ts +4 -0
- package/types/views/FontLanguage.native.d.ts +4 -0
- package/types/views/FontLanguage.types.d.ts +11 -0
- package/types/views/Slot.d.ts +4 -4
- package/types/views/Stack.d.ts +1 -1
- package/types/views/TamaguiProvider.d.ts +4 -0
- package/types/views/Text.d.ts +1 -1
- package/types/views/Theme.d.ts +4 -3
- package/types/views/ThemeProvider.d.ts +0 -1
- package/dist/cjs/Pressability.js.map +0 -7
- package/dist/cjs/Pressability.native.js.map +0 -7
- package/dist/cjs/ThemeContext.js.map +0 -7
- package/dist/cjs/ThemeManager.js +0 -204
- package/dist/cjs/ThemeManager.js.map +0 -7
- package/dist/cjs/conf.js.map +0 -7
- package/dist/cjs/constants/rnw.js.map +0 -7
- package/dist/cjs/constants/rnw.native.js.map +0 -7
- package/dist/cjs/defaultComponentState.js +0 -1
- package/dist/cjs/helpers/createTamaguiProvider.js +0 -91
- package/dist/cjs/helpers/createTamaguiProvider.js.map +0 -7
- package/dist/cjs/helpers/cssHash.js.map +0 -7
- package/dist/cjs/helpers/getTextSize.js +0 -55
- package/dist/cjs/helpers/getTextSize.js.map +0 -7
- package/dist/cjs/helpers/nativeGestureHandler.native.js.map +0 -7
- package/dist/cjs/helpers/wrapThemeManagerContext.js +0 -37
- package/dist/cjs/helpers/wrapThemeManagerContext.js.map +0 -7
- package/dist/cjs/hooks/useFeatures.js +0 -230
- package/dist/cjs/hooks/useFeatures.js.map +0 -7
- package/dist/cjs/hooks/usePrevious.js +0 -1
- package/dist/cjs/hooks/usePrevious.js.map +0 -7
- package/dist/cjs/views/TextAncestorContext.js +0 -43
- package/dist/cjs/views/TextAncestorContext.js.map +0 -7
- package/dist/esm/Pressability.js.map +0 -7
- package/dist/esm/Pressability.native.js.map +0 -7
- package/dist/esm/ThemeContext.js.map +0 -7
- package/dist/esm/ThemeManager.js +0 -179
- package/dist/esm/ThemeManager.js.map +0 -7
- package/dist/esm/conf.js.map +0 -7
- package/dist/esm/constants/rnw.js +0 -6
- package/dist/esm/constants/rnw.js.map +0 -7
- package/dist/esm/constants/rnw.native.js +0 -5
- package/dist/esm/constants/rnw.native.js.map +0 -7
- package/dist/esm/defaultComponentState.js +0 -1
- package/dist/esm/defaultComponentState.js.map +0 -7
- package/dist/esm/helpers/createTamaguiProvider.js +0 -67
- package/dist/esm/helpers/createTamaguiProvider.js.map +0 -7
- package/dist/esm/helpers/cssHash.js +0 -27
- package/dist/esm/helpers/cssHash.js.map +0 -7
- package/dist/esm/helpers/getTextSize.js +0 -32
- package/dist/esm/helpers/getTextSize.js.map +0 -7
- package/dist/esm/helpers/nativeGestureHandler.native.js +0 -2
- package/dist/esm/helpers/nativeGestureHandler.native.js.map +0 -7
- package/dist/esm/helpers/wrapThemeManagerContext.js +0 -11
- package/dist/esm/helpers/wrapThemeManagerContext.js.map +0 -7
- package/dist/esm/hooks/useFeatures.js +0 -206
- package/dist/esm/hooks/useFeatures.js.map +0 -7
- package/dist/esm/hooks/usePrevious.js +0 -1
- package/dist/esm/hooks/usePrevious.js.map +0 -7
- package/dist/esm/views/TextAncestorContext.js +0 -15
- package/dist/esm/views/TextAncestorContext.js.map +0 -7
- package/types/Pressability.d.ts +0 -2
- package/types/Pressability.native.d.ts +0 -2
- package/types/Tamagui.d.ts.map +0 -1
- package/types/ThemeContext.d.ts +0 -7
- package/types/ThemeContext.d.ts.map +0 -1
- package/types/ThemeManager.d.ts +0 -52
- package/types/ThemeManager.d.ts.map +0 -1
- package/types/conf.d.ts +0 -26
- package/types/conf.d.ts.map +0 -1
- package/types/constants/platform.d.ts +0 -12
- package/types/constants/rnw.d.ts +0 -2
- package/types/constants/rnw.d.ts.map +0 -1
- package/types/constants/rnw.native.d.ts +0 -2
- package/types/contexts/ButtonInsideButtonContext.d.ts +0 -3
- package/types/createComponent.d.ts.map +0 -1
- package/types/createFont.d.ts.map +0 -1
- package/types/createTamagui.d.ts.map +0 -1
- package/types/createTokens.d.ts.map +0 -1
- package/types/defaultComponentState.d.ts +0 -1
- package/types/helpers/areEqualSets.d.ts +0 -2
- package/types/helpers/assignNativePropsToWeb.d.ts +0 -2
- package/types/helpers/assignNativePropsToWeb.d.ts.map +0 -1
- package/types/helpers/assignNativePropsToWeb.native.d.ts +0 -2
- package/types/helpers/calc.d.ts +0 -12
- package/types/helpers/calc.d.ts.map +0 -1
- package/types/helpers/createMediaStyle.d.ts.map +0 -1
- package/types/helpers/createPropMapper.d.ts.map +0 -1
- package/types/helpers/createShallowUpdate.d.ts +0 -3
- package/types/helpers/createTamaguiProvider.d.ts +0 -3
- package/types/helpers/createTamaguiProvider.d.ts.map +0 -1
- package/types/helpers/cssHash.d.ts +0 -2
- package/types/helpers/cssHash.d.ts.map +0 -1
- package/types/helpers/expandStyle.d.ts.map +0 -1
- package/types/helpers/expandStyles.d.ts.map +0 -1
- package/types/helpers/extendStaticConfig.d.ts.map +0 -1
- package/types/helpers/getExpandedShorthands.d.ts.map +0 -1
- package/types/helpers/getFont.d.ts +0 -3
- package/types/helpers/getFont.d.ts.map +0 -1
- package/types/helpers/getSize.d.ts.map +0 -1
- package/types/helpers/getSplitStyles.d.ts.map +0 -1
- package/types/helpers/getStackSize.d.ts +0 -8
- package/types/helpers/getStackSize.d.ts.map +0 -1
- package/types/helpers/getStylesAtomic.d.ts.map +0 -1
- package/types/helpers/getVariantExtras.d.ts.map +0 -1
- package/types/helpers/isTamaguiComponent.d.ts.map +0 -1
- package/types/helpers/isTamaguiElement.d.ts.map +0 -1
- package/types/helpers/nativeGestureHandler.native.d.ts +0 -2
- package/types/helpers/normalizeColor.d.ts.map +0 -1
- package/types/helpers/normalizeValueWithProperty.d.ts.map +0 -1
- package/types/helpers/themeable.d.ts.map +0 -1
- package/types/helpers/validate.d.ts +0 -4
- package/types/helpers/wrapThemeManagerContext.d.ts +0 -3
- package/types/helpers/wrapThemeManagerContext.d.ts.map +0 -1
- package/types/hooks/useConstant.d.ts +0 -2
- package/types/hooks/useFeatures.d.ts +0 -24
- package/types/hooks/useFeatures.d.ts.map +0 -1
- package/types/hooks/useIsMounted.d.ts +0 -3
- package/types/hooks/useMedia.d.ts.map +0 -1
- package/types/hooks/usePressable.d.ts +0 -3
- package/types/hooks/usePrevious.d.ts +0 -1
- package/types/hooks/useTheme.d.ts.map +0 -1
- package/types/hooks/useUnmountEffect.d.ts +0 -2
- package/types/index.d.ts.map +0 -1
- package/types/insertFont.d.ts.map +0 -1
- package/types/static.d.ts.map +0 -1
- package/types/styled.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
- package/types/views/Stack.d.ts.map +0 -1
- package/types/views/Text.d.ts.map +0 -1
- package/types/views/TextAncestorContext.d.ts +0 -5
- package/types/views/TextAncestorContext.d.ts.map +0 -1
- package/types/views/Theme.d.ts.map +0 -1
- package/types/views/ThemeInverse.d.ts +0 -10
- package/types/views/ThemeInverse.d.ts.map +0 -1
- package/types/views/ThemeProvider.d.ts.map +0 -1
- package/types/views/ThemeReset.d.ts +0 -4
- package/types/views/ThemeReset.d.ts.map +0 -1
|
@@ -0,0 +1,1280 @@
|
|
|
1
|
+
import { useComposedRefs } from '@tamagui/compose-refs'
|
|
2
|
+
import { isClient, isRSC, isServer, isWeb, useIsomorphicLayoutEffect } from '@tamagui/constants'
|
|
3
|
+
import {
|
|
4
|
+
composeEventHandlers,
|
|
5
|
+
stylePropsTransform,
|
|
6
|
+
stylePropsView,
|
|
7
|
+
validPseudoKeys,
|
|
8
|
+
validStyles,
|
|
9
|
+
} from '@tamagui/helpers'
|
|
10
|
+
import { useResponderEvents } from '@tamagui/react-native-use-responder-events'
|
|
11
|
+
import type { ViewStyle } from '@tamagui/types-react-native'
|
|
12
|
+
import React, {
|
|
13
|
+
Children,
|
|
14
|
+
Fragment,
|
|
15
|
+
RefObject,
|
|
16
|
+
createElement,
|
|
17
|
+
forwardRef,
|
|
18
|
+
memo,
|
|
19
|
+
useCallback,
|
|
20
|
+
useContext,
|
|
21
|
+
useEffect,
|
|
22
|
+
useRef,
|
|
23
|
+
} from 'react'
|
|
24
|
+
|
|
25
|
+
import { onConfiguredOnce } from './config'
|
|
26
|
+
import { stackDefaultStyles } from './constants/constants'
|
|
27
|
+
import { FontLanguageContext } from './contexts/FontLanguageContext'
|
|
28
|
+
import { TextAncestorContext } from './contexts/TextAncestorContext'
|
|
29
|
+
import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig'
|
|
30
|
+
import { getRect } from './helpers/getRect'
|
|
31
|
+
import { getSubStyle, useSplitStyles } from './helpers/getSplitStyles'
|
|
32
|
+
import { getAllSelectors } from './helpers/insertStyleRule'
|
|
33
|
+
import { mergeProps } from './helpers/mergeProps'
|
|
34
|
+
import { mergeTransform } from './helpers/mergeTransform'
|
|
35
|
+
import { proxyThemeVariables } from './helpers/proxyThemeVariables'
|
|
36
|
+
import { useShallowSetState } from './helpers/useShallowSetState'
|
|
37
|
+
import { measureLayout, useElementLayout } from './hooks/useElementLayout'
|
|
38
|
+
import { addMediaQueryListener, getInitialMediaState } from './hooks/useMedia'
|
|
39
|
+
import { useServerRef, useServerState } from './hooks/useServerHooks'
|
|
40
|
+
import { getThemeIsNewTheme, getThemeManager, useTheme } from './hooks/useTheme'
|
|
41
|
+
import {
|
|
42
|
+
DebugProp,
|
|
43
|
+
SpaceDirection,
|
|
44
|
+
SpaceTokens,
|
|
45
|
+
SpacerProps,
|
|
46
|
+
StaticConfig,
|
|
47
|
+
StaticConfigParsed,
|
|
48
|
+
StylableComponent,
|
|
49
|
+
TamaguiComponent,
|
|
50
|
+
TamaguiComponentState,
|
|
51
|
+
TamaguiConfig,
|
|
52
|
+
TamaguiElement,
|
|
53
|
+
TamaguiInternalConfig,
|
|
54
|
+
UseAnimationHook,
|
|
55
|
+
UseAnimationProps,
|
|
56
|
+
} from './types'
|
|
57
|
+
import { usePressability } from './vendor/Pressability'
|
|
58
|
+
import { Slot, mergeEvent } from './views/Slot'
|
|
59
|
+
import { wrapThemeManagerContext } from './views/Theme'
|
|
60
|
+
|
|
61
|
+
// let t
|
|
62
|
+
// import { timer } from '@tamagui/timer'
|
|
63
|
+
// if (true || process.env.ANALYZE) {
|
|
64
|
+
// t = require().timer()
|
|
65
|
+
// setTimeout(() => {
|
|
66
|
+
// const out = t.print()
|
|
67
|
+
// if (isClient) {
|
|
68
|
+
// alert(out)
|
|
69
|
+
// }
|
|
70
|
+
// }, 2000)
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
// this appears to fix expo / babel not picking this up sometimes? really odd
|
|
74
|
+
process.env.TAMAGUI_TARGET
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* All things that need one-time setup after createTamagui is called
|
|
78
|
+
*/
|
|
79
|
+
let defaultComponentState: TamaguiComponentState | null = null
|
|
80
|
+
let defaultComponentStateMounted: TamaguiComponentState | null = null
|
|
81
|
+
let tamaguiConfig: TamaguiInternalConfig
|
|
82
|
+
let AnimatedText: any
|
|
83
|
+
let AnimatedView: any
|
|
84
|
+
let initialTheme: any
|
|
85
|
+
|
|
86
|
+
export const mouseUps = new Set<Function>()
|
|
87
|
+
if (typeof document !== 'undefined') {
|
|
88
|
+
const cancelTouches = () => {
|
|
89
|
+
mouseUps.forEach((x) => x())
|
|
90
|
+
mouseUps.clear()
|
|
91
|
+
}
|
|
92
|
+
addEventListener('mouseup', cancelTouches)
|
|
93
|
+
addEventListener('touchend', cancelTouches)
|
|
94
|
+
addEventListener('touchcancel', cancelTouches)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// mutates
|
|
98
|
+
function mergeShorthands({ defaultProps }: StaticConfigParsed, { shorthands }: TamaguiConfig) {
|
|
99
|
+
// they are defined in correct order already { ...parent, ...child }
|
|
100
|
+
for (const key of Object.keys(defaultProps)) {
|
|
101
|
+
defaultProps[shorthands[key] || key] = defaultProps[key]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Only on native do we need the actual underlying View/Text
|
|
107
|
+
* On the web we avoid react-native altogether in core.
|
|
108
|
+
*/
|
|
109
|
+
let BaseText: any
|
|
110
|
+
let BaseView: any
|
|
111
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
112
|
+
const native = require('react-native')
|
|
113
|
+
BaseText = native.Text || native.default.Text
|
|
114
|
+
BaseView = native.View || native.default.View
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function createComponent<
|
|
118
|
+
ComponentPropTypes extends Object = {},
|
|
119
|
+
Ref = TamaguiElement,
|
|
120
|
+
BaseProps = never
|
|
121
|
+
>(configIn: Partial<StaticConfig> | StaticConfigParsed, ParentComponent?: StylableComponent) {
|
|
122
|
+
const staticConfig = (() => {
|
|
123
|
+
const next = extendStaticConfig(configIn, ParentComponent)
|
|
124
|
+
if ('parsed' in next) {
|
|
125
|
+
return next
|
|
126
|
+
} else {
|
|
127
|
+
return parseStaticConfig(next)
|
|
128
|
+
}
|
|
129
|
+
})()
|
|
130
|
+
|
|
131
|
+
const defaultComponentClassName = `is_${staticConfig.componentName}`
|
|
132
|
+
let defaultNativeStyle: any
|
|
133
|
+
let tamaguiDefaultProps: any
|
|
134
|
+
let defaultTag: string | undefined
|
|
135
|
+
|
|
136
|
+
// see onConfiguredOnce below which attaches a name then to this component
|
|
137
|
+
const component = forwardRef<Ref, ComponentPropTypes>((propsIn: any, forwardedRef) => {
|
|
138
|
+
// const time = t.start({ quiet: true })
|
|
139
|
+
|
|
140
|
+
// React inserts default props after your props for some reason...
|
|
141
|
+
// order important so we do loops, you can't just spread because JS does weird things
|
|
142
|
+
let props: any
|
|
143
|
+
if (tamaguiDefaultProps && !propsIn.asChild) {
|
|
144
|
+
props = mergeProps(tamaguiDefaultProps, propsIn)[0]
|
|
145
|
+
} else {
|
|
146
|
+
props = propsIn
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const debugProp = props['debug'] as DebugProp
|
|
150
|
+
const { Component, isText, isZStack } = staticConfig
|
|
151
|
+
const componentName = props.componentName || staticConfig.componentName
|
|
152
|
+
const componentClassName = props.asChild
|
|
153
|
+
? ''
|
|
154
|
+
: props.componentName
|
|
155
|
+
? `is_${props.componentName}`
|
|
156
|
+
: defaultComponentClassName
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Component state for tracking animations, pseudos
|
|
160
|
+
*/
|
|
161
|
+
const animationsConfig = tamaguiConfig.animations
|
|
162
|
+
const useAnimations = animationsConfig?.useAnimations as UseAnimationHook | undefined
|
|
163
|
+
const avoidClassesWhileAnimating = animationsConfig.isReactNative
|
|
164
|
+
const hasEnterStyle = !!props.enterStyle
|
|
165
|
+
const needsMount = Boolean((isWeb ? isClient : true) && (hasEnterStyle || props.animation))
|
|
166
|
+
const states = useServerState<TamaguiComponentState>(
|
|
167
|
+
needsMount ? defaultComponentState! : defaultComponentStateMounted!
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
const state = propsIn.forceStyle ? { ...states[0], [propsIn.forceStyle]: true } : states[0]
|
|
171
|
+
const setState = states[1]
|
|
172
|
+
const setStateShallow = useShallowSetState(setState, debugProp, componentName)
|
|
173
|
+
|
|
174
|
+
// conditional but if ever true stays true
|
|
175
|
+
// [animated, inversed]
|
|
176
|
+
const stateRef = useRef(
|
|
177
|
+
undefined as any as {
|
|
178
|
+
hasAnimated?: boolean
|
|
179
|
+
hasThemeInversed?: boolean
|
|
180
|
+
hasProvidedThemeManager?: boolean
|
|
181
|
+
themeShouldReset?: boolean
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
stateRef.current ??= {}
|
|
185
|
+
|
|
186
|
+
const isAnimated = (() => {
|
|
187
|
+
const next = !!(useAnimations && props.animation)
|
|
188
|
+
if (next && !stateRef.current.hasAnimated) {
|
|
189
|
+
stateRef.current.hasAnimated = true
|
|
190
|
+
}
|
|
191
|
+
return next || stateRef.current.hasAnimated
|
|
192
|
+
})()
|
|
193
|
+
|
|
194
|
+
const usePresence = tamaguiConfig.animations?.usePresence
|
|
195
|
+
const presence = !isRSC && isAnimated ? usePresence() : null
|
|
196
|
+
|
|
197
|
+
// set enter/exit variants onto our new props object
|
|
198
|
+
if (isAnimated && presence) {
|
|
199
|
+
const presenceState = presence[2]
|
|
200
|
+
if (presenceState) {
|
|
201
|
+
if (state.unmounted && presenceState.enterVariant) {
|
|
202
|
+
props[presenceState.enterVariant] = true
|
|
203
|
+
}
|
|
204
|
+
if (!presenceState.isPresent && presenceState.exitVariant) {
|
|
205
|
+
props[presenceState.exitVariant] = true
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const isReactNative = Boolean(
|
|
211
|
+
staticConfig.isReactNative || (isAnimated && tamaguiConfig.animations.isReactNative)
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
if (process.env.NODE_ENV === 'development') {
|
|
215
|
+
if (debugProp) {
|
|
216
|
+
const name = `${
|
|
217
|
+
componentName || Component?.displayName || Component?.name || '[Unnamed Component]'
|
|
218
|
+
}`
|
|
219
|
+
const type = isReactNative ? '(rnw)' : ''
|
|
220
|
+
const dataIs = propsIn['data-is'] || ''
|
|
221
|
+
const banner = `${name}${dataIs ? ` ${dataIs}` : ''} ${type}`
|
|
222
|
+
// eslint-disable-next-line no-console
|
|
223
|
+
console.group(`%c ${banner}`, 'background: yellow;')
|
|
224
|
+
if (!isServer) {
|
|
225
|
+
// eslint-disable-next-line no-console
|
|
226
|
+
console.log(`state`, state)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const shouldAvoidClasses =
|
|
232
|
+
!isWeb || !!(props.animation && avoidClassesWhileAnimating) || !staticConfig.acceptsClassName
|
|
233
|
+
const shouldForcePseudo = !!propsIn.forceStyle
|
|
234
|
+
const noClassNames = shouldAvoidClasses || shouldForcePseudo
|
|
235
|
+
|
|
236
|
+
const theme = useTheme({
|
|
237
|
+
name: props.theme,
|
|
238
|
+
componentName,
|
|
239
|
+
reset: props.reset,
|
|
240
|
+
inverse: props.themeInverse,
|
|
241
|
+
// @ts-expect-error internal use only
|
|
242
|
+
disable: props['data-themeable'],
|
|
243
|
+
debug: props.debug,
|
|
244
|
+
})
|
|
245
|
+
const themeManager = getThemeManager(theme)
|
|
246
|
+
const themeIsNew = getThemeIsNewTheme(theme)
|
|
247
|
+
|
|
248
|
+
const shouldSetMounted = needsMount && state.unmounted
|
|
249
|
+
const setMounted = shouldSetMounted
|
|
250
|
+
? () => {
|
|
251
|
+
// for some reason without some small delay it doesn't animate css
|
|
252
|
+
setTimeout(
|
|
253
|
+
() => {
|
|
254
|
+
setStateShallow({
|
|
255
|
+
unmounted: false,
|
|
256
|
+
})
|
|
257
|
+
},
|
|
258
|
+
isWeb ? 10 : 0
|
|
259
|
+
)
|
|
260
|
+
}
|
|
261
|
+
: undefined
|
|
262
|
+
|
|
263
|
+
const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false)
|
|
264
|
+
const languageContext = isRSC ? null : useContext(FontLanguageContext)
|
|
265
|
+
const isDisabled = props.disabled ?? props.accessibilityState?.disabled
|
|
266
|
+
|
|
267
|
+
const isTaggable = !Component || typeof Component === 'string'
|
|
268
|
+
// default to tag, fallback to component (when both strings)
|
|
269
|
+
const element = isWeb
|
|
270
|
+
? isTaggable
|
|
271
|
+
? props.tag || defaultTag || Component
|
|
272
|
+
: Component
|
|
273
|
+
: Component
|
|
274
|
+
|
|
275
|
+
const BaseTextComponent = BaseText || element || 'span'
|
|
276
|
+
const BaseViewComponent = BaseView || element || (hasTextAncestor ? 'span' : 'div')
|
|
277
|
+
let elementType = isText
|
|
278
|
+
? (isAnimated ? AnimatedText : null) || BaseTextComponent
|
|
279
|
+
: (isAnimated ? AnimatedView : null) || BaseViewComponent
|
|
280
|
+
|
|
281
|
+
elementType = Component || elementType
|
|
282
|
+
const isStringElement = typeof elementType === 'string'
|
|
283
|
+
|
|
284
|
+
const isExiting = presence?.[0] === false
|
|
285
|
+
const splitStyles = useSplitStyles(
|
|
286
|
+
props,
|
|
287
|
+
staticConfig,
|
|
288
|
+
theme,
|
|
289
|
+
{
|
|
290
|
+
...state,
|
|
291
|
+
noClassNames,
|
|
292
|
+
dynamicStylesInline: noClassNames,
|
|
293
|
+
hasTextAncestor,
|
|
294
|
+
resolveVariablesAs: 'value',
|
|
295
|
+
isExiting,
|
|
296
|
+
},
|
|
297
|
+
null,
|
|
298
|
+
languageContext || undefined,
|
|
299
|
+
elementType,
|
|
300
|
+
debugProp
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
const hostRef = useServerRef<TamaguiElement>(null)
|
|
304
|
+
|
|
305
|
+
// animation setup
|
|
306
|
+
const isAnimatedReactNativeWeb = isAnimated && avoidClassesWhileAnimating
|
|
307
|
+
|
|
308
|
+
if (process.env.NODE_ENV === 'development') {
|
|
309
|
+
if (!process.env.TAMAGUI_TARGET) {
|
|
310
|
+
// eslint-disable-next-line no-console
|
|
311
|
+
console.error(`No process.env.TAMAGUI_TARGET set, please set it to "native" or "web".`)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (debugProp) {
|
|
315
|
+
// eslint-disable-next-line no-console
|
|
316
|
+
console.groupCollapsed('props')
|
|
317
|
+
// eslint-disable-next-line no-console
|
|
318
|
+
console.log('props in', propsIn, 'mapped to', props, 'in order', Object.keys(props))
|
|
319
|
+
// eslint-disable-next-line no-console
|
|
320
|
+
console.log('splitStyles', splitStyles)
|
|
321
|
+
// eslint-disable-next-line no-console
|
|
322
|
+
console.log('className', Object.values(splitStyles.classNames))
|
|
323
|
+
if (isClient) {
|
|
324
|
+
// eslint-disable-next-line no-console
|
|
325
|
+
console.log('ref', hostRef, '(click to view)')
|
|
326
|
+
}
|
|
327
|
+
// eslint-disable-next-line no-console
|
|
328
|
+
console.groupEnd()
|
|
329
|
+
if (debugProp === 'break') {
|
|
330
|
+
// eslint-disable-next-line no-debugger
|
|
331
|
+
debugger
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const {
|
|
337
|
+
viewProps: viewPropsIn,
|
|
338
|
+
pseudos,
|
|
339
|
+
medias,
|
|
340
|
+
style: splitStylesStyle,
|
|
341
|
+
classNames,
|
|
342
|
+
mediaKeys,
|
|
343
|
+
} = splitStyles
|
|
344
|
+
|
|
345
|
+
const propsWithAnimation = props as UseAnimationProps
|
|
346
|
+
|
|
347
|
+
// once you set animation prop don't remove it, you can set to undefined/false
|
|
348
|
+
// reason is animations are heavy - no way around it, and must be run inline here (🙅 loading as a sub-component)
|
|
349
|
+
let animationStyles: any
|
|
350
|
+
if (!isRSC && isAnimated && useAnimations) {
|
|
351
|
+
const animations = useAnimations({
|
|
352
|
+
props: propsWithAnimation,
|
|
353
|
+
style: splitStylesStyle,
|
|
354
|
+
presence,
|
|
355
|
+
state,
|
|
356
|
+
pseudos,
|
|
357
|
+
onDidAnimate: props.onDidAnimate,
|
|
358
|
+
hostRef,
|
|
359
|
+
staticConfig,
|
|
360
|
+
})
|
|
361
|
+
if (animations) {
|
|
362
|
+
animationStyles = animations.style
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// media queries
|
|
367
|
+
useIsomorphicLayoutEffect(() => {
|
|
368
|
+
const disposers = mediaKeys.map((key) => {
|
|
369
|
+
return addMediaQueryListener(key, (next: boolean) => {
|
|
370
|
+
setState((prev) => {
|
|
371
|
+
if (prev.mediaState![key] !== next) {
|
|
372
|
+
return {
|
|
373
|
+
...prev,
|
|
374
|
+
mediaState: getMediaStateObject({
|
|
375
|
+
...prev.mediaState,
|
|
376
|
+
[key]: next,
|
|
377
|
+
}),
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return prev
|
|
381
|
+
})
|
|
382
|
+
})
|
|
383
|
+
})
|
|
384
|
+
return () => {
|
|
385
|
+
disposers.forEach((d) => d())
|
|
386
|
+
}
|
|
387
|
+
}, [mediaKeys.join(',')])
|
|
388
|
+
|
|
389
|
+
const {
|
|
390
|
+
hitSlop,
|
|
391
|
+
asChild,
|
|
392
|
+
children,
|
|
393
|
+
onPress,
|
|
394
|
+
onPressIn,
|
|
395
|
+
onPressOut,
|
|
396
|
+
onHoverIn,
|
|
397
|
+
onHoverOut,
|
|
398
|
+
themeShallow,
|
|
399
|
+
space: spaceProp,
|
|
400
|
+
spaceDirection: _spaceDirection,
|
|
401
|
+
disabled: disabledProp,
|
|
402
|
+
onMouseUp,
|
|
403
|
+
onMouseDown,
|
|
404
|
+
onMouseEnter,
|
|
405
|
+
onMouseLeave,
|
|
406
|
+
hrefAttrs,
|
|
407
|
+
separator,
|
|
408
|
+
// ignore from here on out
|
|
409
|
+
forceStyle: _forceStyle,
|
|
410
|
+
// @ts-ignore for next/link compat etc
|
|
411
|
+
onClick,
|
|
412
|
+
theme: _themeProp,
|
|
413
|
+
// @ts-ignore
|
|
414
|
+
defaultVariants,
|
|
415
|
+
|
|
416
|
+
...nonTamaguiProps
|
|
417
|
+
} = viewPropsIn
|
|
418
|
+
|
|
419
|
+
const disabled =
|
|
420
|
+
(props.accessibilityState != null && props.accessibilityState.disabled === true) ||
|
|
421
|
+
props.accessibilityDisabled
|
|
422
|
+
|
|
423
|
+
// these can ultimately be for DOM, react-native-web views, or animated views
|
|
424
|
+
// so the type is pretty loose
|
|
425
|
+
let viewProps: Record<string, any>
|
|
426
|
+
|
|
427
|
+
// if react-native-web view just pass all props down
|
|
428
|
+
if (process.env.TAMAGUI_TARGET === 'web' && !isReactNative) {
|
|
429
|
+
// otherwise replicate react-native-web functionality
|
|
430
|
+
const {
|
|
431
|
+
// event props
|
|
432
|
+
onMoveShouldSetResponder,
|
|
433
|
+
onMoveShouldSetResponderCapture,
|
|
434
|
+
onResponderEnd,
|
|
435
|
+
onResponderGrant,
|
|
436
|
+
onResponderMove,
|
|
437
|
+
onResponderReject,
|
|
438
|
+
onResponderRelease,
|
|
439
|
+
onResponderStart,
|
|
440
|
+
onResponderTerminate,
|
|
441
|
+
onResponderTerminationRequest,
|
|
442
|
+
onScrollShouldSetResponder,
|
|
443
|
+
onScrollShouldSetResponderCapture,
|
|
444
|
+
onSelectionChangeShouldSetResponder,
|
|
445
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
446
|
+
onStartShouldSetResponder,
|
|
447
|
+
onStartShouldSetResponderCapture,
|
|
448
|
+
|
|
449
|
+
// android
|
|
450
|
+
collapsable,
|
|
451
|
+
focusable,
|
|
452
|
+
|
|
453
|
+
// deprecated,
|
|
454
|
+
accessible,
|
|
455
|
+
accessibilityDisabled,
|
|
456
|
+
|
|
457
|
+
onLayout,
|
|
458
|
+
|
|
459
|
+
...webProps
|
|
460
|
+
} = nonTamaguiProps
|
|
461
|
+
|
|
462
|
+
viewProps = webProps
|
|
463
|
+
|
|
464
|
+
if (!isRSC) {
|
|
465
|
+
usePlatformMethods(hostRef as RefObject<Element>)
|
|
466
|
+
|
|
467
|
+
useElementLayout(hostRef as RefObject<Element>, onLayout as any)
|
|
468
|
+
|
|
469
|
+
useResponderEvents(hostRef, {
|
|
470
|
+
onMoveShouldSetResponder,
|
|
471
|
+
onMoveShouldSetResponderCapture,
|
|
472
|
+
onResponderEnd,
|
|
473
|
+
onResponderGrant,
|
|
474
|
+
onResponderMove,
|
|
475
|
+
onResponderReject,
|
|
476
|
+
onResponderRelease,
|
|
477
|
+
onResponderStart,
|
|
478
|
+
onResponderTerminate,
|
|
479
|
+
onResponderTerminationRequest,
|
|
480
|
+
onScrollShouldSetResponder,
|
|
481
|
+
onScrollShouldSetResponderCapture,
|
|
482
|
+
onSelectionChangeShouldSetResponder,
|
|
483
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
484
|
+
onStartShouldSetResponder,
|
|
485
|
+
onStartShouldSetResponderCapture,
|
|
486
|
+
} as any)
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (props.href != undefined && hrefAttrs != undefined) {
|
|
490
|
+
const { download, rel, target } = hrefAttrs
|
|
491
|
+
if (download != null) {
|
|
492
|
+
viewProps.download = download
|
|
493
|
+
}
|
|
494
|
+
if (rel != null) {
|
|
495
|
+
viewProps.rel = rel
|
|
496
|
+
}
|
|
497
|
+
if (typeof target === 'string') {
|
|
498
|
+
viewProps.target = target.charAt(0) !== '_' ? '_' + target : target
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// FOCUS
|
|
503
|
+
// "focusable" indicates that an element may be a keyboard tab-stop.
|
|
504
|
+
const _focusable = focusable != undefined ? focusable : accessible
|
|
505
|
+
const role = viewProps.role
|
|
506
|
+
if (_focusable === false) {
|
|
507
|
+
viewProps.tabIndex = '-1'
|
|
508
|
+
}
|
|
509
|
+
if (
|
|
510
|
+
// These native elements are focusable by default
|
|
511
|
+
elementType === 'a' ||
|
|
512
|
+
elementType === 'button' ||
|
|
513
|
+
elementType === 'input' ||
|
|
514
|
+
elementType === 'select' ||
|
|
515
|
+
elementType === 'textarea'
|
|
516
|
+
) {
|
|
517
|
+
if (_focusable === false || accessibilityDisabled === true) {
|
|
518
|
+
viewProps.tabIndex = '-1'
|
|
519
|
+
}
|
|
520
|
+
} else if (
|
|
521
|
+
// These roles are made focusable by default
|
|
522
|
+
role === 'button' ||
|
|
523
|
+
role === 'checkbox' ||
|
|
524
|
+
role === 'link' ||
|
|
525
|
+
role === 'radio' ||
|
|
526
|
+
role === 'textbox' ||
|
|
527
|
+
role === 'switch'
|
|
528
|
+
) {
|
|
529
|
+
if (_focusable !== false) {
|
|
530
|
+
viewProps.tabIndex = '0'
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
// Everything else must explicitly set the prop
|
|
534
|
+
if (_focusable === true) {
|
|
535
|
+
viewProps.tabIndex = '0'
|
|
536
|
+
}
|
|
537
|
+
} else {
|
|
538
|
+
viewProps = nonTamaguiProps
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
viewProps.ref = useComposedRefs(hostRef as any, forwardedRef, setMounted)
|
|
542
|
+
|
|
543
|
+
if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
|
|
544
|
+
Children.toArray(props.children).forEach((item) => {
|
|
545
|
+
if (typeof item === 'string') {
|
|
546
|
+
// eslint-disable-next-line no-console
|
|
547
|
+
console.error(`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`)
|
|
548
|
+
}
|
|
549
|
+
})
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const unPress = useCallback(() => {
|
|
553
|
+
setStateShallow({
|
|
554
|
+
press: false,
|
|
555
|
+
pressIn: false,
|
|
556
|
+
})
|
|
557
|
+
}, [setStateShallow])
|
|
558
|
+
|
|
559
|
+
if (!isRSC) {
|
|
560
|
+
useEffect(() => {
|
|
561
|
+
return () => {
|
|
562
|
+
mouseUps.delete(unPress)
|
|
563
|
+
}
|
|
564
|
+
}, [unPress])
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
let styles: Record<string, any>[]
|
|
568
|
+
|
|
569
|
+
if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {
|
|
570
|
+
styles = {
|
|
571
|
+
...defaultNativeStyle,
|
|
572
|
+
...(animationStyles ?? splitStylesStyle),
|
|
573
|
+
...medias,
|
|
574
|
+
}
|
|
575
|
+
} else {
|
|
576
|
+
styles = [isWeb ? null : defaultNativeStyle, animationStyles ?? splitStylesStyle, medias]
|
|
577
|
+
|
|
578
|
+
// ugly but for now...
|
|
579
|
+
if (shouldForcePseudo) {
|
|
580
|
+
const next = {}
|
|
581
|
+
styles.forEach((style) => Object.assign(next, style))
|
|
582
|
+
// @ts-ignore
|
|
583
|
+
Object.assign(splitStyles.style, next)
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
let fontFamily = isText ? splitStyles.fontFamily || staticConfig.defaultProps.fontFamily : null
|
|
588
|
+
if (fontFamily && fontFamily[0] === '$') {
|
|
589
|
+
fontFamily = fontFamily.slice(1)
|
|
590
|
+
}
|
|
591
|
+
const fontFamilyClassName = fontFamily ? `font_${fontFamily}` : ''
|
|
592
|
+
|
|
593
|
+
const classList = [
|
|
594
|
+
componentName ? componentClassName : '',
|
|
595
|
+
fontFamilyClassName,
|
|
596
|
+
themeIsNew ? theme.className : '',
|
|
597
|
+
classNames ? Object.values(classNames).join(' ') : '',
|
|
598
|
+
]
|
|
599
|
+
const className = classList.join(' ')
|
|
600
|
+
|
|
601
|
+
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
602
|
+
const style = animationStyles ?? splitStyles.style
|
|
603
|
+
|
|
604
|
+
if (isAnimatedReactNativeWeb) {
|
|
605
|
+
viewProps.style = style
|
|
606
|
+
} else if (isReactNative) {
|
|
607
|
+
const rnwStyle = { $$css: true }
|
|
608
|
+
for (const name of className.split(' ')) {
|
|
609
|
+
rnwStyle[name] = name
|
|
610
|
+
}
|
|
611
|
+
viewProps.style = [rnwStyle, ...(Array.isArray(style) ? style : [style])]
|
|
612
|
+
if (process.env.NODE_ENV === 'development') {
|
|
613
|
+
// turn debug data- props into dataSet in dev mode
|
|
614
|
+
Object.keys(viewProps).forEach((key) => {
|
|
615
|
+
if (key.startsWith('data-')) {
|
|
616
|
+
viewProps.dataSet ??= {}
|
|
617
|
+
viewProps.dataSet[key.replace('data-', '')] = viewProps[key]
|
|
618
|
+
delete viewProps[key]
|
|
619
|
+
}
|
|
620
|
+
})
|
|
621
|
+
}
|
|
622
|
+
} else {
|
|
623
|
+
viewProps.className = className
|
|
624
|
+
viewProps.style = style
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
629
|
+
// swap out the right family based on weight/style
|
|
630
|
+
if (splitStyles.fontFamily) {
|
|
631
|
+
const faceInfo = tamaguiConfig.fontsParsed[splitStyles.fontFamily]?.face
|
|
632
|
+
if (faceInfo) {
|
|
633
|
+
const [weight, style] = (() => {
|
|
634
|
+
let weight: string | undefined
|
|
635
|
+
let style: string | undefined
|
|
636
|
+
for (let i = styles.length; i >= 0; i--) {
|
|
637
|
+
weight ??= styles[i]?.fontWeight
|
|
638
|
+
style ??= styles[i]?.fontStyle
|
|
639
|
+
}
|
|
640
|
+
return [weight || '400', style || 'normal'] as const
|
|
641
|
+
})()
|
|
642
|
+
const overrideFace = faceInfo[weight]?.[style]?.val
|
|
643
|
+
if (overrideFace) {
|
|
644
|
+
for (const style of styles) {
|
|
645
|
+
if (style?.fontFamily) {
|
|
646
|
+
style.fontFamily = overrideFace
|
|
647
|
+
delete style.fontWeight
|
|
648
|
+
delete style.fontStyle
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// assign styles
|
|
656
|
+
viewProps.style = styles
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const runtimePressStyle = !disabled && noClassNames && pseudos?.pressStyle
|
|
660
|
+
const attachPress = !!(runtimePressStyle || onPress || onPressOut || onPressIn || onClick)
|
|
661
|
+
const runtimeHoverStyle = !disabled && noClassNames && pseudos?.hoverStyle
|
|
662
|
+
const isHoverable =
|
|
663
|
+
isWeb && !!(runtimeHoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave)
|
|
664
|
+
|
|
665
|
+
const handlesPressEvents = !isWeb && !asChild
|
|
666
|
+
|
|
667
|
+
// check presence rather than value to prevent reparenting bugs
|
|
668
|
+
// allows for onPress={x ? function : undefined} without re-ordering dom
|
|
669
|
+
const shouldAttach = asChild
|
|
670
|
+
? false
|
|
671
|
+
: Boolean(
|
|
672
|
+
attachPress ||
|
|
673
|
+
isHoverable ||
|
|
674
|
+
'pressStyle' in props ||
|
|
675
|
+
'onPress' in props ||
|
|
676
|
+
'onPressIn' in props ||
|
|
677
|
+
'onPressOut' in props ||
|
|
678
|
+
(isWeb &&
|
|
679
|
+
('hoverStyle' in props ||
|
|
680
|
+
'onHoverIn' in props ||
|
|
681
|
+
'onHoverOut' in props ||
|
|
682
|
+
'onMouseEnter' in props ||
|
|
683
|
+
'onMouseLeave' in props))
|
|
684
|
+
)
|
|
685
|
+
|
|
686
|
+
const events =
|
|
687
|
+
shouldAttach && !isRSC && !isDisabled
|
|
688
|
+
? {
|
|
689
|
+
onPressOut: attachPress
|
|
690
|
+
? (e) => {
|
|
691
|
+
unPress()
|
|
692
|
+
onPressOut?.(e)
|
|
693
|
+
onMouseUp?.(e)
|
|
694
|
+
}
|
|
695
|
+
: undefined,
|
|
696
|
+
...(isHoverable && {
|
|
697
|
+
onMouseEnter: isHoverable
|
|
698
|
+
? (e) => {
|
|
699
|
+
const next: Partial<typeof state> = {}
|
|
700
|
+
if (isHoverable) {
|
|
701
|
+
next.hover = true
|
|
702
|
+
}
|
|
703
|
+
if (state.pressIn) {
|
|
704
|
+
next.press = true
|
|
705
|
+
}
|
|
706
|
+
if (isHoverable || state.pressIn) {
|
|
707
|
+
setStateShallow(next)
|
|
708
|
+
}
|
|
709
|
+
onHoverIn?.(e)
|
|
710
|
+
onMouseEnter?.(e)
|
|
711
|
+
}
|
|
712
|
+
: undefined,
|
|
713
|
+
onMouseLeave: isHoverable
|
|
714
|
+
? (e) => {
|
|
715
|
+
const next: Partial<typeof state> = {}
|
|
716
|
+
mouseUps.add(unPress)
|
|
717
|
+
if (isHoverable) {
|
|
718
|
+
next.hover = false
|
|
719
|
+
}
|
|
720
|
+
if (state.pressIn) {
|
|
721
|
+
next.press = false
|
|
722
|
+
next.pressIn = false
|
|
723
|
+
}
|
|
724
|
+
if (Object.keys(next).length) {
|
|
725
|
+
setStateShallow(next)
|
|
726
|
+
}
|
|
727
|
+
onHoverOut?.(e)
|
|
728
|
+
onMouseLeave?.(e)
|
|
729
|
+
}
|
|
730
|
+
: undefined,
|
|
731
|
+
}),
|
|
732
|
+
onPressIn: attachPress
|
|
733
|
+
? (e) => {
|
|
734
|
+
setStateShallow({
|
|
735
|
+
press: true,
|
|
736
|
+
pressIn: true,
|
|
737
|
+
hover: false,
|
|
738
|
+
})
|
|
739
|
+
onPressIn?.(e)
|
|
740
|
+
onMouseDown?.(e)
|
|
741
|
+
if (isWeb) {
|
|
742
|
+
mouseUps.add(unPress)
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
: undefined,
|
|
746
|
+
onPress: attachPress
|
|
747
|
+
? (e) => {
|
|
748
|
+
unPress()
|
|
749
|
+
// @ts-ignore
|
|
750
|
+
onClick?.(e)
|
|
751
|
+
onPress?.(e)
|
|
752
|
+
}
|
|
753
|
+
: undefined,
|
|
754
|
+
|
|
755
|
+
// replicating TouchableWithoutFeedback
|
|
756
|
+
...(!isWeb && {
|
|
757
|
+
cancelable: !props.rejectResponderTermination,
|
|
758
|
+
disabled: isDisabled,
|
|
759
|
+
hitSlop: props.hitSlop,
|
|
760
|
+
delayLongPress: props.delayLongPress,
|
|
761
|
+
delayPressIn: props.delayPressIn,
|
|
762
|
+
delayPressOut: props.delayPressOut,
|
|
763
|
+
focusable: viewProps.focusable ?? true,
|
|
764
|
+
minPressDuration: 0,
|
|
765
|
+
}),
|
|
766
|
+
}
|
|
767
|
+
: null
|
|
768
|
+
|
|
769
|
+
let space = spaceProp
|
|
770
|
+
|
|
771
|
+
// find space by media query
|
|
772
|
+
if (state.mediaState && mediaKeys.length) {
|
|
773
|
+
for (const key in state.mediaState) {
|
|
774
|
+
if (key in state.mediaState && key in props && props[key].space !== undefined) {
|
|
775
|
+
space = props[key].space
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
const themeShouldReset = Boolean(themeShallow && themeManager && themeIsNew)
|
|
781
|
+
const shouldProvideThemeManager = themeShouldReset || (themeManager && themeIsNew)
|
|
782
|
+
|
|
783
|
+
// memoize to avoid re-parenting
|
|
784
|
+
if (shouldProvideThemeManager) {
|
|
785
|
+
stateRef.current.hasProvidedThemeManager = true
|
|
786
|
+
}
|
|
787
|
+
if (themeShouldReset) {
|
|
788
|
+
stateRef.current.themeShouldReset = true
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
const childEls =
|
|
792
|
+
!children || asChild
|
|
793
|
+
? children
|
|
794
|
+
: wrapThemeManagerContext(
|
|
795
|
+
spacedChildren({
|
|
796
|
+
separator,
|
|
797
|
+
children,
|
|
798
|
+
space,
|
|
799
|
+
direction: props.spaceDirection || 'both',
|
|
800
|
+
isZStack,
|
|
801
|
+
}),
|
|
802
|
+
// only set context if changed theme
|
|
803
|
+
stateRef.current.hasProvidedThemeManager ? themeManager : undefined,
|
|
804
|
+
stateRef.current.themeShouldReset
|
|
805
|
+
)
|
|
806
|
+
|
|
807
|
+
let content: any
|
|
808
|
+
|
|
809
|
+
if (asChild) {
|
|
810
|
+
elementType = Slot
|
|
811
|
+
viewProps = {
|
|
812
|
+
...viewProps,
|
|
813
|
+
onPress,
|
|
814
|
+
onPressIn,
|
|
815
|
+
onPressOut,
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// EVENTS native
|
|
820
|
+
if (process.env.TAMAGUI_TARGET === 'native') {
|
|
821
|
+
// add focus events
|
|
822
|
+
const attachFocus = !!pseudos.focusStyle
|
|
823
|
+
if (attachFocus) {
|
|
824
|
+
viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {
|
|
825
|
+
setStateShallow({ focus: true })
|
|
826
|
+
})
|
|
827
|
+
viewProps.onBlur = mergeEvent(viewProps.onBlur, () => {
|
|
828
|
+
setStateShallow({ focus: false })
|
|
829
|
+
})
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// use Pressability to get smooth unPress when you press + hold + move out
|
|
833
|
+
// only ever create once, use .configure() to update later
|
|
834
|
+
const pressability = usePressability(events ? { ...events, hitSlop } : {})
|
|
835
|
+
if (attachPress && events) {
|
|
836
|
+
for (const key in pressability) {
|
|
837
|
+
const og = props[key]
|
|
838
|
+
const val = pressability[key]
|
|
839
|
+
viewProps[key] =
|
|
840
|
+
og && !dontComposePressabilityKeys[key] ? composeEventHandlers(og, val) : val
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
content = createElement(elementType, viewProps, childEls)
|
|
846
|
+
|
|
847
|
+
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
848
|
+
if (events || isAnimatedReactNativeWeb) {
|
|
849
|
+
content = (
|
|
850
|
+
<span
|
|
851
|
+
className={(isAnimatedReactNativeWeb ? className : '') + ` _dsp_contents`}
|
|
852
|
+
{...(events && {
|
|
853
|
+
onMouseEnter: events.onMouseEnter,
|
|
854
|
+
onMouseLeave: events.onMouseLeave,
|
|
855
|
+
onClick: events.onPress,
|
|
856
|
+
onMouseDown: events.onPressIn,
|
|
857
|
+
onMouseUp: events.onPressOut,
|
|
858
|
+
onTouchStart: events.onPressIn,
|
|
859
|
+
onTouchEnd: events.onPressOut,
|
|
860
|
+
})}
|
|
861
|
+
>
|
|
862
|
+
{content}
|
|
863
|
+
</span>
|
|
864
|
+
)
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
if (process.env.NODE_ENV === 'development' && process.env.DEBUG !== 'tamagui') {
|
|
869
|
+
if (debugProp) {
|
|
870
|
+
const element = typeof elementType === 'string' ? elementType : 'Component'
|
|
871
|
+
// eslint-disable-next-line no-console
|
|
872
|
+
console.groupCollapsed(`render <${element} /> with props`, viewProps)
|
|
873
|
+
for (const key in viewProps) {
|
|
874
|
+
// eslint-disable-next-line no-console
|
|
875
|
+
console.log(key, viewProps[key])
|
|
876
|
+
}
|
|
877
|
+
// eslint-disable-next-line no-console
|
|
878
|
+
console.log('children', content)
|
|
879
|
+
// eslint-disable-next-line no-console
|
|
880
|
+
console.groupEnd()
|
|
881
|
+
if (typeof window !== 'undefined') {
|
|
882
|
+
// prettier-ignore
|
|
883
|
+
// eslint-disable-next-line no-console
|
|
884
|
+
console.log({ state, shouldProvideThemeManager, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, defaultNativeStyle, ...(typeof window !== 'undefined' ? { theme, themeClassName: theme.className, staticConfig, tamaguiConfig, events, shouldAvoidClasses, shouldForcePseudo, classNames: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) } : null) })
|
|
885
|
+
}
|
|
886
|
+
// eslint-disable-next-line no-console
|
|
887
|
+
console.groupEnd()
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
return content
|
|
892
|
+
})
|
|
893
|
+
|
|
894
|
+
if (staticConfig.componentName) {
|
|
895
|
+
component.displayName = staticConfig.componentName
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
onConfiguredOnce((conf) => {
|
|
899
|
+
// one time only setup
|
|
900
|
+
if (!tamaguiConfig) {
|
|
901
|
+
tamaguiConfig = conf
|
|
902
|
+
|
|
903
|
+
if (!defaultComponentState) {
|
|
904
|
+
defaultComponentState = {
|
|
905
|
+
hover: false,
|
|
906
|
+
press: false,
|
|
907
|
+
pressIn: false,
|
|
908
|
+
focus: false,
|
|
909
|
+
unmounted: true,
|
|
910
|
+
mediaState: getMediaStateObject(getInitialMediaState()),
|
|
911
|
+
}
|
|
912
|
+
defaultComponentStateMounted = {
|
|
913
|
+
...defaultComponentState,
|
|
914
|
+
unmounted: false,
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
if (tamaguiConfig.animations) {
|
|
919
|
+
AnimatedText = tamaguiConfig.animations.Text
|
|
920
|
+
AnimatedView = tamaguiConfig.animations.View
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (!initialTheme) {
|
|
924
|
+
const next = conf.themes[Object.keys(conf.themes)[0]]
|
|
925
|
+
initialTheme = proxyThemeVariables(next)
|
|
926
|
+
if (process.env.NODE_ENV === 'development') {
|
|
927
|
+
if (!initialTheme) {
|
|
928
|
+
// eslint-disable-next-line no-console
|
|
929
|
+
console.log(`Warning: Missing theme`)
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// per-component setup
|
|
936
|
+
// do this to make sure shorthands don't duplicate with.. longhands
|
|
937
|
+
mergeShorthands(staticConfig, tamaguiConfig)
|
|
938
|
+
|
|
939
|
+
let defaultPropsIn = staticConfig.defaultProps || {}
|
|
940
|
+
|
|
941
|
+
// because we run createTamagui after styled() defs, have to do some work here
|
|
942
|
+
// gather defaults props one time and merge downwards
|
|
943
|
+
// find last unprocessed and process
|
|
944
|
+
const parentNames = [...(staticConfig.parentNames || []), staticConfig.componentName]
|
|
945
|
+
|
|
946
|
+
if (tamaguiConfig.defaultProps && parentNames && staticConfig.componentName) {
|
|
947
|
+
defaultPropsIn = mergeConfigDefaultProps(
|
|
948
|
+
staticConfig.componentName,
|
|
949
|
+
defaultPropsIn,
|
|
950
|
+
tamaguiConfig.defaultProps,
|
|
951
|
+
parentNames,
|
|
952
|
+
tamaguiConfig
|
|
953
|
+
)
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
const debug = defaultPropsIn['debug']
|
|
957
|
+
|
|
958
|
+
// remove all classNames
|
|
959
|
+
const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {})
|
|
960
|
+
|
|
961
|
+
if (ourProps.tag) {
|
|
962
|
+
defaultTag = ourProps.tag
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
const noClassNames = !staticConfig.acceptsClassName
|
|
966
|
+
const { name, variants, defaultVariants, ...restProps } = ourProps
|
|
967
|
+
|
|
968
|
+
// must preserve prop order
|
|
969
|
+
// leave out className because we handle that already with initialSplitStyles.classNames
|
|
970
|
+
// otherwise it confuses variant functions getting className props
|
|
971
|
+
const [defaults, defaultsClassnames] = mergeProps(component.defaultProps as any, {
|
|
972
|
+
...defaultVariants,
|
|
973
|
+
...restProps,
|
|
974
|
+
})
|
|
975
|
+
|
|
976
|
+
defaultNativeStyle = {}
|
|
977
|
+
|
|
978
|
+
const validStyles = staticConfig.validStyles || stylePropsView
|
|
979
|
+
|
|
980
|
+
// split - keep variables on props to be processed using theme values at runtime (native)
|
|
981
|
+
if (!isWeb) {
|
|
982
|
+
for (const key in staticConfig.defaultProps) {
|
|
983
|
+
const val = staticConfig.defaultProps[key]
|
|
984
|
+
if (validPseudoKeys[key]) continue
|
|
985
|
+
if ((typeof val === 'string' && val[0] === '$') || !validStyles[key]) {
|
|
986
|
+
defaults[key] = val
|
|
987
|
+
} else {
|
|
988
|
+
defaultNativeStyle[key] = val
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// set to global
|
|
994
|
+
tamaguiDefaultProps = defaults
|
|
995
|
+
|
|
996
|
+
// add debug logs
|
|
997
|
+
if (process.env.NODE_ENV === 'development' && debug) {
|
|
998
|
+
if (process.env.IS_STATIC !== 'is_static') {
|
|
999
|
+
// prettier-ignore
|
|
1000
|
+
// eslint-disable-next-line no-console
|
|
1001
|
+
console.log(`🐛 [${staticConfig.componentName || 'Component'}]`, { staticConfig, tamaguiDefaultProps, defaultNativeStyle, defaults, defaultPropsIn, defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps), defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [k, defaultPropsIn[k]]), ourProps, ourClassNames, defaultsClassnames, defaultTag, noClassNames, })
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
})
|
|
1005
|
+
|
|
1006
|
+
let res: TamaguiComponent<ComponentPropTypes, Ref, BaseProps> = component as any
|
|
1007
|
+
|
|
1008
|
+
if (configIn.memo) {
|
|
1009
|
+
res = memo(res) as any
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
res.staticConfig = {
|
|
1013
|
+
validStyles: staticConfig.validStyles || stylePropsView,
|
|
1014
|
+
...staticConfig,
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
// res.extractable HoC
|
|
1018
|
+
res.extractable = (Component: any, conf?: Partial<StaticConfig>) => {
|
|
1019
|
+
Component.staticConfig = extendStaticConfig(
|
|
1020
|
+
{
|
|
1021
|
+
Component,
|
|
1022
|
+
...conf,
|
|
1023
|
+
neverFlatten: true,
|
|
1024
|
+
defaultProps: {
|
|
1025
|
+
...Component.defaultProps,
|
|
1026
|
+
...conf?.defaultProps,
|
|
1027
|
+
},
|
|
1028
|
+
},
|
|
1029
|
+
res
|
|
1030
|
+
)
|
|
1031
|
+
return Component
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
return res
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
// for elements to avoid spacing
|
|
1038
|
+
export const Unspaced = (props: { children?: any }) => {
|
|
1039
|
+
return props.children
|
|
1040
|
+
}
|
|
1041
|
+
Unspaced['isUnspaced'] = true
|
|
1042
|
+
|
|
1043
|
+
// dont used styled() here to avoid circular deps
|
|
1044
|
+
// keep inline to avoid circular deps
|
|
1045
|
+
|
|
1046
|
+
export const Spacer = createComponent<SpacerProps>({
|
|
1047
|
+
memo: true,
|
|
1048
|
+
componentName: 'Spacer',
|
|
1049
|
+
validStyles,
|
|
1050
|
+
|
|
1051
|
+
defaultProps: {
|
|
1052
|
+
...stackDefaultStyles,
|
|
1053
|
+
// avoid nesting issues
|
|
1054
|
+
tag: 'span',
|
|
1055
|
+
size: true,
|
|
1056
|
+
},
|
|
1057
|
+
|
|
1058
|
+
variants: {
|
|
1059
|
+
size: {
|
|
1060
|
+
'...size': (size, { tokens }) => {
|
|
1061
|
+
size = size == true ? '$true' : size
|
|
1062
|
+
const sizePx = tokens.space[size] ?? size
|
|
1063
|
+
return {
|
|
1064
|
+
width: sizePx,
|
|
1065
|
+
height: sizePx,
|
|
1066
|
+
minWidth: sizePx,
|
|
1067
|
+
minHeight: sizePx,
|
|
1068
|
+
}
|
|
1069
|
+
},
|
|
1070
|
+
},
|
|
1071
|
+
|
|
1072
|
+
flex: {
|
|
1073
|
+
true: {
|
|
1074
|
+
flexGrow: 1,
|
|
1075
|
+
},
|
|
1076
|
+
},
|
|
1077
|
+
|
|
1078
|
+
direction: {
|
|
1079
|
+
horizontal: {
|
|
1080
|
+
height: 0,
|
|
1081
|
+
minHeight: 0,
|
|
1082
|
+
},
|
|
1083
|
+
vertical: {
|
|
1084
|
+
width: 0,
|
|
1085
|
+
minWidth: 0,
|
|
1086
|
+
},
|
|
1087
|
+
both: {},
|
|
1088
|
+
},
|
|
1089
|
+
} as const,
|
|
1090
|
+
})
|
|
1091
|
+
|
|
1092
|
+
export type SpacedChildrenProps = {
|
|
1093
|
+
isZStack?: boolean
|
|
1094
|
+
children?: React.ReactNode
|
|
1095
|
+
space?: SpaceTokens | number | null
|
|
1096
|
+
spaceFlex?: boolean | number
|
|
1097
|
+
direction?: SpaceDirection
|
|
1098
|
+
separator?: React.ReactNode
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
export function spacedChildren({
|
|
1102
|
+
isZStack,
|
|
1103
|
+
children,
|
|
1104
|
+
space,
|
|
1105
|
+
direction,
|
|
1106
|
+
spaceFlex,
|
|
1107
|
+
separator,
|
|
1108
|
+
}: SpacedChildrenProps) {
|
|
1109
|
+
const hasSpace = !!(space || spaceFlex)
|
|
1110
|
+
const hasSeparator = !(separator === undefined || separator === null)
|
|
1111
|
+
if (!hasSpace && !hasSeparator && !isZStack) {
|
|
1112
|
+
return children
|
|
1113
|
+
}
|
|
1114
|
+
const childrenList = Children.toArray(children)
|
|
1115
|
+
if (childrenList.length <= 1 && !isZStack) {
|
|
1116
|
+
return childrenList
|
|
1117
|
+
}
|
|
1118
|
+
const final: React.ReactNode[] = []
|
|
1119
|
+
for (const [index, child] of childrenList.entries()) {
|
|
1120
|
+
const isEmpty =
|
|
1121
|
+
child === null || child === undefined || (Array.isArray(child) && child.length === 0)
|
|
1122
|
+
// push them all, but wrap some in Fragment
|
|
1123
|
+
if (isEmpty || !child || (child['key'] && !isZStack)) {
|
|
1124
|
+
final.push(child)
|
|
1125
|
+
} else {
|
|
1126
|
+
final.push(
|
|
1127
|
+
<Fragment key={index}>{isZStack ? <AbsoluteFill>{child}</AbsoluteFill> : child}</Fragment>
|
|
1128
|
+
)
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// first child unspaced avoid insert space
|
|
1132
|
+
if (isUnspaced(child) && index === 0) continue
|
|
1133
|
+
// no spacing on ZStack
|
|
1134
|
+
if (isZStack) continue
|
|
1135
|
+
|
|
1136
|
+
const next = childrenList[index + 1]
|
|
1137
|
+
|
|
1138
|
+
if (next && !isUnspaced(next)) {
|
|
1139
|
+
if (separator) {
|
|
1140
|
+
if (hasSpace) {
|
|
1141
|
+
final.push(
|
|
1142
|
+
createSpacer({
|
|
1143
|
+
key: `_${index}_00tmgui`,
|
|
1144
|
+
direction,
|
|
1145
|
+
space,
|
|
1146
|
+
spaceFlex,
|
|
1147
|
+
})
|
|
1148
|
+
)
|
|
1149
|
+
}
|
|
1150
|
+
final.push(
|
|
1151
|
+
React.isValidElement(separator)
|
|
1152
|
+
? React.cloneElement(separator, { key: `sep_${index}` })
|
|
1153
|
+
: separator
|
|
1154
|
+
)
|
|
1155
|
+
if (hasSpace) {
|
|
1156
|
+
final.push(
|
|
1157
|
+
createSpacer({
|
|
1158
|
+
key: `_${index}01tmgui`,
|
|
1159
|
+
direction,
|
|
1160
|
+
space,
|
|
1161
|
+
spaceFlex,
|
|
1162
|
+
})
|
|
1163
|
+
)
|
|
1164
|
+
}
|
|
1165
|
+
} else {
|
|
1166
|
+
final.push(
|
|
1167
|
+
createSpacer({
|
|
1168
|
+
key: `_${index}02tmgui`,
|
|
1169
|
+
direction,
|
|
1170
|
+
space,
|
|
1171
|
+
spaceFlex,
|
|
1172
|
+
})
|
|
1173
|
+
)
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
return final
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
type CreateSpacerProps = SpacedChildrenProps & { key: string }
|
|
1182
|
+
|
|
1183
|
+
function createSpacer({ key, direction, space, spaceFlex }: CreateSpacerProps) {
|
|
1184
|
+
return (
|
|
1185
|
+
// @ts-ignore this one blew up but the types seem better
|
|
1186
|
+
<Spacer
|
|
1187
|
+
key={key}
|
|
1188
|
+
size={space}
|
|
1189
|
+
direction={direction}
|
|
1190
|
+
{...(typeof spaceFlex !== 'undefined' && {
|
|
1191
|
+
flex: spaceFlex === true ? 1 : spaceFlex === false ? 0 : spaceFlex,
|
|
1192
|
+
})}
|
|
1193
|
+
/>
|
|
1194
|
+
)
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
function isUnspaced(child: React.ReactNode) {
|
|
1198
|
+
// console.log('unspaced?', child, getMedia())
|
|
1199
|
+
return child?.['type']?.['isVisuallyHidden'] || child?.['type']?.['isUnspaced']
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
const DefaultProps = new Map()
|
|
1203
|
+
|
|
1204
|
+
function mergeConfigDefaultProps(
|
|
1205
|
+
name: string,
|
|
1206
|
+
props: Record<string, any>,
|
|
1207
|
+
configDefaults: Record<string, Object>,
|
|
1208
|
+
parentNames: (string | undefined)[],
|
|
1209
|
+
conf: TamaguiInternalConfig
|
|
1210
|
+
) {
|
|
1211
|
+
const len = parentNames.length
|
|
1212
|
+
let prev
|
|
1213
|
+
|
|
1214
|
+
for (let i = 0; i < len; i++) {
|
|
1215
|
+
const n = parentNames[i]
|
|
1216
|
+
if (!n) continue
|
|
1217
|
+
if (DefaultProps.has(n)) {
|
|
1218
|
+
prev = DefaultProps.get(n)
|
|
1219
|
+
continue
|
|
1220
|
+
}
|
|
1221
|
+
const props = configDefaults[n]
|
|
1222
|
+
if (!props) {
|
|
1223
|
+
if (prev) {
|
|
1224
|
+
DefaultProps.set(n, prev)
|
|
1225
|
+
}
|
|
1226
|
+
continue
|
|
1227
|
+
}
|
|
1228
|
+
prev = mergeProps(prev || {}, props, false, conf.inverseShorthands)[0]
|
|
1229
|
+
DefaultProps.set(n, prev)
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
// overwrite the user defined defaults on top of internal defined defaults
|
|
1233
|
+
const ourDefaultsMerged = DefaultProps.get(name)
|
|
1234
|
+
if (ourDefaultsMerged) {
|
|
1235
|
+
return mergeProps(props, ourDefaultsMerged, false, conf.inverseShorthands)[0]
|
|
1236
|
+
}
|
|
1237
|
+
return props
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
// react native compat (web only)
|
|
1241
|
+
function usePlatformMethods(hostRef: RefObject<Element>) {
|
|
1242
|
+
useIsomorphicLayoutEffect(() => {
|
|
1243
|
+
const node = hostRef.current
|
|
1244
|
+
if (!node) return
|
|
1245
|
+
// @ts-ignore
|
|
1246
|
+
node.measure = (callback) => measureLayout(node, null, callback)
|
|
1247
|
+
// @ts-ignore
|
|
1248
|
+
node.measureLayout = (relativeToNode, success) => measureLayout(node, relativeToNode, success)
|
|
1249
|
+
// @ts-ignore
|
|
1250
|
+
node.measureInWindow = (callback) => {
|
|
1251
|
+
if (!node) return
|
|
1252
|
+
setTimeout(() => {
|
|
1253
|
+
const { height, left, top, width } = getRect(node as HTMLElement)!
|
|
1254
|
+
callback(left, top, width, height)
|
|
1255
|
+
}, 0)
|
|
1256
|
+
}
|
|
1257
|
+
}, [hostRef])
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
const AbsoluteFill: any = createComponent({
|
|
1261
|
+
componentName: 'AbsoluteFill',
|
|
1262
|
+
defaultProps: {
|
|
1263
|
+
...stackDefaultStyles,
|
|
1264
|
+
flexDirection: 'column',
|
|
1265
|
+
position: 'absolute',
|
|
1266
|
+
top: 0,
|
|
1267
|
+
right: 0,
|
|
1268
|
+
bottom: 0,
|
|
1269
|
+
left: 0,
|
|
1270
|
+
pointerEvents: 'box-none',
|
|
1271
|
+
},
|
|
1272
|
+
})
|
|
1273
|
+
|
|
1274
|
+
const dontComposePressabilityKeys = {
|
|
1275
|
+
onClick: true,
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function getMediaStateObject(obj: Object) {
|
|
1279
|
+
return Object.fromEntries(Object.entries(obj).flatMap(([k, v]) => (v ? [[`$${k}`, v]] : [])))
|
|
1280
|
+
}
|