about summary refs log tree commit diff
path: root/src/components/LinearGradientBackground.tsx
blob: 9b28b897c08676d039001dc399df702af830b77b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react'
import {StyleProp, ViewStyle} from 'react-native'
import {LinearGradient} from 'expo-linear-gradient'

import {gradients} from '#/alf/tokens'

export function LinearGradientBackground({
  style,
  gradient = 'sky',
  children,
  start,
  end,
}: {
  style?: StyleProp<ViewStyle>
  gradient?: keyof typeof gradients
  children?: React.ReactNode
  start?: [number, number]
  end?: [number, number]
}) {
  const colors = gradients[gradient].values.map(([_, color]) => {
    return color
  }) as [string, string, ...string[]]

  if (gradient.length < 2) {
    throw new Error('Gradient must have at least 2 colors')
  }

  return (
    <LinearGradient colors={colors} style={style} start={start} end={end}>
      {children}
    </LinearGradient>
  )
}