code review:

- Removed redundant equality guards in SideEffect — MutableState already suppresses no-op writes for value types
- Changed mutableStateOf({}) to mutableStateOf(null) with explicit nullable type — clearer intent, no accidental no-op invocation
-  stopRecording() now early-returns with ?: return when not recording, so the Toast only shows for genuinely failed recordings (too short)
This commit is contained in:
davotoula
2026-03-24 09:25:07 +01:00
parent 4e43b14b09
commit e976bf9e2e
2 changed files with 6 additions and 11 deletions
@@ -79,7 +79,8 @@ fun RecordAudioBox(
}
fun stopRecording() {
val result = mediaRecorder.value?.stop()
val recorder = mediaRecorder.value ?: return
val result = recorder.stop()
mediaRecorder.value = null
if (result != null) {
onRecordTaken(result)
@@ -138,9 +139,7 @@ fun RecordAudioBox(
},
content = { active ->
content(active, elapsedSeconds) {
if (isRecording) {
stopRecording()
}
stopRecording()
}
},
)
@@ -50,7 +50,7 @@ fun RecordVoiceButton(
) {
var isRecording by remember { mutableStateOf(false) }
var elapsedSeconds by remember { mutableIntStateOf(0) }
var onStopRecording by remember { mutableStateOf({}) }
var onStopRecording: (() -> Unit)? by remember { mutableStateOf(null) }
Column(
verticalArrangement = Arrangement.Center,
@@ -73,12 +73,8 @@ fun RecordVoiceButton(
maxDurationSeconds = maxDurationSeconds,
) { recordingState, elapsed, onStop ->
SideEffect {
if (isRecording != recordingState) {
isRecording = recordingState
}
if (elapsedSeconds != elapsed) {
elapsedSeconds = elapsed
}
isRecording = recordingState
elapsedSeconds = elapsed
onStopRecording = onStop
}