import {LucideChevronDown, LucideChevronUp} from 'lucide-react-native'; import React, {useCallback, useImperativeHandle, useState } from 'react'; import { StyleSheet, Text, View, Animated, LayoutAnimation, Platform, UIManager, TouchableWithoutFeedback, } from 'react-native'; if ( Platform.OS === 'android' && UIManager.setLayoutAnimationEnabledExperimental ) { UIManager.setLayoutAnimationEnabledExperimental(true); } type Props = { title: string; children: React.ReactNode; }; export const Accordion = React.forwardRef((props: Props, ref) => { const {title, children} = props; const [isOpen, setIsOpen] = useState(false); const toggleOpen = useCallback(() => { LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); setIsOpen(!isOpen); }, [isOpen]); useImperativeHandle( ref, () => ({ open: () => { if (isOpen) { return; } return toggleOpen(); }, }), [toggleOpen, isOpen], ); return ( {title} {isOpen ? ( ) : ( )} {isOpen && {children}} ); }); const styles = StyleSheet.create({ accordionSection: { marginBottom: 16, }, accordionTitle: { padding: 10, backgroundColor: '#f0f0f0', }, accordionContent: { overflow: 'hidden', backgroundColor: '#E0E0E0', }, accordionHeader: { fontSize: 20, fontWeight: 'bold', }, });