-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
91 lines (84 loc) · 2.19 KB
/
Copy pathApp.js
File metadata and controls
91 lines (84 loc) · 2.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from 'react';
import { StyleSheet, Text, View, ImageBackground, TouchableOpacity } from 'react-native';
import bgImg from './assets/bg.jpg'
export default class App extends React.Component {
state = {
count: 0,
}
onUp = () => {
const { count } = this.state
this.setState({ count: count + 1 })
}
onDown = () => {
const { count } = this.state
const newCount = count > 0 ? count - 1 : 0
this.setState({ count: newCount })
}
onReset = () => {
this.setState({ count: 0 })
}
render() {
const { count } = this.state
return (
<ImageBackground style={styles.container} source={bgImg}>
<View style={styles.headerContainer}>
<Text style={styles.title}>{count}</Text>
</View>
<View style={styles.bodyContainer}>
<TouchableOpacity style={styles.button} onPress={this.onUp}>
<Text style={styles.buttonTitle}>Count Up!</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this.onDown}>
<Text style={styles.buttonTitle}>Count Down</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={this.onReset}>
<Text style={styles.buttonTitle}>Reset</Text>
</TouchableOpacity>
</View>
</ImageBackground>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fff',
},
headerContainer: {
flex: 2,
width: '100%',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
bodyContainer: {
flex: 1,
flexDirection: 'column',
alignSelf: 'stretch',
justifyContent: 'space-between',
paddingBottom: 20,
},
button: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(255, 255, 255, 0.4)',
marginVertical: 15,
marginHorizontal: 20,
borderRadius: 60,
},
title: {
color: 'white',
fontSize: 140,
fontWeight: 'bold',
},
buttonTitle: {
color: 'black',
fontSize: 16,
fontWeight: 'bold',
},
});