Skip to content

Commit 234a97a

Browse files
committed
commiting finished work
1 parent 4df786a commit 234a97a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4608
-44
lines changed

App.js

+33-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
1-
import React from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
1+
import React, { Component } from 'react';
2+
import { YellowBox } from 'react-native';
3+
import { createAppContainer } from 'react-navigation';
4+
import { createStackNavigator } from 'react-navigation-stack';
5+
import EventList from './EventList';
6+
import EventForm from './EventForm';
37

4-
export default function App() {
5-
return (
6-
<View style={styles.container}>
7-
<Text>Hello world!</Text>
8-
</View>
9-
);
10-
}
8+
// class App extends Component {
9+
// render() {
10+
// return (
11+
// <EventList />
12+
// );
13+
// }
14+
// }
1115

12-
const styles = StyleSheet.create({
13-
container: {
14-
flex: 1,
15-
backgroundColor: '#FFF',
16-
alignItems: 'center',
17-
justifyContent: 'center',
16+
YellowBox.ignoreWarnings([
17+
'Warning: componentWillMount is deprecated',
18+
'Warning: componentWillReceiveProps is deprecated',
19+
'Warning: componentWillReceiveProps has been renamed',
20+
]);
21+
22+
const AppNavigator = createStackNavigator({
23+
list: {
24+
screen: EventList,
25+
navigationOptions: () => ({
26+
title: 'Your Events',
27+
}),
28+
},
29+
form: {
30+
screen: EventForm,
31+
navigationOptions: () => ({
32+
title: 'Add Event',
33+
}),
1834
},
1935
});
36+
37+
export default createAppContainer(AppNavigator);

EventCard.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React from 'react';
2+
import { Text, View, StyleSheet } from 'react-native';
3+
import PropTypes from 'prop-types';
4+
import { formatDate, getCountdownParts } from './api';
5+
import EventCounterPart from './EventCounterPart';
6+
7+
const styles = StyleSheet.create({
8+
card: {
9+
backgroundColor: '#fff',
10+
flex: 1,
11+
padding: 10,
12+
paddingTop: 10,
13+
paddingBottom: 20,
14+
margin: 10,
15+
marginTop: 5,
16+
marginBottom: 5,
17+
},
18+
cardHeader: {
19+
flex: 1,
20+
flexDirection: 'row',
21+
},
22+
date: {
23+
fontWeight: '200',
24+
fontSize: 15,
25+
color: '#bdbdbd',
26+
width: '30%',
27+
textAlign: 'right',
28+
},
29+
title: {
30+
fontSize: 15,
31+
fontWeight: '300',
32+
marginLeft: 7,
33+
textAlign: 'left',
34+
},
35+
counterContainer: {
36+
flex: 1,
37+
flexDirection: 'row',
38+
justifyContent: 'space-between',
39+
paddingLeft: '5%',
40+
paddingRight: '5%',
41+
},
42+
});
43+
44+
function EventCard({event}) {
45+
const { days, hours, minutes, seconds } = getCountdownParts(event.date);
46+
47+
return (
48+
<View style={styles.card}>
49+
<View style={styles.cardHeader}>
50+
<Text style={styles.date}>{formatDate(event.date)} </Text>
51+
<Text style={styles.title}>{event.title}</Text>
52+
</View>
53+
<View style={styles.counterContainer}>
54+
<EventCounterPart counter={days} label={'DAYS'} />
55+
<EventCounterPart counter={hours} label={'HOURS'} />
56+
<EventCounterPart counter={minutes} label={'MINUTES'} />
57+
<EventCounterPart counter={seconds} label={'SECONDS'} />
58+
</View>
59+
</View>
60+
);
61+
}
62+
63+
EventCard.propTypes = {
64+
event: PropTypes.shape({
65+
title: PropTypes.string.isRequired,
66+
date: PropTypes.instanceOf(Date)
67+
}),
68+
}
69+
70+
export default EventCard;

EventCounterPart.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { View, Text, StyleSheet } from 'react-native';
3+
import PropTypes from 'prop-types';
4+
5+
const styles = StyleSheet.create({
6+
counter: {
7+
width: '25%',
8+
flex: 1,
9+
},
10+
counterText: {
11+
fontSize: 40,
12+
textAlign: 'center',
13+
},
14+
counterLabel: {
15+
fontSize: 13,
16+
fontWeight: '100',
17+
color: '#a3a3a3',
18+
textAlign: 'center',
19+
paddingTop: 0,
20+
},
21+
});
22+
23+
function EventCounterPart({counter, label}) {
24+
return (
25+
<View style={styles.counter}>
26+
<Text style={styles.counterText}>{counter}</Text>
27+
<Text style={styles.counterLabel}>{label}</Text>
28+
</View>
29+
);
30+
}
31+
32+
EventCounterPart.propTypes = {
33+
counter: PropTypes.number.isRequired,
34+
label: PropTypes.string.isRequired,
35+
}
36+
37+
export default EventCounterPart;
38+

EventForm.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import React, { Component } from 'react';
2+
import { View, Text, TextInput, TouchableHighlight, StyleSheet } from 'react-native';
3+
import DateTimePicker from '@react-native-community/datetimepicker';
4+
import { formatDateTime, saveEvent } from './api';
5+
6+
const styles = StyleSheet.create({
7+
fieldContainer: {
8+
marginTop: 20,
9+
marginBottom: 20,
10+
backgroundColor: '#fff',
11+
},
12+
text: {
13+
height: 40,
14+
margin: 0,
15+
marginRight: 7,
16+
paddingLeft: 10,
17+
},
18+
button: {
19+
height: 50,
20+
backgroundColor: '#48BBEC',
21+
borderColor: '#48BBEC',
22+
alignSelf: 'stretch',
23+
margin: 10,
24+
justifyContent: 'center',
25+
alignItems: 'center',
26+
borderRadius: 5,
27+
},
28+
buttonText: {
29+
color: '#fff',
30+
fontSize: 20,
31+
},
32+
borderTop: {
33+
borderColor: '#edeeef',
34+
borderTopWidth: 1,
35+
}
36+
});
37+
38+
class EventForm extends Component {
39+
state = {
40+
title: null,
41+
date: Date.now(),
42+
showDatePicker: false,
43+
}
44+
45+
handleAddPress = () => {
46+
saveEvent(this.state)
47+
.then(() => this.props.navigation.navigate('list'));
48+
}
49+
50+
handleChangeTitle = (value) => {
51+
this.setState({title: value });
52+
}
53+
54+
handleDatePress = () => {
55+
this.setState({showDatePicker: true });
56+
}
57+
58+
handleHideDatePicker = () => {
59+
this.setState({showDatePicker: false });
60+
}
61+
62+
handleDatePicked = (event, date) => {
63+
date = date || this.state.date;
64+
this.setState({
65+
date,
66+
showDatePicker: Platform.OS === 'ios' ? true : false,
67+
});
68+
}
69+
70+
render() {
71+
const { title, date, showDatePicker } = this.state;
72+
return (
73+
<View style={{flex: 1}}>
74+
<View style={styles.fieldContainer}>
75+
<TextInput
76+
style={styles.text}
77+
placeholder="Event title"
78+
spellCheck={false}
79+
onChangeText={this.handleChangeTitle}
80+
value={title}
81+
/>
82+
<TextInput
83+
style={[styles.text, styles.borderTop]}
84+
placeholder="Event date"
85+
spellCheck={false}
86+
value={formatDateTime(date)}
87+
editable={!this.state.showDatePicker}
88+
onFocus={this.handleDatePress}
89+
/>
90+
{showDatePicker &&
91+
<DateTimePicker
92+
mode="datetime"
93+
onChange={this.handleDatePicked}
94+
value={date}
95+
/> }
96+
</View>
97+
<TouchableHighlight onPress={this.handleAddPress} style={styles.button}>
98+
<Text style={styles.buttonText}>Add</Text>
99+
</TouchableHighlight>
100+
</View>
101+
);
102+
}
103+
}
104+
105+
export default EventForm;

EventList.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React, { Component } from 'react';
2+
import { FlatList, StyleSheet } from 'react-native';
3+
import ActionButton from 'react-native-action-button';
4+
import EventCard from './EventCard';
5+
import { getEvents } from './api';
6+
7+
const styles = StyleSheet.create({
8+
list: {
9+
flex: 1,
10+
paddingTop: 60,
11+
backgroundColor: '#F3F3F3',
12+
marginBottom: 100,
13+
}
14+
});
15+
16+
class EventList extends Component {
17+
state = {
18+
events: []
19+
}
20+
21+
componentDidMount() {
22+
setInterval(() => {
23+
this.setState({
24+
events: this.state.events.map(event => ({
25+
...event,
26+
timer: Date.now(),
27+
}))
28+
});
29+
}, 1000);
30+
31+
this.props.navigation.addListener('didFocus', () => {
32+
getEvents().then(events => this.setState({ events }));
33+
});
34+
}
35+
36+
listItem(item) {
37+
return <EventCard event={item} />;
38+
}
39+
40+
handleAddEvent = () => {
41+
this.props.navigation.navigate('form');
42+
}
43+
44+
render() {
45+
return [
46+
<FlatList
47+
key="flatlist"
48+
data={this.state.events}
49+
renderItem={({ item }) => this.listItem(item)}
50+
keyExtractor={item => item.id}
51+
style={styles.list}
52+
/>,
53+
<ActionButton
54+
key="actionbutton"
55+
onPress={this.handleAddEvent}
56+
buttonColor="rgba(231, 76, 60,1)"
57+
/>
58+
]
59+
}
60+
}
61+
62+
export default EventList;

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# React Native event countdown
2+
3+
to start the application:
4+
5+
You will need to have Expo client installed on your mobile device.
6+
7+
1. `npm install`
8+
2. `json-server --host <ipaddress>db.json`
9+
3. In a separate terminal window run `npm start`

0 commit comments

Comments
 (0)