https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

02/01/2022, 7:34 PM
I'm building a simple todo app. There is a single text field when you open the app and it should have the keyboard ready when the app opens. Is this the right way to do it?
Copy code
val focusRequester = FocusRequester()

  DisposableEffect(Unit) {
      focusRequester.requestFocus()
      onDispose { }
  }
  
OutlinedTextField(label = {Text("TODO")}, modifier = Modifier.focusRequester(focusRequester),
Or do I not need a sideEffect?
c

Colton Idle

02/01/2022, 7:39 PM
OOf. thats what i get for not scrolling up a bit. and here I thought I was following most of the conversations...
f

FunkyMuse

02/01/2022, 10:28 PM
Usually everyone scrolls up to their question only 😁 I have mine not answered about 2D scrolling and i made 100 solutions that don't work but still hoping it'll be answered 🤷‍♂️
s

Stylianos Gakis

02/02/2022, 9:30 AM
Colton did you get it to work without getting the exception I am showing here ? And if the solution is putting the DisposableEffect below the declaration of the focusRequester modifier, I wonder if this should be considered a hack and if it will even work if for whatever reason they run in opposite order.
c

Colton Idle

02/02/2022, 8:38 PM
No exceptions nope. My sample above works, I just wanted to know if that's the "right" way to do what I wanted to do. @Zach Klippenstein (he/him) [MOD] sorry for the direct mention, but I know you are working on text fields and focus now. Can you confirm if this is all you need to have a keyboard show up on launch?
Copy code
val focusRequester = FocusRequester()

  DisposableEffect(Unit) {
      focusRequester.requestFocus()
      onDispose { }
  }
  
OutlinedTextField(label = {Text("TODO")}, modifier = Modifier.focusRequester(focusRequester),
z

Zach Klippenstein (he/him) [MOD]

02/05/2022, 4:36 PM
That should do it
🎉 2
6 Views