mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at thread-bug 60 lines 1.5 kB view raw
1import {StyleSheet, type TextProps} from 'react-native' 2import {type PathProps, type SvgProps} from 'react-native-svg' 3import {Defs, LinearGradient, Stop} from 'react-native-svg' 4import {nanoid} from 'nanoid/non-secure' 5 6import {tokens, useTheme} from '#/alf' 7 8export type Props = { 9 fill?: PathProps['fill'] 10 style?: TextProps['style'] 11 size?: keyof typeof sizes 12 gradient?: keyof typeof tokens.gradients 13} & Omit<SvgProps, 'style' | 'size'> 14 15export const sizes = { 16 xs: 12, 17 sm: 16, 18 md: 20, 19 lg: 24, 20 xl: 28, 21 '2xl': 32, 22} as const 23 24export function useCommonSVGProps(props: Props) { 25 const t = useTheme() 26 const {fill, size, gradient, ...rest} = props 27 const style = StyleSheet.flatten(rest.style) 28 const _size = Number(size ? sizes[size] : rest.width || sizes.md) 29 let _fill = fill || style?.color || t.palette.primary_500 30 let gradientDef = null 31 32 if (gradient && tokens.gradients[gradient]) { 33 const id = gradient + '_' + nanoid() 34 const config = tokens.gradients[gradient] 35 _fill = `url(#${id})` 36 gradientDef = ( 37 <Defs> 38 <LinearGradient 39 id={id} 40 x1="0" 41 y1="0" 42 x2="100%" 43 y2="0" 44 gradientTransform="rotate(45)"> 45 {config.values.map(([stop, fill]) => ( 46 <Stop key={stop} offset={stop} stopColor={fill} /> 47 ))} 48 </LinearGradient> 49 </Defs> 50 ) 51 } 52 53 return { 54 fill: _fill, 55 size: _size, 56 style, 57 gradient: gradientDef, 58 ...rest, 59 } 60}