Earlier, with `onImeActionPerformed` argument to T...
# compose
k
Earlier, with
onImeActionPerformed
argument to TextField, I had a chance to implement some global logic for all the actions. Like I had written if the action was
Done
, hide the software keyboard and it was possible to do so because of the handy
softwareKeyboardController
argument to
onImeActionPerformed
. How can I do the same using KeyboardActions now? The callback methods are not “Composables” so I won't even be able to use
LocalSoftwareKeyboardController.current
a
get the reference outside the callback?
k
Doesn’t work. It was not accessible for some reason. Also, do you think it’d work? I feel like we don’t know when that callback will be called and getting reference outside it wouldn’t always be valid.
a
Works for me.
Copy code
val keyboard = LocalSoftwareKeyboardController.current
OutlinedTextField(
  keyboardActions = KeyboardActions {
    keyboard?.hideSoftwareKeyboard()
  }
)
k
Oh, I was trying to access it inside
with(options.keyboardActions) { ... }
, changing it as below solved the issue. (
options
here is my delegate class)