Skip to content

Commit da0224f

Browse files
committed
Consume recording-transition flag only on announce
Move `onTransitionConsumed()` inside the announcement branches so the caller's `cancelRequested` flag only clears when an announcement has actually fired. The bug described in the review doesn't manifest with the current state writers (the wrapped `onCancelRecording` / `onDeleteRecording` set the flag and `setState(Idle)` in the same Compose snapshot) but separating "transition observed" from "transition consumed" tightens the helper's contract and makes it robust to future changes to the flag writers or the `LaunchedEffect` keys.
1 parent 4b6ddf9 commit da0224f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/composer/internal/AudioRecordingAccessibility.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ internal fun Modifier.micButtonSemantics(): Modifier {
6161
* @param recordingState Current recording state to observe.
6262
* @param cancelRequested `true` when the user invoked a cancel or delete action since the last
6363
* transition was processed.
64-
* @param onTransitionConsumed Invoked after each processed transition so the caller can reset
65-
* [cancelRequested] to `false`.
64+
* @param onTransitionConsumed Invoked only when a transition is actually announced, so the
65+
* caller can reset [cancelRequested] to `false`. Transitions that don't result in an
66+
* announcement leave the flag untouched.
6667
*/
6768
@Composable
6869
internal fun AnnounceRecordingTransitions(
@@ -80,18 +81,21 @@ internal fun AnnounceRecordingTransitions(
8081
LaunchedEffect(currentIsIdle, currentIsHold) {
8182
val wasIdle = previousWasIdle
8283
previousWasIdle = currentIsIdle
84+
var consumed = false
8385
when (recordingState) {
8486
is RecordingState.Hold -> if (wasIdle) {
8587
view.announceForAccessibility(startedAnnouncement)
88+
consumed = true
8689
}
8790
is RecordingState.Idle -> if (!wasIdle && cancelRequested) {
8891
view.announceForAccessibility(cancelledAnnouncement)
92+
consumed = true
8993
}
9094
is RecordingState.Locked,
9195
is RecordingState.Overview,
9296
is RecordingState.Complete,
9397
-> Unit
9498
}
95-
onTransitionConsumed()
99+
if (consumed) onTransitionConsumed()
96100
}
97101
}

0 commit comments

Comments
 (0)