import * as React from 'react'; import type { ImageSourcePropType } from 'react-native'; import { StyleSheet, View, useWindowDimensions } from 'react-native'; import Animated, { useAnimatedStyle } from 'react-native-reanimated'; import { colors } from '../../../constants'; import type { AnimatedColorProp } from '../SharedProps'; import { parseAnimatedColorProp } from '../utils/parseAnimatedColorProp'; import { HeaderBackground } from './HeaderBackground'; import { HeaderBackgroundImage } from './HeaderBackgroundImage'; interface HeaderWrapperProps { backgroundColor?: AnimatedColorProp; backgroundImage?: ImageSourcePropType; contentBackgroundColor?: AnimatedColorProp; hasBorderRadius?: boolean; parallaxHeight: number; scrollHeight: number; scrollValue: Animated.SharedValue; tabsContainerBackgroundColor?: AnimatedColorProp; } export const HeaderWrapper: React.FC> = ({ backgroundColor, backgroundImage, children, contentBackgroundColor, hasBorderRadius, parallaxHeight, scrollHeight, scrollValue, tabsContainerBackgroundColor, }) => { const { width } = useWindowDimensions(); const hasBackgroundImage = !!backgroundImage; const contentAnimatedStyle = useAnimatedStyle(() => { // TypeScript complains about AnimatedNode> from reanimated v1 return { backgroundColor: parseAnimatedColorProp(contentBackgroundColor) as string }; }, [contentBackgroundColor]); const foregroundAnimatedStyle = useAnimatedStyle(() => { if (hasBackgroundImage) { return { backgroundColor: colors.transparent }; } return { backgroundColor: parseAnimatedColorProp(tabsContainerBackgroundColor), }; }, [hasBackgroundImage, tabsContainerBackgroundColor]); return ( {backgroundImage ? ( } backgroundHeight={scrollHeight} backgroundImage={backgroundImage} /> ) : ( )} {children} ); }; const styles = StyleSheet.create({ headerStyle: { position: 'absolute', left: 0, top: 0, alignItems: 'flex-start', justifyContent: 'flex-end', }, });