julioromano
01/29/2021, 2:09 PMBasicTextField
and an IconButton
, Iād like to give focus to the text field (and therefore have the on screen keyboard appear) at the press of the button.
Which API should I use?Adriano Celentano
01/29/2021, 3:08 PMSoftwareKeyboardController
FocusRequester
is what i used before, not sure it fits the use case or if its still up to dateZach Klippenstein (he/him) [MOD]
01/29/2021, 6:25 PMdecorationBox
API in alpha11? https://android-review.googlesource.com/c/platform/frameworks/support/+/1537302julioromano
02/02/2021, 4:21 PM@Composable
fun MyWidget(
text: String,
onTextChange: (text: String) -> Unit
) {
var isVisible by mutableStateOf(false)
if (isVisible) {
BasicTextField(
value = text,
onValueChange = onTextChange
)
} else {
IconButton(
onClick = {
isVisible = true
// we should shift focus on BasicTextField here
// therefore the on screen keyboard should reveal itself
}
) {
Icon(
imageVector = <http://Icons.Default.Info|Icons.Default.Info>,
contentDescription = null
)
}
}
}
How can the decorationBox
help here?Zach Klippenstein (he/him) [MOD]
02/02/2021, 4:30 PMZach Klippenstein (he/him) [MOD]
02/02/2021, 4:31 PMinnerTextField
function conditionally?julioromano
02/02/2021, 4:31 PMjulioromano
02/02/2021, 4:31 PMjulioromano
02/02/2021, 4:43 PMYou must call innerTextField exactly once.
it is possible to call it 0 times.
Though when isVisible
is flipped to true
and innerTextField
is actually called, the text field becomes visible but still no keyboard pops up automatically (another tap in the text field is needed).Zach Klippenstein (he/him) [MOD]
02/02/2021, 5:09 PMZach Klippenstein (he/him) [MOD]
02/02/2021, 5:09 PMjulioromano
02/03/2021, 1:47 PMZach Klippenstein (he/him) [MOD]
02/03/2021, 4:46 PMjulioromano
02/03/2021, 7:50 PMinnerTextField
0 times?
Or because of the focus thing?
IMHO itās correct that calling innerTextField
merely shows the text field without necessarily shift focus to it.
One would not always want to move focus into a text field on every recomposition.Zach Klippenstein (he/him) [MOD]
02/03/2021, 7:58 PMdecoratedBox
, the text field should get focus any time the box has focus. If the text view was already shown, and you clicked in the box, then it would definitely be a bug if the text field wasnāt shown.
I suspect the resolution to the bug would be āthrow if called zero or >1 timesā, but at least then it prevents others from going down this path erroneously.julioromano
02/04/2021, 8:32 AMZach Klippenstein (he/him) [MOD]
02/04/2021, 5:52 PM