-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContador.js
More file actions
150 lines (124 loc) · 3.62 KB
/
Contador.js
File metadata and controls
150 lines (124 loc) · 3.62 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React, {useState, useEffect} from 'react';
import { StatusBar } from 'expo-status-bar';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import {Picker} from '@react-native-picker/picker';
import { LinearGradient } from 'expo-linear-gradient';
import { Audio } from 'expo-av';
export const Contador = (props) => {
var done = false;
useEffect(() => {
const timer = setInterval(() => {
props.setarSegundos(props.segundos - 1)
if (props.segundos <= 0) {
if (props.minutos > 0) {
props.setarMinutos(minutos - 1);
props.setarSegundos(59)
}else{
if (!done) {
done = true;
props.setarEstado('selecionar');
props.setarMinutos(0);
props.setarSegundos(1);
play();
}
}
}
},1000)
return () => clearInterval(timer);
}, )
const resetar = () => {
props.setarEstado('selecionar');
props.setarMinutos(0);
props.setarSegundos(1);
}
const formatarNumeros = (number) => {
var finalNumber = '';
if (number < 10) {
finalNumber = '0' + number;
}else{
finalNumber = number;
}
return finalNumber;
}
var segundos = formatarNumeros(props.segundos);
var minutos = formatarNumeros(props.minutos);
const play = async () => {
const sound = new Audio.Sound();
try {
var alarme;
props.alarmes.map((val) =>{
if (val.selecionado) {
alarme = val.file;
}
})
await sound.loadAsync(alarme);
await sound.playAsync();
// Your sound is playing!
// Don't forget to unload the sound from memory
// when you are done using the Sound object
} catch (error) {
console.log(error);
}
}
return (
<View style={styles.container}>
<StatusBar hidden />
<LinearGradient
// Background Linear Gradient
colors={['rgba(0, 84, 163,0.4)', 'rgba(0, 84, 163,0.9)']}
style={styles.background}
/>
<View style={styles.content}>
<Text style={styles.Text}>{minutos} : </Text>
<Text style={styles.Text}>{segundos}</Text>
</View>
<TouchableOpacity
onPress={() =>resetar() }
style={styles.btnEscolherSelecionado}
>
<Text
style={styles.btnEscolherText}
>
Resetar
</Text>
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
background: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
height: '100%',
},
Text: {
color: 'white',
fontSize: 40,
},
content: {
flexDirection: 'row',
},
btnEscolherSelecionado: {
padding: 10,
backgroundColor: 'rgb(209, 42, 27)',
borderRadius: 20,
marginTop:20,
width: 200,
},
btnEscolherText: {
color: 'white',
textAlign: 'center',
},
});