Is there a way to get a callback one the keyboard ...
# compose
s
Is there a way to get a callback one the keyboard when someone presses the button which minimizes (hides) the keyboard? I wanted to clear focus as they click that button but can’t seem to find a way to do it.
The context of this actually is that I have a TextField in a movableContentOf {} lambda, which I move to one place if the keyboard is open, and another place if the kayboard is closed. What happens is that when I close the keyboard, the textfield gets moved, it’s put in the new position, and the keyboard appears again, since I suppose it looks like it’s a new TextField composable which has focus, so it opens the keyboard again, flipping what I was trying to do initially. So basically I am stuck to the “open keyboard” state as every time I close it it auto-opens again.
a
I’d be a bit cautious when starting to drive more complicated logic that isn’t just spacing related with the insets APIs and
isImeVisible
. If a user is using a hardware keyboard, they can still be editing a text field even if the software keyboard isn’t visible. And if you’re in multi-window mode, there’s no guarantee that your app’s window overlaps with the software keyboard.
s
In this case, I wanted to have 1 style of the UI if the keyboard was open, and another if it was not open. If they were using hardware keyboard then no problem, it’d always be that 1 version of the UI and I wouldn’t change it. And that version of the UI can definitely support editing the text field, hence I was using MovableContent in order to show that same text field in both of these scenarios. For now I went around this issue altogether, as I explain in this thread (even if it’s not 100% correct either, but eh), so I am going around this issue, but besides that, having a TextField being inside a MovableContent, and as it moves from one place to another, the fact that the keyboard shows up automatically was quite tricky. I am sure this also breaks other cases where folks are using TextFields + MovableContent.
a
Agreed,
movableContentOf
should just move things without side-effects from moving, looks like that abstraction is leaking a bit here. Definitely report a bug with a minimal repro of that if you can!
s
Filed here https://issuetracker.google.com/issues/284480124, with a super minimal repro here https://github.com/StylianosGakis/repro-movable-content-textfield-showing-keyboard. Feel free to move it to a more appropriate location, this was the only one that mentioned “runtime” and movableContent is inside .runtime so I figured this should be the right place.