-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimer.js
48 lines (47 loc) · 1.14 KB
/
Timer.js
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
import React from 'react';
import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';
export default class Timer extends React.Component {
state = {
time: 240,
};
startTimer = () => {
this.interval = setInterval(() => {
this.setState(state => ({
time: state.time - 1,
}));
}, 1000);
};
stopTimer = () => {
clearInterval(this.interval);
};
render() {
return (
<View
style={{
flexDirection: 'row',
alignContent: 'space-around',
justifyContent: 'center',
}}>
<View style={{flexDirection: 'column', marginRight: 10}}>
<TouchableOpacity onPress={this.startTimer}>
<Text style={styles.text}>Start</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.stopTimer}>
<Text style={styles.text}>Stop</Text>
</TouchableOpacity>
</View>
<Text style={styles.time}>{this.state.time}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
text: {
fontSize: 17.5,
fontWeight: '500',
},
time: {
fontSize: 25,
fontWeight: '500',
},
});