@uiw/react-native
Version:
UIW for React Native
32 lines (27 loc) • 742 B
JavaScript
import React from 'react';
import { LayoutAnimation, StyleSheet, View, TouchableOpacity } from 'react-native';
function ExpandableSection(props) {
const {
expanded = false,
sectionHeader,
children,
top = false
} = props;
const onPress = () => {
props.onPress?.(); // 动画效果
LayoutAnimation.configureNext({ ...LayoutAnimation.Presets.easeInEaseOut,
duration: 300
});
};
return <View style={styles.container}>
{top && expanded && children}
<TouchableOpacity onPress={onPress}>{sectionHeader}</TouchableOpacity>
{!top && expanded && children}
</View>;
}
export default ExpandableSection;
const styles = StyleSheet.create({
container: {
overflow: 'hidden'
}
});