Are there any samples for detecting keyboard visib...
# compose
c
Are there any samples for detecting keyboard visibility? I've looked around and can't find any outside of
LocalView.current.rootWindowInsets?.isVisible(WindowInsets.Type.ime())
. But that's for api 30+... I've tried to use
accompanist's insets
api to see if there's insets (for the keyboard) but to no success.
b
Try
LocalWindowInsets.current.ime.isVisible
c
That is a check for if it's open in a composable, yep. I'm looking for a listener to react to visibility changes. If there's a way to observe that value via a
snapshotFlow
that would be ideal but I can't find one at the moment.
👀 1
c
You can observe that value from a
snapshotFlow{}
just fine:
Copy code
val imeInsets = LocalWindowInsets.current.ime
LaunchedEffect(imeInsets) {
    snapshotFlow { imeInsets.isVisible }
}
💯 2
c
You can do that but unfortunately (I'm not sure if this is why or not) when the keyboard is dismissed it doesn't emit a new value to that flow. I believe snapshotFlow needs a mutableState object in order to have values emitted to it and isVisible is just a boolean in an interface
Is there any way to hook into Accompanists's
OnApplyWindowInsetsListener
? Probably not but worth asking 😄
c
Nope, it will trigger for anything which reads snapshots (state), which that does.
If you have a sample which reproduces this, please raise an issue on the repo. This is more likely to be an
WindowInsetsCompat
issue though, as the < API 30 logic is tricky.
c
Okay I'll look more into this. I wasn't calling `
Copy code
WindowCompat.setDecorFitsSystemWindows(window, false)
from my BaseActivity. I assume that boolean value needs to be false for accompanist to provide insets? With that value as false my bottom bar and toolbar are gone so I need to do some investigation. Thanks for the information! If I'm able to sort out my bars being gone and it still doesn't update I'll raise an issue :)
c
The guide is probably worth a read as it covers this: https://google.github.io/accompanist/insets/