I am trying to intercept clicks on a text to chang...
# compose
u
I am trying to intercept clicks on a text to change the text colors. Both click and color work as expected. However, because of this interception,
talkback a11y
doesn't focus on the text anymore. Doesn't anyone know what could be wrong with this approach?
Copy code
var isTextPressed by remember { mutableStateOf(false) }
Text(
    modifier = Modifier
        .pointerInput(Unit) {
            detectTapGestures(
                onPress = {
                    isTextPressed = true
                    if (tryAwaitRelease()) {
                        isTextPressed = false
                    }
                },
                onTap = {
                    onClick.invoke()
                }
            )
        }
    ...
    ...
)
t
@Utkarsh Tiwari i’m having the same issue. Have you find a fix?
u
Give this a try:
Copy code
val interactionSource = remember { MutableInteractionSource() }
val isPressed by interactionSource.collectIsPressedAsState()
val interactionModifier =
    Modifier
        .clickable(
            interactionSource,
            indication = rememberRipple(color = Color.Blue),
            enabled = enabled
        ) { onClick() }
And apply the
interactionModifier
to your target composable
t
Unfortunately i need
pointerInput
to detect zoom and pan on an image
My only issue is with talkback and have no idea how to make it work again with the image
t
@Utkarsh Tiwari Maybe you have to wrap the modifier into
composed { }
.