I am a bit new to react native and been messing around with JSON for some time. I want to display my json data with a calendar event view. I need help in passing activity_periods data to the calendar for each user.
Here is my Json file data :
{
"ok": true,
"members": [{
"id": "W012A3CDE",
"real_name": "Egon Spengler",
"tz": "America/Los_Angeles",
"activity_periods": [{
"start_time": "Feb 1 2020 1:33PM",
"end_time": "Feb 1 2020 1:54PM"
},
{
"start_time": "Mar 1 2020 11:11AM",
"end_time": "Mar 1 2020 2:00PM"
},
{
"start_time": "Mar 16 2020 5:33PM",
"end_time": "Mar 16 2020 8:02PM"
}
]
},
{
"id": "W07QCRPA4",
"real_name": "Glinda Southgood",
"tz": "Asia/Kolkata",
"activity_periods": [{
"start_time": "Feb 1 2020 1:33PM",
"end_time": "Feb 1 2020 1:54PM"
},
{
"start_time": "Mar 1 2020 11:11AM",
"end_time": "Mar 1 2020 2:00PM"
},
{
"start_time": "Mar 16 2020 5:33PM",
"end_time": "Mar 16 2020 8:02PM"
}
]
}
]
}
code to display Userdata using flatlist:
import React, { Component } from 'react'
import { Text, View, StyleSheet, TouchableOpacity, FlatList } from 'react-native';
import {Card} from 'react-native-paper'
import data from '../data/db.json';
export default class UsersScreen extends Component {
render()
{
return(
<View style={styles.container}>
<Text style={styles.header}>User Data</Text>
<FlatList
data={data.members}
renderItem={({item}) => (
<Card
style={{
margin:5,
backgroundColor:'#9075E3',
borderRadius:10
}}
onPress={()=>this.props.navigation.navigate('Schedule')}
>
<View style={styles.datacontainer}>
<Text style={styles.name}>Name - {item.real_name}</Text>
<Text style={styles.location}> Id - {item.id}</Text>
<Text style={styles.location}>Timezone - {item.tz}</Text>
</View>
</Card>
)}
keyExtractor={member=> member.id}
/>
</View>
)
}
}
Help me to resolve this issue here. My code for calendar view as follows:
import React, { Component } from 'react';
import { Text, View, Dimensions } from 'react-native';
import data from '../data/db.json';
import EventCalendar from 'react-native-events-calendar';
let { width } = Dimensions.get('window');
export default class ScheduleScreen extends Component {
render() {
return (
<View style={{ flex: 1, marginTop: 20 }}>
{data.members[0].activity_periods.map((period, index) => {
return(
<EventCalendar
eventTapped={this.eventClicked.bind(this)}
events={
data.members.activity_periods
}
width={width}
size={60}
initDate={'2019-02-01'}
scrollToFirst
/>
)
})}
</View>
);
}
}
first you map the data 1st
after that passing the data through navigation inside your Flatlist