When I click on a bottom `BasicTextField`, the key...
# compose
a
When I click on a bottom
BasicTextField
, the keyboard covers the input. Is this expected behavior (even with
adjustResize
)?
Copy code
LazyColumn {
  items((1..100).toList()) { BasicTextField("$it", {}) }
}
👍 1
An android layout--either as below or as a recycler view--would scroll a bottom element up to the top of the keyboard input.
Copy code
<ScrollView
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
  <LinearLayoutandroid:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <EditText
      android:text="hi there"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
    </EditText>
    ...
  </LinearLayout>
</ScrollView>
I'm not sure why Compose doesn't do the same with lists currently. A
Box
(with
adjustResize
set on your
AndroidManifest.xml
) scrolls the
BasicEditField
upwards just fine, it should be noted. But this approach doesn't work with lists, as mentioned above.
Copy code
Box(Modifier.fillMaxSize()) {
  BasicTextField(
    "This works",
    {},
    Modifier.align(Alignment.BottomStart)
  )
}
w
It does not work when there is a scrollable parent involved like LazyColumn & verticalScroll Modifier on a parent You can use relocation requester to bring it into the view currently and this is not a permanent fix but works with one line text fields in a lazy column , Its not the "right way" to do it as well ! You would have to wait for compose team to fix this
🙌 1
a
Thanks man. That's really helpful. I didn't know about
RelocationRequester
. I've found a hacky solution with
onFocusChanged
.
Copy code
.onFocusChanged {
  if("$it" == "Active") {
    scope.launch {
      delay(200)
      relocationRequester.bringIntoView()
    }
  }
}
It's obviously hackey with the
delay
and having to convert
FocusState
to a string to get to the internal
FocusStateImpl.Active
value. Seems to work for simple cases, however.
👍 1
b
For me it works just once. When i dismiss the keyboard and press the textfield again, it does not scroll. Did you try that?