Skip to content

Commit 2c3648a

Browse files
committed
fix: disable delete button when no recording
1 parent 0bfe0c4 commit 2c3648a

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

example/src/App.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ const AppContainer = () => {
227227
const [shouldScroll, setShouldScroll] = useState<boolean>(true);
228228
const [currentPlaying, setCurrentPlaying] = useState<string>('');
229229
const [list, setList] = useState<ListItem[]>([]);
230+
const [nbOfRecording, setNumberOfRecording] = useState<number>(0);
230231
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] =
231232
useState<PlaybackSpeedType>(1.0);
232233

@@ -241,6 +242,12 @@ const AppContainer = () => {
241242
});
242243
}, []);
243244

245+
useEffect(() => {
246+
getRecordedAudios().then(recordedAudios =>
247+
setNumberOfRecording(recordedAudios.length)
248+
);
249+
}, [list]);
250+
244251
const changeSpeed = () => {
245252
setCurrentPlaybackSpeed(
246253
prev =>
@@ -291,20 +298,27 @@ const AppContainer = () => {
291298
<GestureHandlerRootView style={styles.appContainer}>
292299
<View style={styles.screenBackground}>
293300
<View style={styles.container}>
294-
<View style={styles.simformImageContainer}>
301+
<View style={styles.headerContainer}>
295302
<Image
296303
source={Icons.simform}
297304
style={styles.simformImage}
298305
resizeMode="contain"
299306
/>
300307
<Pressable
301-
style={styles.playBackControlPressable}
302-
onPress={handleDeleteRecordings}>
308+
style={[
309+
styles.deleteRecordingContainer,
310+
{ opacity: nbOfRecording ? 1 : 0.5 },
311+
]}
312+
onPress={handleDeleteRecordings}
313+
disabled={!nbOfRecording}>
303314
<Image
304315
source={Icons.delete}
305316
style={styles.buttonImage}
306317
resizeMode="contain"
307318
/>
319+
<Text style={styles.deleteRecordingTitle}>
320+
{'Delete recorded audio files'}
321+
</Text>
308322
</Pressable>
309323
</View>
310324
<ScrollView scrollEnabled={shouldScroll}>

example/src/styles.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,19 @@ const styles = (params: StyleSheetParams = {}) =>
9090
width: '100%',
9191
tintColor: Colors.pink,
9292
},
93-
simformImageContainer: {
93+
headerContainer: {
94+
alignItems: 'center',
95+
},
96+
deleteRecordingContainer: {
9497
alignItems: 'center',
95-
justifyContent: 'space-around',
9698
flexDirection: 'row',
9799
},
100+
deleteRecordingTitle: {
101+
fontSize: scale(20),
102+
fontWeight: 'bold',
103+
color: Colors.pink,
104+
paddingLeft: scale(8),
105+
},
98106
loadingText: {
99107
color: Colors.black,
100108
},

0 commit comments

Comments
 (0)