import React, { useEffect, FunctionComponent, useState, useRef } from 'react'; import { LayoutAnimation, Animated } from 'react-native'; import * as Styled from './CollapsibleView.style'; import type { ICollapsibleViewProps } from './CollapsibleView.types'; import { animateIn, animateOut, interpolateRotation, customLayoutAnimation, } from './CollapsibleView.animation'; import { Typography } from '../Typography'; export const CollapsibleView: FunctionComponent = ({ label, children, onChange = () => {}, }) => { const [isOpen, setIsOpen] = useState(false); const rotationValue = useRef(new Animated.Value(0)).current; useEffect(() => { if (isOpen) { animateIn(rotationValue); } else { animateOut(rotationValue); } }, [isOpen]); const labelColor = false ? 'brandPrimary' : 'brandSecondary'; const Label = ( { LayoutAnimation.configureNext(customLayoutAnimation); onChange(!isOpen); setIsOpen(!isOpen); }} > {label} {'V'} ); const Content = isOpen && ( {children} ); return ( {Label} {Content} ); };