-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventList.js
More file actions
57 lines (50 loc) · 1.19 KB
/
Copy pathEventList.js
File metadata and controls
57 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { Component } from 'react';
import { FlatList, StyleSheet } from 'react-native';
import EventCard from './EventCard';
import ActionButton from 'react-native-action-button';
import { getEvents } from './api';
const styles = StyleSheet.create({
list: {
flex: 1,
paddingTop: 20,
backgroundColor: '#F3F3F3'
},
});
class EventList extends Component {
state = {
events: []
}
componentDidMount() {
setInterval(() => {
this.setState({
events: this.state.events.map(evt => ({
...evt,
timer: Date.now()
})),
})
}, 1000);
this.props.navigation.addListener('didFocus', () => {
getEvents().then(events => this.setState({ events }));
});
}
handleAddEvent = () => {
this.props.navigation.navigate('form');
};
render() {
return [
<FlatList
key="flatlist"
style={styles.list}
data={this.state.events}
renderItem={({ item }) => <EventCard event={item} />}
keyExtractor={item => item.id}
/>,
<ActionButton
key="fab"
onPress={this.handleAddEvent}
buttonColor="rgba(231, 76, 60, 1)"
/>
]
}
}
export default EventList;