@tamagui/core 1.0.0-alpha.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/.ultra.cache.json +1 -0
- package/_/constants/constants.js +14 -0
- package/_/constants/constants.js.map +7 -0
- package/_/constants/platform.js +20 -0
- package/_/constants/platform.js.map +7 -0
- package/_/constants/pseudos.js +18 -0
- package/_/constants/pseudos.js.map +7 -0
- package/_/constants/rnw.js +22 -0
- package/_/constants/rnw.js.map +7 -0
- package/_/createComponent.js +427 -0
- package/_/createComponent.js.map +7 -0
- package/_/createShorthands.js +10 -0
- package/_/createShorthands.js.map +7 -0
- package/_/createTamagui.js +122 -0
- package/_/createTamagui.js.map +7 -0
- package/_/createTheme.js +20 -0
- package/_/createTheme.js.map +7 -0
- package/_/createTokens.js +29 -0
- package/_/createTokens.js.map +7 -0
- package/_/createVariable.js +22 -0
- package/_/createVariable.js.map +7 -0
- package/_/helpers/addStylesUsingClassname.js +32 -0
- package/_/helpers/addStylesUsingClassname.js.map +7 -0
- package/_/helpers/createMediaStyle.js +34 -0
- package/_/helpers/createMediaStyle.js.map +7 -0
- package/_/helpers/createTamaguiProvider.js +42 -0
- package/_/helpers/createTamaguiProvider.js.map +7 -0
- package/_/helpers/extendStaticConfig.js +176 -0
- package/_/helpers/extendStaticConfig.js.map +7 -0
- package/_/helpers/fixNativeShadow.js +8 -0
- package/_/helpers/fixNativeShadow.js.map +7 -0
- package/_/helpers/fixNativeShadow.native.js +30 -0
- package/_/helpers/fixNativeShadow.native.js.map +7 -0
- package/_/helpers/getSplitStyles.js +160 -0
- package/_/helpers/getSplitStyles.js.map +7 -0
- package/_/helpers/getStylesAtomic.js +84 -0
- package/_/helpers/getStylesAtomic.js.map +7 -0
- package/_/helpers/getStylesAtomic.native.js +10 -0
- package/_/helpers/getStylesAtomic.native.js.map +7 -0
- package/_/helpers/insertStyleRule.js +24 -0
- package/_/helpers/insertStyleRule.js.map +7 -0
- package/_/helpers/matchMedia.js +15 -0
- package/_/helpers/matchMedia.js.map +7 -0
- package/_/helpers/matchMedia.native.js +8 -0
- package/_/helpers/matchMedia.native.js.map +7 -0
- package/_/helpers/themeable.js +26 -0
- package/_/helpers/themeable.js.map +7 -0
- package/_/hooks/useConstant.js +15 -0
- package/_/hooks/useConstant.js.map +7 -0
- package/_/hooks/useFeatures.js +75 -0
- package/_/hooks/useFeatures.js.map +7 -0
- package/_/hooks/useForceUpdate.js +28 -0
- package/_/hooks/useForceUpdate.js.map +7 -0
- package/_/hooks/useMedia.js +173 -0
- package/_/hooks/useMedia.js.map +7 -0
- package/_/hooks/usePressable.js +14 -0
- package/_/hooks/usePressable.js.map +7 -0
- package/_/hooks/useTheme.js +94 -0
- package/_/hooks/useTheme.js.map +7 -0
- package/_/index.js +30 -0
- package/_/index.js.map +7 -0
- package/_/static/postProcessStyles.js +18 -0
- package/_/static/postProcessStyles.js.map +7 -0
- package/_/static.js +12 -0
- package/_/static.js.map +7 -0
- package/_/styled.js +21 -0
- package/_/styled.js.map +7 -0
- package/_/types.js +1 -0
- package/_/types.js.map +7 -0
- package/_/views/Animated.js +79 -0
- package/_/views/Animated.js.map +7 -0
- package/_/views/Stack.js +12 -0
- package/_/views/Stack.js.map +7 -0
- package/_/views/Text.js +60 -0
- package/_/views/Text.js.map +7 -0
- package/_/views/TextAncestorContext.js +19 -0
- package/_/views/TextAncestorContext.js.map +7 -0
- package/_/views/Theme.js +57 -0
- package/_/views/Theme.js.map +7 -0
- package/_/views/ThemeContext.js +6 -0
- package/_/views/ThemeContext.js.map +7 -0
- package/_/views/ThemeInverse.js +27 -0
- package/_/views/ThemeInverse.js.map +7 -0
- package/_/views/ThemeManagerContext.js +56 -0
- package/_/views/ThemeManagerContext.js.map +7 -0
- package/_/views/ThemeProvider.js +45 -0
- package/_/views/ThemeProvider.js.map +7 -0
- package/dist/constants/constants.js +14 -0
- package/dist/constants/constants.js.map +7 -0
- package/dist/constants/platform.js +19 -0
- package/dist/constants/platform.js.map +7 -0
- package/dist/constants/pseudos.js +18 -0
- package/dist/constants/pseudos.js.map +7 -0
- package/dist/constants/rnw.js +22 -0
- package/dist/constants/rnw.js.map +7 -0
- package/dist/constants/styleConstants.js +46 -0
- package/dist/constants/styleConstants.js.map +7 -0
- package/dist/createComponent.js +445 -0
- package/dist/createComponent.js.map +7 -0
- package/dist/createFont.js +24 -0
- package/dist/createFont.js.map +7 -0
- package/dist/createShorthands.js +10 -0
- package/dist/createShorthands.js.map +7 -0
- package/dist/createTamagui.js +159 -0
- package/dist/createTamagui.js.map +7 -0
- package/dist/createTheme.js +20 -0
- package/dist/createTheme.js.map +7 -0
- package/dist/createTokens.js +29 -0
- package/dist/createTokens.js.map +7 -0
- package/dist/createVariable.js +22 -0
- package/dist/createVariable.js.map +7 -0
- package/dist/helpers/addStylesUsingClassname.js +57 -0
- package/dist/helpers/addStylesUsingClassname.js.map +7 -0
- package/dist/helpers/createMediaStyle.js +34 -0
- package/dist/helpers/createMediaStyle.js.map +7 -0
- package/dist/helpers/createPropMapper.js +153 -0
- package/dist/helpers/createPropMapper.js.map +7 -0
- package/dist/helpers/createTamaguiProvider.js +25 -0
- package/dist/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/helpers/extendStaticConfig.js +59 -0
- package/dist/helpers/extendStaticConfig.js.map +7 -0
- package/dist/helpers/fixNativeShadow.js +8 -0
- package/dist/helpers/fixNativeShadow.js.map +7 -0
- package/dist/helpers/fixNativeShadow.native.js +30 -0
- package/dist/helpers/fixNativeShadow.native.js.map +7 -0
- package/dist/helpers/getSplitStyles.js +160 -0
- package/dist/helpers/getSplitStyles.js.map +7 -0
- package/dist/helpers/getStylesAtomic.js +83 -0
- package/dist/helpers/getStylesAtomic.js.map +7 -0
- package/dist/helpers/getStylesAtomic.native.js +10 -0
- package/dist/helpers/getStylesAtomic.native.js.map +7 -0
- package/dist/helpers/insertStyleRule.js +24 -0
- package/dist/helpers/insertStyleRule.js.map +7 -0
- package/dist/helpers/isObj.js +7 -0
- package/dist/helpers/isObj.js.map +7 -0
- package/dist/helpers/matchMedia.js +15 -0
- package/dist/helpers/matchMedia.js.map +7 -0
- package/dist/helpers/matchMedia.native.js +8 -0
- package/dist/helpers/matchMedia.native.js.map +7 -0
- package/dist/helpers/pseudos.js +1 -0
- package/dist/helpers/pseudos.js.map +7 -0
- package/dist/helpers/themeable.js +26 -0
- package/dist/helpers/themeable.js.map +7 -0
- package/dist/hooks/useConstant.js +15 -0
- package/dist/hooks/useConstant.js.map +7 -0
- package/dist/hooks/useFeatures.js +75 -0
- package/dist/hooks/useFeatures.js.map +7 -0
- package/dist/hooks/useForceUpdate.js +28 -0
- package/dist/hooks/useForceUpdate.js.map +7 -0
- package/dist/hooks/useMedia.js +171 -0
- package/dist/hooks/useMedia.js.map +7 -0
- package/dist/hooks/usePressable.js +13 -0
- package/dist/hooks/usePressable.js.map +7 -0
- package/dist/hooks/useTheme.js +93 -0
- package/dist/hooks/useTheme.js.map +7 -0
- package/dist/index.cjs +2125 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +7 -0
- package/dist/packages/core/src/constants/constants.d.ts +8 -0
- package/dist/packages/core/src/constants/constants.d.ts.map +1 -0
- package/dist/packages/core/src/constants/platform.d.ts +9 -0
- package/dist/packages/core/src/constants/platform.d.ts.map +1 -0
- package/dist/packages/core/src/constants/pseudos.d.ts +15 -0
- package/dist/packages/core/src/constants/pseudos.d.ts.map +1 -0
- package/dist/packages/core/src/constants/rnw.d.ts +2 -0
- package/dist/packages/core/src/constants/rnw.d.ts.map +1 -0
- package/dist/packages/core/src/createComponent.d.ts +16 -0
- package/dist/packages/core/src/createComponent.d.ts.map +1 -0
- package/dist/packages/core/src/createShorthands.d.ts +2 -0
- package/dist/packages/core/src/createShorthands.d.ts.map +1 -0
- package/dist/packages/core/src/createTamagui.d.ts +37 -0
- package/dist/packages/core/src/createTamagui.d.ts.map +1 -0
- package/dist/packages/core/src/createTheme.d.ts +5 -0
- package/dist/packages/core/src/createTheme.d.ts.map +1 -0
- package/dist/packages/core/src/createTokens.d.ts +45 -0
- package/dist/packages/core/src/createTokens.d.ts.map +1 -0
- package/dist/packages/core/src/createVariable.d.ts +14 -0
- package/dist/packages/core/src/createVariable.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts +2 -0
- package/dist/packages/core/src/helpers/addStylesUsingClassname.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/createMediaStyle.d.ts +8 -0
- package/dist/packages/core/src/helpers/createMediaStyle.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts +5 -0
- package/dist/packages/core/src/helpers/createTamaguiProvider.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/extendStaticConfig.d.ts +5 -0
- package/dist/packages/core/src/helpers/extendStaticConfig.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.d.ts +2 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts +2 -0
- package/dist/packages/core/src/helpers/fixNativeShadow.native.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/getSplitStyles.d.ts +15 -0
- package/dist/packages/core/src/helpers/getSplitStyles.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.d.ts +3 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts +2 -0
- package/dist/packages/core/src/helpers/getStylesAtomic.native.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/insertStyleRule.d.ts +2 -0
- package/dist/packages/core/src/helpers/insertStyleRule.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/matchMedia.d.ts +2 -0
- package/dist/packages/core/src/helpers/matchMedia.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/matchMedia.native.d.ts +3 -0
- package/dist/packages/core/src/helpers/matchMedia.native.d.ts.map +1 -0
- package/dist/packages/core/src/helpers/themeable.d.ts +10 -0
- package/dist/packages/core/src/helpers/themeable.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useConstant.d.ts +2 -0
- package/dist/packages/core/src/hooks/useConstant.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useFeatures.d.ts +5 -0
- package/dist/packages/core/src/hooks/useFeatures.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useForceUpdate.d.ts +2 -0
- package/dist/packages/core/src/hooks/useForceUpdate.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useMedia.d.ts +16 -0
- package/dist/packages/core/src/hooks/useMedia.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/usePressable.d.ts +3 -0
- package/dist/packages/core/src/hooks/usePressable.d.ts.map +1 -0
- package/dist/packages/core/src/hooks/useTheme.d.ts +18 -0
- package/dist/packages/core/src/hooks/useTheme.d.ts.map +1 -0
- package/dist/packages/core/src/index.d.ts +27 -0
- package/dist/packages/core/src/index.d.ts.map +1 -0
- package/dist/packages/core/src/static/postProcessStyles.d.ts +7 -0
- package/dist/packages/core/src/static/postProcessStyles.d.ts.map +1 -0
- package/dist/packages/core/src/static.d.ts +12 -0
- package/dist/packages/core/src/static.d.ts.map +1 -0
- package/dist/packages/core/src/styled.d.ts +16 -0
- package/dist/packages/core/src/styled.d.ts.map +1 -0
- package/dist/packages/core/src/types.d.ts +305 -0
- package/dist/packages/core/src/types.d.ts.map +1 -0
- package/dist/packages/core/src/views/Animated.d.ts +15 -0
- package/dist/packages/core/src/views/Animated.d.ts.map +1 -0
- package/dist/packages/core/src/views/Stack.d.ts +3 -0
- package/dist/packages/core/src/views/Stack.d.ts.map +1 -0
- package/dist/packages/core/src/views/Text.d.ts +3 -0
- package/dist/packages/core/src/views/Text.d.ts.map +1 -0
- package/dist/packages/core/src/views/TextAncestorContext.d.ts +3 -0
- package/dist/packages/core/src/views/TextAncestorContext.d.ts.map +1 -0
- package/dist/packages/core/src/views/Theme.d.ts +8 -0
- package/dist/packages/core/src/views/Theme.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeContext.d.ts +18 -0
- package/dist/packages/core/src/views/ThemeContext.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeInverse.d.ts +10 -0
- package/dist/packages/core/src/views/ThemeInverse.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeManagerContext.d.ts +15 -0
- package/dist/packages/core/src/views/ThemeManagerContext.d.ts.map +1 -0
- package/dist/packages/core/src/views/ThemeProvider.d.ts +10 -0
- package/dist/packages/core/src/views/ThemeProvider.d.ts.map +1 -0
- package/dist/packages/helpers/src/AllRules.d.ts +3 -0
- package/dist/packages/helpers/src/AllRules.d.ts.map +1 -0
- package/dist/packages/helpers/src/concatClassName.d.ts +2 -0
- package/dist/packages/helpers/src/concatClassName.d.ts.map +1 -0
- package/dist/packages/helpers/src/index.d.ts +5 -0
- package/dist/packages/helpers/src/index.d.ts.map +1 -0
- package/dist/packages/helpers/src/types.d.ts +8 -0
- package/dist/packages/helpers/src/types.d.ts.map +1 -0
- package/dist/packages/helpers/src/validStyleProps.d.ts +475 -0
- package/dist/packages/helpers/src/validStyleProps.d.ts.map +1 -0
- package/dist/static/postProcessStyles.js +18 -0
- package/dist/static/postProcessStyles.js.map +7 -0
- package/dist/static.js +15 -0
- package/dist/static.js.map +7 -0
- package/dist/styled.js +21 -0
- package/dist/styled.js.map +7 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +7 -0
- package/dist/views/Animated.js +79 -0
- package/dist/views/Animated.js.map +7 -0
- package/dist/views/SafeAreaProvider.js +30 -0
- package/dist/views/SafeAreaProvider.js.map +7 -0
- package/dist/views/Stack.js +12 -0
- package/dist/views/Stack.js.map +7 -0
- package/dist/views/Text.js +60 -0
- package/dist/views/Text.js.map +7 -0
- package/dist/views/TextAncestorContext.js +18 -0
- package/dist/views/TextAncestorContext.js.map +7 -0
- package/dist/views/Theme.js +56 -0
- package/dist/views/Theme.js.map +7 -0
- package/dist/views/ThemeContext.js +6 -0
- package/dist/views/ThemeContext.js.map +7 -0
- package/dist/views/ThemeInverse.js +27 -0
- package/dist/views/ThemeInverse.js.map +7 -0
- package/dist/views/ThemeManagerContext.js +55 -0
- package/dist/views/ThemeManagerContext.js.map +7 -0
- package/dist/views/ThemeProvider.js +45 -0
- package/dist/views/ThemeProvider.js.map +7 -0
- package/package.json +33 -0
- package/src/constants/constants.ts +12 -0
- package/src/constants/platform.ts +15 -0
- package/src/constants/pseudos.ts +14 -0
- package/src/constants/rnw.tsx +20 -0
- package/src/createComponent.tsx +596 -0
- package/src/createFont.ts +26 -0
- package/src/createShorthands.ts +5 -0
- package/src/createTamagui.ts +207 -0
- package/src/createTheme.ts +19 -0
- package/src/createTokens.ts +83 -0
- package/src/createVariable.ts +22 -0
- package/src/helpers/addStylesUsingClassname.tsx +60 -0
- package/src/helpers/createMediaStyle.ts +46 -0
- package/src/helpers/createPropMapper.ts +184 -0
- package/src/helpers/createTamaguiProvider.tsx +22 -0
- package/src/helpers/extendStaticConfig.ts +68 -0
- package/src/helpers/fixNativeShadow.native.tsx +27 -0
- package/src/helpers/fixNativeShadow.tsx +2 -0
- package/src/helpers/getSplitStyles.tsx +210 -0
- package/src/helpers/getStylesAtomic.native.ts +3 -0
- package/src/helpers/getStylesAtomic.ts +103 -0
- package/src/helpers/insertStyleRule.tsx +18 -0
- package/src/helpers/isObj.ts +1 -0
- package/src/helpers/matchMedia.native.ts +3 -0
- package/src/helpers/matchMedia.ts +9 -0
- package/src/helpers/themeable.tsx +42 -0
- package/src/hooks/useConstant.tsx +10 -0
- package/src/hooks/useFeatures.tsx +78 -0
- package/src/hooks/useForceUpdate.tsx +26 -0
- package/src/hooks/useMedia.tsx +194 -0
- package/src/hooks/usePressable.tsx +9 -0
- package/src/hooks/useTheme.tsx +107 -0
- package/src/index.ts +33 -0
- package/src/static/postProcessStyles.tsx +20 -0
- package/src/static.ts +22 -0
- package/src/styled.ts +82 -0
- package/src/types.tsx +561 -0
- package/src/views/Animated.tsx +121 -0
- package/src/views/SafeAreaProvider.tsx +33 -0
- package/src/views/Stack.tsx +21 -0
- package/src/views/Text.tsx +66 -0
- package/src/views/TextAncestorContext.tsx +12 -0
- package/src/views/Theme.tsx +73 -0
- package/src/views/ThemeContext.tsx +5 -0
- package/src/views/ThemeInverse.tsx +23 -0
- package/src/views/ThemeManagerContext.tsx +50 -0
- package/src/views/ThemeProvider.tsx +52 -0
- package/tsconfig.json +8 -0
- package/types.d.ts +558 -0
package/src/types.tsx
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
import React, { RefObject } from 'react'
|
|
2
|
+
import { TextProps as ReactTextProps, TextStyle } from 'react-native'
|
|
3
|
+
import { GestureResponderEvent, View, ViewProps, ViewStyle } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import { Variable } from './createVariable'
|
|
6
|
+
import { ThemeProviderProps } from './views/ThemeProvider'
|
|
7
|
+
|
|
8
|
+
// to prevent things from going circular, hoisting some types in this file
|
|
9
|
+
// to generally order them as building up towards TamaguiConfig
|
|
10
|
+
|
|
11
|
+
export interface CreateTokens<Val extends number | string | Variable = number | string | Variable> {
|
|
12
|
+
font: { [key: string]: GenericFont }
|
|
13
|
+
color: { [key: string]: Val }
|
|
14
|
+
space: { [key: string]: Val }
|
|
15
|
+
size: { [key: string]: Val }
|
|
16
|
+
radius: { [key: string]: Val }
|
|
17
|
+
zIndex: { [key: string]: Val }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type GenericTokens = CreateTokens
|
|
21
|
+
type GenericThemes = {
|
|
22
|
+
[key: string]: {
|
|
23
|
+
// defined for our tamagui kit , we could do this inside `tamagui`
|
|
24
|
+
// but maybe helpful to have some sort of universally shared things +
|
|
25
|
+
// + enforce if they want their own, redefine in their design sys
|
|
26
|
+
bg: string | Variable
|
|
27
|
+
bg2: string | Variable
|
|
28
|
+
bg3: string | Variable
|
|
29
|
+
bg4: string | Variable
|
|
30
|
+
color: string | Variable
|
|
31
|
+
color2: string | Variable
|
|
32
|
+
color3: string | Variable
|
|
33
|
+
color4: string | Variable
|
|
34
|
+
borderColor: string | Variable
|
|
35
|
+
borderColor2: string | Variable
|
|
36
|
+
shadowColor: string | Variable
|
|
37
|
+
shadowColor2: string | Variable
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
type GenericShorthands = {}
|
|
41
|
+
type GenericMedia<K extends string = string> = {
|
|
42
|
+
// name => media shorthand name (camelCase) => value
|
|
43
|
+
[key in K]: {
|
|
44
|
+
[key: string]: number | string
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// this is the "main" typed object, which users re-define
|
|
49
|
+
// (internal) keep all types directly on this object and reference them from elsewhere
|
|
50
|
+
//
|
|
51
|
+
// const config = createTamagui(...)
|
|
52
|
+
// type MyConfig = typeof config
|
|
53
|
+
// declare module 'tamagui' {
|
|
54
|
+
// export interface TamaguiCustomConfig extends MyConfig {}
|
|
55
|
+
// }
|
|
56
|
+
// now your whole app/kit should be typed correctly
|
|
57
|
+
//
|
|
58
|
+
export interface TamaguiCustomConfig {}
|
|
59
|
+
|
|
60
|
+
export interface TamaguiConfig
|
|
61
|
+
extends Omit<GenericTamaguiConfig, keyof TamaguiCustomConfig>,
|
|
62
|
+
TamaguiCustomConfig {}
|
|
63
|
+
|
|
64
|
+
export type CreateTamaguiConfig<
|
|
65
|
+
A extends GenericTokens,
|
|
66
|
+
B extends GenericThemes,
|
|
67
|
+
C extends GenericShorthands,
|
|
68
|
+
D extends GenericMedia
|
|
69
|
+
> = Partial<Pick<ThemeProviderProps, 'defaultTheme' | 'disableRootThemeClass'>> & {
|
|
70
|
+
tokens: A
|
|
71
|
+
themes: B
|
|
72
|
+
shorthands: C
|
|
73
|
+
media: D
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// for use in creation functions so it doesnt get overwrtitten
|
|
77
|
+
export type GenericTamaguiConfig = CreateTamaguiConfig<
|
|
78
|
+
GenericTokens,
|
|
79
|
+
GenericThemes,
|
|
80
|
+
GenericShorthands,
|
|
81
|
+
GenericMedia
|
|
82
|
+
>
|
|
83
|
+
|
|
84
|
+
// since TamaguiConfig will be re-declared, these will all be typed globally
|
|
85
|
+
export type ThemeObject = TamaguiConfig['themes'][keyof TamaguiConfig['themes']]
|
|
86
|
+
export type Tokens = TamaguiConfig['tokens']
|
|
87
|
+
export type Shorthands = TamaguiConfig['shorthands']
|
|
88
|
+
export type Media = TamaguiConfig['media']
|
|
89
|
+
export type Themes = TamaguiConfig['themes']
|
|
90
|
+
// themes
|
|
91
|
+
export type ThemeName = keyof Themes extends `${infer Prefix}-light`
|
|
92
|
+
? Prefix | keyof Themes
|
|
93
|
+
: keyof Themes
|
|
94
|
+
export type ThemeKeys = keyof ThemeObject
|
|
95
|
+
export type ThemeKeyVariables = `$${ThemeKeys}`
|
|
96
|
+
// export type Spaces = TamaguiConfig['tokens']['spaces'][keyof TamaguiConfig['tokens']['spaces']]
|
|
97
|
+
// export type FontSizes = TamaguiConfig['tokens']['fontSizes'][keyof TamaguiConfig['tokens']['fontSizes']]
|
|
98
|
+
// export type Colors = TamaguiConfig['tokens']['colors'][keyof TamaguiConfig['tokens']['colors']]
|
|
99
|
+
|
|
100
|
+
// this is the config generated via createTamagui()
|
|
101
|
+
export type TamaguiInternalConfig<
|
|
102
|
+
A extends GenericTokens = GenericTokens,
|
|
103
|
+
B extends GenericThemes = GenericThemes,
|
|
104
|
+
C extends GenericShorthands = GenericShorthands,
|
|
105
|
+
D extends GenericMedia = GenericMedia
|
|
106
|
+
> = CreateTamaguiConfig<A, B, C, D> & {
|
|
107
|
+
Provider: (props: TamaguiProviderProps) => any
|
|
108
|
+
// with $ prefixes for fast lookups (one time cost at startup vs every render)
|
|
109
|
+
themeParsed: { [key: string]: Variable }
|
|
110
|
+
tokensParsed: CreateTokens<Variable>
|
|
111
|
+
themeConfig: any
|
|
112
|
+
getCSS: () => string
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// prevents const intersections from being clobbered into string, keeping the consts
|
|
116
|
+
export type UnionableString = string & {}
|
|
117
|
+
export type UnionableNumber = number & {}
|
|
118
|
+
export type PropTypes<A extends StaticComponent> = A extends React.FunctionComponent<infer Props>
|
|
119
|
+
? Props
|
|
120
|
+
: unknown
|
|
121
|
+
|
|
122
|
+
export type GenericFont = {
|
|
123
|
+
size: { [key: string | number]: number | Variable }
|
|
124
|
+
lineHeight: { [key: string | number]: number | Variable }
|
|
125
|
+
letterSpacing: { [key: string | number]: number | Variable }
|
|
126
|
+
weight: { [key: string | number]: string | Variable }
|
|
127
|
+
family: string | Variable
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// media
|
|
131
|
+
export type MediaKeys = keyof Media
|
|
132
|
+
export type MediaQueryObject = { [key: string]: string | number | string }
|
|
133
|
+
export type MediaQueryState = {
|
|
134
|
+
[key in string]: boolean
|
|
135
|
+
}
|
|
136
|
+
export type MediaQueryKey = keyof Media
|
|
137
|
+
export type MediaProps<A> = {
|
|
138
|
+
[key in `$${MediaQueryKey}`]?: A
|
|
139
|
+
}
|
|
140
|
+
export type MediaQueries = {
|
|
141
|
+
[key in MediaQueryKey]: MediaQueryObject
|
|
142
|
+
}
|
|
143
|
+
export type ConfigureMediaQueryOptions = {
|
|
144
|
+
queries?: MediaQueries
|
|
145
|
+
defaultActive?: MediaQueryKey[]
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type TransformStyleProps = {
|
|
149
|
+
x?: number
|
|
150
|
+
y?: number
|
|
151
|
+
perspective?: number
|
|
152
|
+
scale?: number
|
|
153
|
+
scaleX?: number
|
|
154
|
+
scaleY?: number
|
|
155
|
+
skewX?: string
|
|
156
|
+
skewY?: string
|
|
157
|
+
matrix?: number[]
|
|
158
|
+
rotate?: string
|
|
159
|
+
rotateY?: string
|
|
160
|
+
rotateX?: string
|
|
161
|
+
rotateZ?: string
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// createComponent props helpers
|
|
165
|
+
|
|
166
|
+
//
|
|
167
|
+
// base props that are accepted by createComponent (additional to react-native-web)
|
|
168
|
+
//
|
|
169
|
+
type ComponentPropsBase = {
|
|
170
|
+
className?: string
|
|
171
|
+
tag?: string
|
|
172
|
+
animated?: boolean
|
|
173
|
+
onHoverIn?: (e: MouseEvent) => any
|
|
174
|
+
onHoverOut?: (e: MouseEvent) => any
|
|
175
|
+
onPress?: (e: GestureResponderEvent) => any
|
|
176
|
+
onPressIn?: (e: GestureResponderEvent) => any
|
|
177
|
+
onPressOut?: (e: GestureResponderEvent) => any
|
|
178
|
+
// WEB ONLY
|
|
179
|
+
onMouseEnter?: (e: GestureResponderEvent) => any
|
|
180
|
+
// WEB ONLY
|
|
181
|
+
onMouseLeave?: (e: GestureResponderEvent) => any
|
|
182
|
+
space?: Tokens['space'][keyof Tokens['space']] | boolean | string | number
|
|
183
|
+
pointerEvents?: string
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
type GetTokenFontKeysFor<A extends 'size' | 'weight' | 'letterSpacing' | 'family' | 'lineHeight'> =
|
|
187
|
+
keyof Tokens['font'][keyof Tokens['font']][A]
|
|
188
|
+
|
|
189
|
+
export type SpaceTokens = `$${keyof Tokens['space']}`
|
|
190
|
+
|
|
191
|
+
//
|
|
192
|
+
// adds in theme short values to relevant props
|
|
193
|
+
//
|
|
194
|
+
type ThemeValue<A> = Omit<A, string> | UnionableString | Variable
|
|
195
|
+
export type WithThemeValues<T extends object> = {
|
|
196
|
+
[K in keyof T]:
|
|
197
|
+
| ThemeValue<T[K]>
|
|
198
|
+
| (K extends ColorableKeys
|
|
199
|
+
? ThemeKeyVariables
|
|
200
|
+
: K extends SizeKeys
|
|
201
|
+
? `$${keyof Tokens['size']}`
|
|
202
|
+
: K extends FontKeys
|
|
203
|
+
? `$${keyof Tokens['font']}`
|
|
204
|
+
: K extends FontSizeKeys
|
|
205
|
+
? `$${GetTokenFontKeysFor<'size'>}`
|
|
206
|
+
: K extends SpaceKeys
|
|
207
|
+
? `$${keyof Tokens['space']}`
|
|
208
|
+
: K extends ColorKeys
|
|
209
|
+
? `$${keyof Tokens['color']}`
|
|
210
|
+
: K extends ZIndexKeys
|
|
211
|
+
? `$${keyof Tokens['zIndex']}`
|
|
212
|
+
: K extends LineHeightKeys
|
|
213
|
+
? `$${GetTokenFontKeysFor<'lineHeight'>}`
|
|
214
|
+
: K extends FontWeightKeys
|
|
215
|
+
? `$${GetTokenFontKeysFor<'weight'>}`
|
|
216
|
+
: K extends FontLetterSpacingKeys
|
|
217
|
+
? `$${GetTokenFontKeysFor<'letterSpacing'>}`
|
|
218
|
+
: {})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
//
|
|
222
|
+
// adds in shorthand props
|
|
223
|
+
//
|
|
224
|
+
type WithShorthands<StyleProps> = {
|
|
225
|
+
[Key in keyof Shorthands]?: Shorthands[Key] extends keyof StyleProps
|
|
226
|
+
? StyleProps[Shorthands[Key]] | null
|
|
227
|
+
: {}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
//
|
|
231
|
+
// add both theme and shorthands
|
|
232
|
+
//
|
|
233
|
+
type WithThemeAndShorthands<A extends object> = WithThemeValues<A> &
|
|
234
|
+
WithShorthands<WithThemeValues<A>>
|
|
235
|
+
|
|
236
|
+
//
|
|
237
|
+
// adds theme and shorthands + pseudo styles with both
|
|
238
|
+
//
|
|
239
|
+
type WithThemeShorthandsAndPseudos<A extends object> = WithThemeAndShorthands<A> & {
|
|
240
|
+
hoverStyle?: WithThemeAndShorthands<A> | null
|
|
241
|
+
pressStyle?: WithThemeAndShorthands<A> | null
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
//
|
|
245
|
+
// adds theme, shorthands, psuedos, then all the previous to media queries
|
|
246
|
+
//
|
|
247
|
+
type WithThemeShorthandsPseudosAndMedia<A extends object> = WithThemeShorthandsAndPseudos<A> &
|
|
248
|
+
MediaProps<WithThemeShorthandsAndPseudos<A>>
|
|
249
|
+
|
|
250
|
+
//
|
|
251
|
+
// Stack
|
|
252
|
+
//
|
|
253
|
+
|
|
254
|
+
type WebOnlyStyleProps = {
|
|
255
|
+
// WEB ONLY
|
|
256
|
+
cursor?: string
|
|
257
|
+
// WEB ONLY
|
|
258
|
+
contain?: 'none' | 'strict' | 'content' | 'size' | 'layout' | 'paint' | string
|
|
259
|
+
// WEB ONLY values: inherit, inline, block, content
|
|
260
|
+
display?: 'inherit' | 'none' | 'inline' | 'block' | 'contents' | 'flex' | 'inline-flex'
|
|
261
|
+
// WEB ONLY pointerEvents can be a style prop
|
|
262
|
+
pointerEvents?: ViewProps['pointerEvents']
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
type StackStyleProps = WithThemeShorthandsPseudosAndMedia<
|
|
266
|
+
Omit<ViewStyle, 'display' | 'backfaceVisibility' | 'elevation'> &
|
|
267
|
+
TransformStyleProps &
|
|
268
|
+
WebOnlyStyleProps
|
|
269
|
+
>
|
|
270
|
+
|
|
271
|
+
export type StackProps = Omit<RNWInternalProps, 'children'> &
|
|
272
|
+
Omit<ViewProps, 'display' | 'children'> &
|
|
273
|
+
StackStyleProps &
|
|
274
|
+
ComponentPropsBase & {
|
|
275
|
+
ref?: RefObject<View | HTMLElement> | ((node: View | HTMLElement) => any)
|
|
276
|
+
children?: any | any[]
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//
|
|
280
|
+
// Text props
|
|
281
|
+
//
|
|
282
|
+
|
|
283
|
+
// type EnhancedTextStyleProps = WithThemeValues<
|
|
284
|
+
// Omit<TextStyle, 'display' | 'backfaceVisibility'> & TransformStyleProps
|
|
285
|
+
// >
|
|
286
|
+
// export type TextStylePropsBase = EnhancedTextStyleProps
|
|
287
|
+
// export type TextStyleProps<S = TextStylePropsBase> = S & {
|
|
288
|
+
// hoverStyle?: S | null
|
|
289
|
+
// pressStyle?: S | null
|
|
290
|
+
// }
|
|
291
|
+
|
|
292
|
+
type TextStyleProps = WithThemeShorthandsPseudosAndMedia<
|
|
293
|
+
Omit<TextStyle, 'display' | 'backfaceVisibility'> & TransformStyleProps & WebOnlyStyleProps
|
|
294
|
+
>
|
|
295
|
+
|
|
296
|
+
export type TextProps = Omit<ReactTextProps, 'style'> &
|
|
297
|
+
TextStyleProps &
|
|
298
|
+
ComponentPropsBase & {
|
|
299
|
+
ellipse?: boolean
|
|
300
|
+
selectable?: boolean
|
|
301
|
+
textDecorationDistance?: number
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
//
|
|
305
|
+
// StaticComponent
|
|
306
|
+
//
|
|
307
|
+
|
|
308
|
+
export type StaticComponent<
|
|
309
|
+
Props = any,
|
|
310
|
+
VariantProps = any,
|
|
311
|
+
StaticConfParsed = StaticConfigParsed,
|
|
312
|
+
ParentVariantProps = any
|
|
313
|
+
> = React.FunctionComponent<Props> & {
|
|
314
|
+
staticConfig: StaticConfParsed
|
|
315
|
+
variantProps?: VariantProps
|
|
316
|
+
|
|
317
|
+
/*
|
|
318
|
+
* Only needed for more complex components
|
|
319
|
+
* If you create a styled frame component this is a HoC to extract
|
|
320
|
+
* styles from all parents.
|
|
321
|
+
*/
|
|
322
|
+
extractable: <X>(a: X) => X
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export type TamaguiProviderProps = Partial<Omit<ThemeProviderProps, 'children'>> & {
|
|
326
|
+
initialWindowMetrics?: any
|
|
327
|
+
fallback?: any
|
|
328
|
+
children?: any
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export type RNWInternalProps = {
|
|
332
|
+
accessibilityState?: {
|
|
333
|
+
busy?: boolean
|
|
334
|
+
checked?: boolean | 'mixed'
|
|
335
|
+
disabled?: boolean
|
|
336
|
+
expanded?: boolean
|
|
337
|
+
grabbed?: boolean
|
|
338
|
+
hidden?: boolean
|
|
339
|
+
invalid?: boolean
|
|
340
|
+
modal?: boolean
|
|
341
|
+
pressed?: boolean
|
|
342
|
+
readonly?: boolean
|
|
343
|
+
required?: boolean
|
|
344
|
+
selected?: boolean
|
|
345
|
+
}
|
|
346
|
+
accessibilityValue?: {
|
|
347
|
+
max?: number
|
|
348
|
+
min?: number
|
|
349
|
+
now?: number
|
|
350
|
+
text?: string
|
|
351
|
+
}
|
|
352
|
+
children?: any
|
|
353
|
+
focusable?: boolean
|
|
354
|
+
nativeID?: string
|
|
355
|
+
onBlur?: (e: any) => void
|
|
356
|
+
onClick?: (e: any) => void
|
|
357
|
+
onClickCapture?: (e: any) => void
|
|
358
|
+
onContextMenu?: (e: any) => void
|
|
359
|
+
onFocus?: (e: any) => void
|
|
360
|
+
onKeyDown?: (e: any) => void
|
|
361
|
+
onKeyUp?: (e: any) => void
|
|
362
|
+
onMoveShouldSetResponder?: (e: any) => boolean
|
|
363
|
+
onMoveShouldSetResponderCapture?: (e: any) => boolean
|
|
364
|
+
onResponderEnd?: (e: any) => void
|
|
365
|
+
onResponderGrant?: (e: any) => void
|
|
366
|
+
onResponderMove?: (e: any) => void
|
|
367
|
+
onResponderReject?: (e: any) => void
|
|
368
|
+
onResponderRelease?: (e: any) => void
|
|
369
|
+
onResponderStart?: (e: any) => void
|
|
370
|
+
onResponderTerminate?: (e: any) => void
|
|
371
|
+
onResponderTerminationRequest?: (e: any) => boolean
|
|
372
|
+
onScrollShouldSetResponder?: (e: any) => boolean
|
|
373
|
+
onScrollShouldSetResponderCapture?: (e: any) => boolean
|
|
374
|
+
onSelectionChangeShouldSetResponder?: (e: any) => boolean
|
|
375
|
+
onSelectionChangeShouldSetResponderCapture?: (e: any) => boolean
|
|
376
|
+
onStartShouldSetResponder?: (e: any) => boolean
|
|
377
|
+
onStartShouldSetResponderCapture?: (e: any) => boolean
|
|
378
|
+
pointerEvents?: 'box-none' | 'none' | 'box-only' | 'auto'
|
|
379
|
+
testID?: string
|
|
380
|
+
// unstable
|
|
381
|
+
dataSet?: Object
|
|
382
|
+
onMouseDown?: (e: any) => void
|
|
383
|
+
onMouseEnter?: (e: any) => void
|
|
384
|
+
onMouseLeave?: (e: any) => void
|
|
385
|
+
onMouseMove?: (e: any) => void
|
|
386
|
+
onMouseOver?: (e: any) => void
|
|
387
|
+
onMouseOut?: (e: any) => void
|
|
388
|
+
onMouseUp?: (e: any) => void
|
|
389
|
+
onScroll?: (e: any) => void
|
|
390
|
+
onTouchCancel?: (e: any) => void
|
|
391
|
+
onTouchCancelCapture?: (e: any) => void
|
|
392
|
+
onTouchEnd?: (e: any) => void
|
|
393
|
+
onTouchEndCapture?: (e: any) => void
|
|
394
|
+
onTouchMove?: (e: any) => void
|
|
395
|
+
onTouchMoveCapture?: (e: any) => void
|
|
396
|
+
onTouchStart?: (e: any) => void
|
|
397
|
+
onTouchStartCapture?: (e: any) => void
|
|
398
|
+
onWheel?: (e: any) => void
|
|
399
|
+
href?: string
|
|
400
|
+
hrefAttrs?: { download?: boolean; rel?: string; target?: string }
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export type StaticConfigParsed = StaticConfig & {
|
|
404
|
+
parsed: true
|
|
405
|
+
propMapper: (
|
|
406
|
+
key: string,
|
|
407
|
+
value: any,
|
|
408
|
+
theme: ThemeObject,
|
|
409
|
+
props: any
|
|
410
|
+
) => undefined | boolean | { [key: string]: any }
|
|
411
|
+
variantsParsed?: {
|
|
412
|
+
[key: string]: {
|
|
413
|
+
[key: string]: any
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export type StaticConfig = {
|
|
419
|
+
Component?: StaticComponent
|
|
420
|
+
|
|
421
|
+
variants?: {
|
|
422
|
+
[key: string]: {
|
|
423
|
+
[key: string]:
|
|
424
|
+
| ((a: any, b: any) => any)
|
|
425
|
+
| {
|
|
426
|
+
[key: string]: any
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/*
|
|
432
|
+
* If you need to pass context or something, prevents from ever
|
|
433
|
+
* flattening. The 'jsx' option means it will never flatten. if you
|
|
434
|
+
* pass JSX as a children (if its purely string, it will still flatten).
|
|
435
|
+
*/
|
|
436
|
+
neverFlatten?: boolean | 'jsx'
|
|
437
|
+
|
|
438
|
+
/*
|
|
439
|
+
* Determines ultimate output tag (Text vs View)
|
|
440
|
+
*/
|
|
441
|
+
isText?: boolean
|
|
442
|
+
|
|
443
|
+
/*
|
|
444
|
+
* Which style keys are allowed to be extracted.
|
|
445
|
+
*/
|
|
446
|
+
validStyles?: { [key: string]: boolean }
|
|
447
|
+
|
|
448
|
+
/*
|
|
449
|
+
* Allows for defining extra valid props to be extracted beyond
|
|
450
|
+
* the default ones.
|
|
451
|
+
*/
|
|
452
|
+
validPropsExtra?: { [key: string]: any }
|
|
453
|
+
|
|
454
|
+
/*
|
|
455
|
+
* Same as React.defaultProps, be sure to sync
|
|
456
|
+
*/
|
|
457
|
+
defaultProps?: any
|
|
458
|
+
|
|
459
|
+
/*
|
|
460
|
+
* If this prop is encountered, bail on all optimization.
|
|
461
|
+
*/
|
|
462
|
+
deoptProps?: Set<string>
|
|
463
|
+
|
|
464
|
+
/*
|
|
465
|
+
* A bit odd, only for more advanced heirarchies.
|
|
466
|
+
* Indicates that the component will set this prop so the
|
|
467
|
+
* static extraction can ensure it sets them to ={undefined}
|
|
468
|
+
* so they get overriddent. In the future, this can be smarter.
|
|
469
|
+
*/
|
|
470
|
+
ensureOverriddenProp?: { [key: string]: boolean }
|
|
471
|
+
|
|
472
|
+
/*
|
|
473
|
+
* We need to wrap children
|
|
474
|
+
*/
|
|
475
|
+
isZStack?: boolean
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
type ColorableKeys =
|
|
479
|
+
| 'color'
|
|
480
|
+
| 'backgroundColor'
|
|
481
|
+
| 'borderColor'
|
|
482
|
+
| 'borderTopColor'
|
|
483
|
+
| 'borderBottomColor'
|
|
484
|
+
| 'borderLeftColor'
|
|
485
|
+
| 'borderRightColor'
|
|
486
|
+
| 'shadowColor'
|
|
487
|
+
|
|
488
|
+
type SizeKeys = 'width' | 'height' | 'minWidth' | 'minHeight' | 'maxWidth' | 'maxHeight'
|
|
489
|
+
|
|
490
|
+
type FontKeys = 'fontFamily'
|
|
491
|
+
|
|
492
|
+
type FontSizeKeys = 'fontSize'
|
|
493
|
+
|
|
494
|
+
type FontWeightKeys = 'fontWeight'
|
|
495
|
+
|
|
496
|
+
type FontLetterSpacingKeys = 'letterSpacing'
|
|
497
|
+
|
|
498
|
+
type LineHeightKeys = 'lineHeight'
|
|
499
|
+
|
|
500
|
+
type ZIndexKeys = 'zIndex'
|
|
501
|
+
|
|
502
|
+
type ColorKeys =
|
|
503
|
+
| 'color'
|
|
504
|
+
| 'backgroundColor'
|
|
505
|
+
| 'borderColor'
|
|
506
|
+
| 'borderBottomColor'
|
|
507
|
+
| 'borderTopColor'
|
|
508
|
+
| 'borderLeftColor'
|
|
509
|
+
| 'borderRightColor'
|
|
510
|
+
|
|
511
|
+
type SpaceKeys =
|
|
512
|
+
| 'padding'
|
|
513
|
+
| 'paddingHorizontal'
|
|
514
|
+
| 'paddingVertical'
|
|
515
|
+
| 'paddingLeft'
|
|
516
|
+
| 'paddingTop'
|
|
517
|
+
| 'paddingBottom'
|
|
518
|
+
| 'paddingLeft'
|
|
519
|
+
| 'paddingRight'
|
|
520
|
+
| 'paddingEnd'
|
|
521
|
+
| 'paddingStart'
|
|
522
|
+
| 'margin'
|
|
523
|
+
| 'marginHorizontal'
|
|
524
|
+
| 'marginVertical'
|
|
525
|
+
| 'marginLeft'
|
|
526
|
+
| 'marginTop'
|
|
527
|
+
| 'marginBottom'
|
|
528
|
+
| 'marginLeft'
|
|
529
|
+
| 'marginRight'
|
|
530
|
+
| 'marginEnd'
|
|
531
|
+
| 'marginStart'
|
|
532
|
+
| 'x'
|
|
533
|
+
| 'y'
|
|
534
|
+
| 'scale'
|
|
535
|
+
| 'scaleX'
|
|
536
|
+
| 'scaleY'
|
|
537
|
+
| 'borderTopEndRadius'
|
|
538
|
+
| 'borderTopLeftRadius'
|
|
539
|
+
| 'borderTopRightRadius'
|
|
540
|
+
| 'borderTopStartRadius'
|
|
541
|
+
| 'borderBottomEndRadius'
|
|
542
|
+
| 'borderBottomLeftRadius'
|
|
543
|
+
| 'borderBottomRightRadius'
|
|
544
|
+
| 'borderBottomStartRadius'
|
|
545
|
+
| 'borderBottomWidth'
|
|
546
|
+
| 'borderLeftWidth'
|
|
547
|
+
| 'borderRadius'
|
|
548
|
+
| 'borderRightWidth'
|
|
549
|
+
| 'borderTopEndRadius'
|
|
550
|
+
| 'borderTopLeftRadius'
|
|
551
|
+
| 'borderTopRightRadius'
|
|
552
|
+
| 'borderEndWidth'
|
|
553
|
+
| 'borderStartWidth'
|
|
554
|
+
| 'borderTopStartRadius'
|
|
555
|
+
| 'borderTopWidth'
|
|
556
|
+
| 'borderWidth'
|
|
557
|
+
| 'left'
|
|
558
|
+
| 'top'
|
|
559
|
+
| 'right'
|
|
560
|
+
| 'bottom'
|
|
561
|
+
| 'shadowOffset'
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import React, { useMemo } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
PerpectiveTransform,
|
|
5
|
+
RotateTransform,
|
|
6
|
+
RotateXTransform,
|
|
7
|
+
RotateYTransform,
|
|
8
|
+
RotateZTransform,
|
|
9
|
+
ScaleTransform,
|
|
10
|
+
ScaleXTransform,
|
|
11
|
+
ScaleYTransform,
|
|
12
|
+
SkewXTransform,
|
|
13
|
+
SkewYTransform,
|
|
14
|
+
TranslateXTransform,
|
|
15
|
+
TranslateYTransform,
|
|
16
|
+
} from 'react-native'
|
|
17
|
+
|
|
18
|
+
import { useIsomorphicLayoutEffect } from '../constants/platform'
|
|
19
|
+
import { useConstant } from '../hooks/useConstant'
|
|
20
|
+
import { StackProps } from '../types'
|
|
21
|
+
import { Stack } from './Stack'
|
|
22
|
+
|
|
23
|
+
const defaultAnimation = {
|
|
24
|
+
from: {
|
|
25
|
+
opacity: 0,
|
|
26
|
+
translateY: 12,
|
|
27
|
+
},
|
|
28
|
+
to: {
|
|
29
|
+
opacity: 1,
|
|
30
|
+
translateY: 0,
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type AnimatableProps = Partial<
|
|
35
|
+
Pick<StackProps, 'backgroundColor' | 'borderColor' | 'opacity'> &
|
|
36
|
+
PerpectiveTransform &
|
|
37
|
+
RotateTransform &
|
|
38
|
+
RotateXTransform &
|
|
39
|
+
RotateYTransform &
|
|
40
|
+
RotateZTransform &
|
|
41
|
+
ScaleTransform &
|
|
42
|
+
ScaleXTransform &
|
|
43
|
+
ScaleYTransform &
|
|
44
|
+
TranslateXTransform &
|
|
45
|
+
TranslateYTransform &
|
|
46
|
+
SkewXTransform &
|
|
47
|
+
SkewYTransform
|
|
48
|
+
>
|
|
49
|
+
|
|
50
|
+
const styleKeys = {
|
|
51
|
+
opacity: true,
|
|
52
|
+
backgroundColor: true,
|
|
53
|
+
borderColor: true,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type AnimatedStackProps = StackProps & {
|
|
57
|
+
animateState?: 'in' | 'out'
|
|
58
|
+
velocity?: number
|
|
59
|
+
animation?: {
|
|
60
|
+
from: AnimatableProps
|
|
61
|
+
to: AnimatableProps
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const AnimatedStack = ({
|
|
66
|
+
animateState = 'in',
|
|
67
|
+
animation = defaultAnimation,
|
|
68
|
+
velocity = 6,
|
|
69
|
+
children,
|
|
70
|
+
animated,
|
|
71
|
+
...props
|
|
72
|
+
}: AnimatedStackProps) => {
|
|
73
|
+
const driver = useConstant(() => {
|
|
74
|
+
return new Animated.Value(0)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const animatedProps = useMemo(() => {
|
|
78
|
+
if (!animated) {
|
|
79
|
+
return null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const styleProps = {}
|
|
83
|
+
const transform: any = []
|
|
84
|
+
|
|
85
|
+
for (const key in animation.from) {
|
|
86
|
+
const fromVal = animation.from[key]
|
|
87
|
+
const toVal = animation.to[key]
|
|
88
|
+
const interpolatedVal = driver.interpolate({
|
|
89
|
+
inputRange: [0, 1],
|
|
90
|
+
outputRange: [fromVal, toVal],
|
|
91
|
+
})
|
|
92
|
+
if (styleKeys[key]) {
|
|
93
|
+
styleProps[key] = interpolatedVal
|
|
94
|
+
} else {
|
|
95
|
+
transform.push({
|
|
96
|
+
[key]: interpolatedVal,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return { transform, ...styleProps }
|
|
101
|
+
}, [animated, animateState])
|
|
102
|
+
|
|
103
|
+
useIsomorphicLayoutEffect(() => {
|
|
104
|
+
if (!animated) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
Animated.spring(driver, {
|
|
108
|
+
useNativeDriver: true,
|
|
109
|
+
velocity,
|
|
110
|
+
toValue: animateState === 'in' ? 1 : 0,
|
|
111
|
+
}).start()
|
|
112
|
+
}, [animated, animateState])
|
|
113
|
+
|
|
114
|
+
const childrenMemo = useMemo(() => children, [children])
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<Stack animated={animated} {...props} {...animatedProps}>
|
|
118
|
+
{childrenMemo}
|
|
119
|
+
</Stack>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
import {
|
|
4
|
+
Metrics,
|
|
5
|
+
SafeAreaProvider as RNSafeAreaProvider,
|
|
6
|
+
initialWindowMetrics as defaultInitialWindowMetrics,
|
|
7
|
+
} from 'react-native-safe-area-context'
|
|
8
|
+
|
|
9
|
+
let defaultMetrics: Metrics | null = null
|
|
10
|
+
|
|
11
|
+
export const SafeAreaProvider = ({
|
|
12
|
+
initialWindowMetrics,
|
|
13
|
+
children,
|
|
14
|
+
}: {
|
|
15
|
+
children?: any
|
|
16
|
+
initialWindowMetrics?: any
|
|
17
|
+
}) => {
|
|
18
|
+
if (!initialWindowMetrics && !defaultMetrics) {
|
|
19
|
+
defaultMetrics = Platform.select({
|
|
20
|
+
web: {
|
|
21
|
+
frame: { x: 0, y: 0, width: 0, height: 0 },
|
|
22
|
+
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
|
23
|
+
},
|
|
24
|
+
default: defaultInitialWindowMetrics,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<RNSafeAreaProvider initialMetrics={initialWindowMetrics ?? defaultMetrics}>
|
|
30
|
+
{children}
|
|
31
|
+
</RNSafeAreaProvider>
|
|
32
|
+
)
|
|
33
|
+
}
|