mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-09 08:04:45 +00:00
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:
@@ -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()
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
+3
-7
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user