(with decoration used). but it is not working but if I add
Modifier.clickable
in the decoration then it is working. Any idea why
clickable
is not working when added to top BTF
Atul Gupta
02/19/2024, 6:54 AM
Code is like below
Copy code
BasicTextField(
modifier = Modifier
.fillMaxWidth()
.height(50.dp)
.clickable {
Toast.makeText(this@MainActivity, "Basic text field modifier clickable clicked", Toast.LENGTH_LONG).show()
Log.d("Tag123", "Basic text field modifier clickable clicked")
},
value = value.value,
onValueChange = {
value.value = it
},
enabled = true,
decorationBox = { innerTextField ->
val density = LocalDensity.current
Row(
modifier = Modifier
.clickable {
Toast.makeText(this@MainActivity, "Decoration Box of basic text field row modifier clickable clicked", Toast.LENGTH_LONG).show()
Log.d("Tag123", "Decoration Box of basic text field row modifier clickable clicked")
}
.padding(horizontal = 16.dp, vertical = 8.dp)
.width(100.dp)
.height(20.dp)
) {
Box(
modifier = Modifier
.align(Alignment.CenterVertically)
) {
innerTextField()
if (value.value.text.isEmpty()) {
Text(text = "Test")
}
}
}
}
)
Atul Gupta
02/19/2024, 7:03 AM
Here first clickable is not working while clickable inside
decorationBox
is working
a
Ajay Chandran
02/19/2024, 7:08 AM
I guess the BasicTextField by default intercepts the click actions to handle the focus events. And that is the reason why the clickable you defined is not getting called. Wherein if you have a clickable inside the decoration box (i.e, your own view), then it will work.
a
Atul Gupta
02/20/2024, 6:19 AM
Thanks @Ajay Chandran. Is this expected?
a
Ajay Chandran
02/20/2024, 7:10 AM
@Atul Gupta Yes it is.
z
Zach Klippenstein (he/him) [MOD]
02/20/2024, 3:37 PM
If you need to handle touch events on the whole field you can go one level deeper into the pointerInput modifier and watch events in the initial pass, before clickable sees them.