-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
117 lines (112 loc) · 2.95 KB
/
App.tsx
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
import { StatusBar } from "expo-status-bar";
import {
ActivityIndicator,
StyleSheet,
Text,
TouchableOpacity,
View,
} from "react-native";
import useAudioRecording from "./src/hooks/useAudioRecording";
import useFileSystemCheck from "./src/hooks/useFileSystemCheck";
export default function App() {
useFileSystemCheck();
const {
error,
readingCache,
currentReading,
hasAudioPermissions,
startRecording,
stopRecording,
isRecording,
numberOfReadings,
} = useAudioRecording();
// const buttonDisabled = !hasAudioPermissions || isRecording;
return (
<View style={styles.container}>
<View style={styles.resultsContainer}>
<Text style={styles.title}>Audio Meter App</Text>
<Text style={[styles.dbReading, { fontSize: 16 }]}>
{numberOfReadings} samples taken
</Text>
{!isRecording && (
<Text style={styles.dbReading}>
{currentReading?.db ? currentReading.db.toFixed(2) + "dB" : ""}
</Text>
)}
{!isRecording && (
<Text style={[styles.dbReading, { fontSize: 16 }]}>
{currentReading?.meter
? "Meter: " + currentReading.meter.toFixed(2)
: ""}
</Text>
)}
{!isRecording && (
<Text style={[styles.dbReading, { fontSize: 16 }]}>
{currentReading?.float
? "Float: " + currentReading.float.toFixed(2)
: ""}
</Text>
)}
{isRecording && (
<View style={styles.loadingContainer}>
<ActivityIndicator size="large" />
</View>
)}
</View>
<TouchableOpacity
onPressOut={isRecording ? stopRecording : startRecording}
>
<View style={[styles.button]}>
<Text style={[styles.buttonText]}>
{!isRecording ? "TAKE SAMPLE" : "READING..."}
</Text>
</View>
</TouchableOpacity>
{error && <Text style={[styles.title, { fontSize: 16 }]}>{error}</Text>}
<Text style={[styles.title, { fontSize: 16 }]}>
{JSON.stringify(readingCache)}
</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#121212",
alignItems: "center",
justifyContent: "center",
},
resultsContainer: {
alignItems: "center",
justifyContent: "center",
minHeight: 300,
},
title: {
color: "#f7f7f7",
textAlign: "center",
fontSize: 30,
},
dbReading: { color: "#f7f7f7", fontSize: 60, fontWeight: "bold" },
loadingContainer: {
justifyContent: "center",
alignItems: "center",
minHeight: 80,
},
button: {
backgroundColor: "red",
width: 200,
height: 200,
borderRadius: 100,
justifyContent: "center",
alignItems: "center",
padding: 20,
elevation: 3,
},
buttonText: {
textAlign: "center",
color: "#f7f7f7",
fontSize: 30,
fontWeight: "bold",
},
});