https://kotlinlang.org logo
#compose-android
Title
# compose-android
d

dan

07/10/2023, 2:26 AM
#compose-android How can I intercept touch even in parent widget? like the demo, what should I do to control log print in Box?
Copy code
Box() {
    Text("test",Modifier.clickable {
        LogUtil.i("Text click")
    } )
}
k

Kirill Grouchnikov

07/10/2023, 4:26 AM
You don’t need to tag the channel name in every post. You’re already here.
As to your question, is it only for touch events, or for any user interaction such as keyboard, accessibility traversal, etc? What do you mean by intercept - block, conditionally handle, something else?
d

dan

07/10/2023, 5:58 AM
only touch and draw,my requirement is if the main switch close, the other function can't operate, such as : click to open a dialog, draw a slider, click other switch
j

Julius Hinze

07/11/2023, 12:15 PM
You should define a state e.g. (note this is pseudocode)
var isClicked = remember mutableStateOf false
And then you can do
onClick = { isClicked = true
} . To show a slider you use conditional rendering, e.g. with
AnimatedVisibility(isClicked) { Slider() }
. Opening a dialog is something else. I suggest you post another question here.
4 Views