0

I'm currently working with Jetpack Compose version 1.4.3, and I have a BaseTextField component in my UI. However, I noticed that whenever the screen is launched or when the BaseTextField gains focus, the keyboard automatically opens. I want to change this behavior so that the keyboard only opens when the user taps on the BaseTextField.

I have already tried using the LaunchedEffect with FocusRequester to request focus on the BaseTextField only when needed, but the keyboard still opens automatically. I also set the keyboardOptions to KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text) to specify a text keyboard type, but it didn't have the desired effect.

Here is a simplified version of my code:

val focusRequester = remember { FocusRequester() }

BaseTextField(
    value = text,
    onValueChange = { newText -> text = newText },
    keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text),
    modifier = Modifier.focusRequester(focusRequester)
)

LaunchedEffect(Unit) {
    focusRequester.requestFocus()
}

I'm wondering if there is a specific configuration or workaround I need to apply in Jetpack Compose 1.4.3 to prevent the keyboard from opening automatically when the screen is launched or when the BaseTextField gains focus. Any help or guidance would be greatly appreciated. Thank you!

PlusInfosys
  • 3,416
  • 1
  • 19
  • 33

0 Answers0