import { FlashList } from '@shopify/flash-list'; import { useState } from 'react'; import { StyleSheet, Text, TouchableOpacity, TouchableOpacityProps, View } from 'react-native'; import Animated, { FadeInUp, FadeOut, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'; import type { AccordionListProps, FCCWD } from '../../types'; import { applyDefaults } from '../../core/KitraProvider'; import OcticonsIcon from '../Icons/Octicons'; const AnimatedIcon = Animated.createAnimatedComponent(OcticonsIcon); const AccordionList: FCCWD = ({ data, label, left, right, labelContainerStyle, labelStyle, rowTextStyle, rowStyle, onSelect, onExpand, theme, typography, itemDisplay, testID, }) => { const [expanded, setExpanded] = useState(false); const listHeight = useSharedValue(0); const iconRotation = useSharedValue(0); const [contentHeight, setContentHeight] = useState(0); const animatedStyle = useAnimatedStyle(() => ({ height: listHeight.value, }), [contentHeight]); const iconStyle = useAnimatedStyle(() => ({ transform: [{ rotateZ: `${iconRotation.value}deg` }], }), [contentHeight]); const handleListOpen = () => { if (expanded) { listHeight.value = withTiming(0); iconRotation.value = withTiming(0); } else { onExpand?.(); listHeight.value = withTiming(contentHeight, { duration: 600 }); iconRotation.value = withTiming(180, { duration: 200 }); } setExpanded(prev => !prev); }; return ( <> {left && left(expanded)} {label} {right && right(expanded)} { if (h > 0 && h !== contentHeight) setContentHeight(h); }} renderItem={({ item }) => ( onSelect(item)}> {itemDisplay(item)} )} /> ); }; export default applyDefaults(AccordionList); const styles = StyleSheet.create({ labelContianer: { padding: 10, flexDirection: 'row', alignItems: 'center', borderRadius: 3 }, labelText: { textAlign: 'left', marginHorizontal: 10, flex: 1 }, iconContainer: { borderRadius: 3, paddingVertical: 6, paddingHorizontal: 10 }, itemContainer: { padding: 10 }, });