import React, { useState } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, Image } from 'react-native';
const Accordion = () => {
const [activeSection, setActiveSection] = useState(null);
const sections = [
{
title: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
content: 'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo',
image: 'https://www.bootdey.com/image/500x500/6495ED/000000'
},
{
title: 'sed do eiusmod tempor incididunt ut labore et dolore',
content: 'Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eiu',
image: 'https://www.bootdey.com/image/500x500/008B8B/000000'
},
{
title: 'Duis aute irure dolor in reprehenderit',
content: 'Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur',
image: 'https://www.bootdey.com/image/500x500/FF00FF/000000'
}
];
return (
<View style={styles.container}>
<View style={styles.accordionContainer}>
{sections.map((section, index) => (
<View key={index}>
<TouchableOpacity
style={styles.titleContainer}
onPress={() => setActiveSection(index)}
>
<Text style={styles.title}>{section.title}</Text>
</TouchableOpacity>
{activeSection === index && (
<View style={styles.contentContainer}>
<Text style={styles.content}>{section.content}</Text>
<Image style={styles.sectionImage} source={{uri:section.image}} />
</View>
)}
</View>
))}
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor:'#fff'
},
accordionContainer: {
margin: 10,
marginTop:60,
},
titleContainer: {
backgroundColor: '#f2f2f2',
padding: 10,
borderRadius: 5,
marginBottom: 5,
},
title: {
fontWeight: 'bold',
fontSize: 16,
},
contentContainer: {
backgroundColor: '#f9f9f9',
padding: 10,
borderRadius: 5,
marginBottom: 5,
},
content: {
fontSize: 14,
},
sectionImage: {
marginTop:20,
width: '100%',
height: 200,
borderRadius:6,
},
});
export default Accordion;
About this react-native template
This react-native template, simple collapsible accordion with title content and image, was published on Jan 20th 2023, 08:52 by Bootdey Admin and it is free.
We hope you will enjoy this awesome react-native template and stay tuned for the latest updates, we believe it will save your precious time and gives trendy look to your next application.
This template currectly have 1.9K views, Using this react-native template you have the following benefits:
Example Screens
You can jump start your development with our pre-built example, all you need to do is copy the code and execute it, You can also show it to your customers so that they have an idea of the final result.
Cross-platform for mobile development
This template was developed for Android and iOS.
Simple Integration
This template can be simply integrated on existing projects and new ones too, all you need to do is copy the code and start working.
Fully coded view
this is a functional example, You will save a lot of time going from prototyping to full-functional code.