-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
97 lines (73 loc) · 1.91 KB
/
App.js
File metadata and controls
97 lines (73 loc) · 1.91 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
92
93
94
95
96
97
import React, { Component } from 'react';
import {
View,
Text,
Image,
TouchableOpacity
} from 'react-native';
import styles from './src/styles/index.js'
class App extends Component{
constructor(props){
super(props);
this.state = {
numero: 0,
botao: 'VAI',
ultimo: null
};
//Variavel do timer do relogio.
this.timer = null;
this.vai = this.vai.bind(this);
this.limpar = this.limpar.bind(this);
}
vai(){
if(this.timer != null){
//Aqui vai parar o timer
clearInterval(this.timer);
this.timer = null;
this.setState({botao: 'Iniciar'});
}else{
//Comeca girar o timer
this.timer = setInterval( ()=> {
this.setState({numero: this.state.numero + 0.1})
}, 100);
this.setState({botao: 'PAUSAR'});
}
}
limpar(){
if(this.timer != null){
//Aqui vai parar o timer
clearInterval(this.timer);
this.timer = null;
}
this.setState({
ultimo: this.state.numero,
numero: 0,
botao: 'VAI'
})
}
render(){
return(
<View style={styles.container}>
<Image
source={require('./src/images/cronometro.png')}
style={styles.cronometro}
/>
<Text style={styles.timer}> {this.state.numero.toFixed(1)} </Text>
<View style={styles.btnArea}>
<TouchableOpacity style={styles.btn} onPress={this.vai}>
<Text style={styles.btnTexto}> {this.state.botao} </Text>
</TouchableOpacity>
<TouchableOpacity style={styles.btn} onPress={this.limpar}>
<Text style={styles.btnTexto}>PARAR</Text>
</TouchableOpacity>
</View>
<View style={styles.areaUltima}>
<Text style={styles.textoCorrida}>
{this.state.ultimo > 0 ? 'Último tempo: ' + this.state.ultimo.toFixed(2) + 's' : ''}
</Text>
</View>
</View>
);
}
}
export default App;