import React, { FunctionComponent, useEffect, useRef } from 'react'; import { TouchableOpacity, Animated } from 'react-native'; import type { ITabProps } from './Tab.types'; import * as Styled from './Tab.styles'; import { Typography } from '../Typography'; export const Tab: FunctionComponent = ({ label, isSelected = false, ...touchableProps }) => { const scale = useRef(new Animated.Value(0)).current; const opacity = useRef(new Animated.Value(0)).current; const duration = 300; const useNativeDriver = true; const fadeIn = Animated.timing(opacity, { toValue: 1, duration, useNativeDriver, }); const fadeOut = Animated.timing(opacity, { toValue: 0, duration, useNativeDriver, }); const scaleUp = Animated.timing(scale, { toValue: 1, duration, useNativeDriver, }); const scaleDown = Animated.timing(scale, { toValue: 0, duration, useNativeDriver, }); useEffect(() => { (isSelected ? Animated.parallel([fadeIn, scaleUp]) : Animated.parallel([fadeOut, scaleDown]) ).start(); }, [isSelected]); return ( {label} ); };