mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {StyleProp, ViewStyle} from 'react-native'
3import {LinearGradient} from 'expo-linear-gradient'
4
5import {gradients} from '#/alf/tokens'
6
7export function LinearGradientBackground({
8 style,
9 gradient = 'sky',
10 children,
11 start,
12 end,
13}: {
14 style?: StyleProp<ViewStyle>
15 gradient?: keyof typeof gradients
16 children?: React.ReactNode
17 start?: [number, number]
18 end?: [number, number]
19}) {
20 const colors = gradients[gradient].values.map(([_, color]) => {
21 return color
22 }) as [string, string, ...string[]]
23
24 if (gradient.length < 2) {
25 throw new Error('Gradient must have at least 2 colors')
26 }
27
28 return (
29 <LinearGradient colors={colors} style={style} start={start} end={end}>
30 {children}
31 </LinearGradient>
32 )
33}