mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 17:19:27 +01:00
47 lines
1.0 KiB
TypeScript
47 lines
1.0 KiB
TypeScript
import React from 'react'
|
|
import { useWindowDimensions, ViewStyle } from 'react-native'
|
|
import LinearGradient from 'react-native-linear-gradient'
|
|
import colorStyles from '@app/styles/colors'
|
|
|
|
export type GradientBackgroundPropsBase = {
|
|
height?: number | string
|
|
width?: number | string
|
|
position?: 'relative' | 'absolute'
|
|
style?: ViewStyle
|
|
}
|
|
|
|
export type GradientBackgroundProps = GradientBackgroundPropsBase & {
|
|
colors?: string[]
|
|
locations?: number[]
|
|
}
|
|
|
|
const GradientBackground: React.FC<GradientBackgroundProps> = ({
|
|
height,
|
|
width,
|
|
position,
|
|
style,
|
|
colors,
|
|
locations,
|
|
children,
|
|
}) => {
|
|
const layout = useWindowDimensions()
|
|
|
|
return (
|
|
<LinearGradient
|
|
colors={colors || [colorStyles.gradient.high, colorStyles.gradient.low]}
|
|
locations={locations || [0.01, 0.7]}
|
|
style={[
|
|
style,
|
|
{
|
|
width: width || '100%',
|
|
height: height || layout.height,
|
|
position: position || 'absolute',
|
|
},
|
|
]}>
|
|
{children}
|
|
</LinearGradient>
|
|
)
|
|
}
|
|
|
|
export default GradientBackground
|