-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
109 lines (100 loc) · 2.55 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
106
107
108
109
// Example of React Native Timer and Stopwatch
// https://aboutreact.com/react-native-timer-stopwatch/
// import React in our code
import React, {useState} from 'react';
// import all the components we are going to use
import {
SafeAreaView,
StyleSheet,
Text,
View,
TouchableHighlight,
} from 'react-native';
// importing library to use Stopwatch and Timer
import {Stopwatch, Timer} from 'react-native-stopwatch-timer';
const App = () => {
const [isTimerStart, setIsTimerStart] = useState(false);
const [isStopwatchStart, setIsStopwatchStart] = useState(false);
const [timerDuration, setTimerDuration] = useState(90000);
const [resetTimer, setResetTimer] = useState(false);
const [resetStopwatch, setResetStopwatch] = useState(false);
return (
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<Text style={styles.title}>
(Very) Simple Stopwatch
</Text>
<View style={styles.sectionStyle}>
<Stopwatch
laps
msecs
start={isStopwatchStart}
// To start
reset={resetStopwatch}
// To reset
options={options}
// Options for the styling
getTime={(time) => {
console.log(time);
}}
/>
<TouchableHighlight
onPress={() => {
setIsStopwatchStart(!isStopwatchStart);
setResetStopwatch(false);
}}>
<Text style={styles.buttonText}>
{!isStopwatchStart ? 'START' : 'STOP'}
</Text>
</TouchableHighlight>
<TouchableHighlight
onPress={() => {
setIsStopwatchStart(false);
setResetStopwatch(true);
}}>
<Text style={styles.buttonText}>RESET</Text>
</TouchableHighlight>
</View>
</View>
</SafeAreaView>
);
};
export default App;
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 10,
justifyContent: 'center',
alignItems: 'center',
},
title: {
textAlign: 'center',
fontSize: 20,
fontWeight: 'bold',
padding: 20,
},
sectionStyle: {
flex: 1,
marginTop: 32,
alignItems: 'center',
justifyContent: 'center',
},
buttonText: {
fontSize: 20,
marginTop: 10,
},
});
const options = {
container: {
backgroundColor: '#000000',
padding: 5,
borderRadius: 5,
width: 200,
alignItems: 'center',
},
text: {
fontSize: 25,
color: '#FFF',
marginLeft: 7,
},
};