K Merle
08/18/2022, 10:16 AMStylianos Gakis
08/18/2022, 11:18 AMK Merle
08/18/2022, 11:24 AMsubmit
button when keyboard is opened/closed.submit
button changes a for cause of the windowSoftInputMode
adjustResize
value that we have.Stylianos Gakis
08/18/2022, 11:29 AMWindowInsets.isImeVisible
a try? It’s part of the new compose 1.2 inset APIs.K Merle
08/18/2022, 11:30 AMState
, but just a Boolean
value. So I should still have sort of callback to react to keyboard state change.Stylianos Gakis
08/18/2022, 11:34 AMWindowInsets.isImeVisible
is a composable function, aka you’ll always be getting the latest value. It’s kind of like State<Boolean>
, but you don’t see it, you see just a Boolean
, and get the observability for free since you’re inside a composable function.K Merle
08/18/2022, 11:36 AMfalse
value only.
Having WindowInsets.isImeVisible
inside the composable function and opening and closing the keyboard should be enough to recompose that isImeVisible
and return true when I open keyboard?Stylianos Gakis
08/18/2022, 11:42 AMK Merle
08/18/2022, 11:43 AMStylianos Gakis
08/18/2022, 12:24 PM@Suppress("OPT_IN_MARKER_ON_WRONG_TARGET")
@ExperimentalLayoutApi
@Composable
@NonRestartaleComposable
get() = WindowInsetsHolder.current().ime.isVisible
the getter is a composable function, aka you get this observability.
Take a look at this post from @Zach Klippenstein (he/him) [MOD] at the section Snapshot state: Observation
Composable functions already have this implicit observation logic wired up, which is why code like this would just work:
@Composable fun CounterButton(counter: Counter) {
Text("${counter.label}: ${counter.value}")
}
The Compose compiler wraps the body of this CounterButton function with code that effectively observes any and all MutableStates that happen to be read inside the function.
And isVisible
is in fact a State
object as seen here, so it works.
That’s my understanding of all this at least, I hope I’m not giving you any wrong information here 😊Alejandro Rios
08/18/2022, 12:47 PMK Merle
08/18/2022, 12:51 PMAlex Vanyo
08/18/2022, 5:09 PMWindowInsets.isImeVisible
is snapshot state backed, so it will automatically update when the keyboard is opening and closing.
Are you using WindowCompat.setDecorFitsSytemWindows(window, false)
and adjustResize
? (I think you mentioned adjustResize
)K Merle
08/18/2022, 5:48 PMWindowCompat.setDecorFitsSytemWindows(window, false)
, but dynamically change boolean value, depending on a navigation `route`where I'm at, and I do use adjustResize
true
, and I wasn't getting the keyboard state. Setting it to false
gives me value re-actively as @Stylianos Gakis suggested.Alex Vanyo
08/18/2022, 6:16 PMK Merle
08/18/2022, 6:18 PMAlex Vanyo
08/18/2022, 6:30 PMWindowCompat.setDecorFitsSytemWindows(window, false)
on that screen (handling the insets there yourself) and then getting the accurate value for WindowInsets.isImeVisible
K Merle
08/18/2022, 6:31 PM