-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
148 lines (133 loc) · 3.78 KB
/
App.tsx
File metadata and controls
148 lines (133 loc) · 3.78 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
import React, { useState, useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { View, StyleSheet, Alert } from 'react-native';
import FloatingButtons from './src/components/FloatingButtons';
import Settings from './src/components/Settings';
import { screenRecorder } from './src/utils/screenRecorder';
import type { RecordingSettings } from './src/utils/screenRecorder';
const Stack = createNativeStackNavigator();
function HomeScreen({ navigation }) {
const [isRecording, setIsRecording] = useState(false);
const [settings, setSettings] = useState<RecordingSettings>({
maxDuration: 60,
autoDelete: false,
retentionDays: 7,
quality: 'high',
includeMicrophone: false,
});
useEffect(() => {
loadSettings();
}, []);
const loadSettings = async () => {
const savedSettings = await screenRecorder.getSettings();
if (savedSettings) {
setSettings(savedSettings);
}
};
const handleRecord = async () => {
try {
const success = await screenRecorder.startRecording(settings);
if (success) {
setIsRecording(true);
} else {
Alert.alert('Error', 'Failed to start recording');
}
} catch (error) {
Alert.alert('Error', error instanceof Error ? error.message : 'An unknown error occurred');
}
};
const handleStop = async () => {
const recordingPath = await screenRecorder.stopRecording();
setIsRecording(false);
if (recordingPath) {
Alert.alert('Success', 'Recording saved successfully');
} else {
Alert.alert('Error', 'Failed to save recording');
}
};
const handleSettings = () => {
if (isRecording) {
Alert.alert(
'Recording in Progress',
'Do you want to stop recording and go to settings?',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Stop and Go',
style: 'destructive',
onPress: async () => {
await handleStop();
navigation.navigate('Settings');
},
},
]
);
} else {
navigation.navigate('Settings');
}
};
return (
<View style={styles.container}>
<FloatingButtons
isRecording={isRecording}
onRecord={handleRecord}
onStop={handleStop}
onSettings={handleSettings}
/>
</View>
);
}
function SettingsScreen({ navigation }) {
const [settings, setSettings] = useState<RecordingSettings>({
maxDuration: 60,
autoDelete: false,
retentionDays: 7,
quality: 'high',
includeMicrophone: false,
});
useEffect(() => {
loadSettings();
}, []);
const loadSettings = async () => {
const savedSettings = await screenRecorder.getSettings();
if (savedSettings) {
setSettings(savedSettings);
}
};
const handleSave = async (newSettings) => {
await screenRecorder.saveSettings(newSettings);
navigation.goBack();
};
return <Settings initialSettings={settings} onSave={handleSave} />;
}
export default function App() {
return (
<SafeAreaProvider>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{
title: 'Recording Settings',
presentation: 'modal',
}}
/>
</Stack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
});