Keep push-to-talk held when the finger slides off the button
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.ts3client.android.ui
|
package com.ts3client.android.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.awaitEachGesture
|
||||||
|
import androidx.compose.foundation.gestures.awaitFirstDown
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
@@ -51,14 +52,19 @@ internal fun PushToTalk(
|
|||||||
val colors = MaterialTheme.colorScheme
|
val colors = MaterialTheme.colorScheme
|
||||||
Surface(
|
Surface(
|
||||||
modifier.pointerInput(Unit) {
|
modifier.pointerInput(Unit) {
|
||||||
detectTapGestures(onPress = {
|
// Held until the finger lifts, wherever it wanders; a tap gesture would end once it left the button.
|
||||||
|
awaitEachGesture {
|
||||||
|
awaitFirstDown()
|
||||||
onPressed(true)
|
onPressed(true)
|
||||||
try {
|
try {
|
||||||
awaitRelease()
|
do {
|
||||||
|
val event = awaitPointerEvent()
|
||||||
|
event.changes.forEach { it.consume() }
|
||||||
|
} while (event.changes.any { it.pressed })
|
||||||
} finally {
|
} finally {
|
||||||
onPressed(false)
|
onPressed(false)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
},
|
},
|
||||||
shape = shape,
|
shape = shape,
|
||||||
color = if (talking) StatusColors.talking else colors.primaryContainer,
|
color = if (talking) StatusColors.talking else colors.primaryContainer,
|
||||||
|
|||||||
Reference in New Issue
Block a user