-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
105 lines (81 loc) · 2.5 KB
/
App.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
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
98
99
100
101
102
103
104
105
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, Picker, TouchableOpacity } from 'react-native';
import { Audio } from 'expo-av';
import { backgroundColor } from 'react-native/Libraries/Components/View/ReactNativeStyleAttributes';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
selecionado: false,
timeOut: null,
contagem: 0
}
}
async tocarAlarme() {
this.soundObject = new Audio.Sound();
try {
await this.soundObject.loadAsync(require('./alarme.m4a'));
await this.soundObject.playAsync();
} catch (error) {
}
}
pressionado = () => {
var intervalo = setInterval(() => {
this.setState({ contagem: this.state.contagem - 1 });
if (this.state.contagem == 0) {
clearInterval(intervalo);
this.setState({
selecionado: false,
timeOut: null,
contagem: 0
});
this.tocarAlarme();
alert('Acabou!');
}
}, 1000);
}
displayTimer = () => {
var contadores = [];
for (var i = 1; i <= 60; i++) {
contadores.push(<Picker.Item label={i.toString()} value={i.toString()} />);
}
if (this.state.selecionado == false) {
return (
<View style={styles.boxTimerSelect}>
<Text style={{ textAlign: 'center', fontSize: 19, color: '#fff', marginTop: 50 }}>Selecione o tempo para o timer:</Text>
<Picker style={{ width: 200, height: 30, marginTop: 20 }} onValueChange={(value, index) => this.setState({ selecionado: true, contagem: value })}>
<Picker.Item label="Selecione o tempo" value="Selecione o tempo..." />
{contadores}
</Picker>
</View>
)
} else {
return (
<View style={styles.boxTimerSelect}>
<Text style={{ textAlign: 'center', fontSize: 19, color: '#fff', marginTop: 50 }}>Contagem: {"\n\n"} {this.state.contagem}</Text>
<TouchableOpacity style={styles.btn} onPress={() => this.pressionado()}><Text style={{ color: '#fff' }}>Começar</Text></TouchableOpacity>
</View>
)
}
}
render() {
return (
<View>{this.displayTimer()}</View>
)
}
}
const styles = StyleSheet.create({
boxTimerSelect: {
display: 'flex',
backgroundColor: '#934cff',
height: '100%',
alignItems: 'center'
},
btn: {
backgroundColor: '#5f32a8',
padding: 10,
borderRadius: 20,
marginTop: 10
}
});