eygraber
03/08/2023, 7:19 PMWindowInsets.isImeVisible returns false when the keyboard is showing if the softInputMode is set to pan?Alex Vanyo
03/09/2023, 12:19 AMadjustPan can cause changes that the app isn’t fully aware of.
adjustResize gives the most consistent results across API versions, as it gives the most information to the app about how the insets are changingeygraber
03/09/2023, 12:31 AMadjustResize deprecated though? Does it make sense to only use it until the API version it was deprecated in, and then switch to adjustPan?Alex Vanyo
03/09/2023, 1:21 AMadjustPan. For simplicity I usually just specify adjustResize only in the manifest, but you should be able to apply adjustResize for API 29 and below, and adjustPan for API 30 and above. I’d actually be very interested to know if that works if you try it out!eygraber
03/09/2023, 1:22 AMeygraber
03/09/2023, 5:23 AMadjustResize then WindowInsets.isImeVisible works correctly, but TextField isn't properly scrolled into view when it gets focus.
If I use adjustPan then the TextField is properly scrolled into view when it gets focus, but WindowInsets.isImeVisible doesn't work correctly.Alex Vanyo
03/09/2023, 6:33 PMadjustResize, are you changing the size of the scrollable container itself based on the IME insets?eygraber
03/09/2023, 6:52 PMWindowInsets.isImeVisible to drive treatment of a BasicTextField decorationBox. When the IME is visible we draw a border around the area that the next character will display.eygraber
03/09/2023, 6:53 PMAlex Vanyo
03/09/2023, 6:57 PMWindowCompat.setDecorFitsSystemWindows(window, false), then you’ll want to ensure you are applying insets to your components to avoid overlapping.
But it sounds like you might want to have logic based on whether the text field is focused? If you’re using a hardware keyboard, you might want to have the border visible as well?eygraber
03/09/2023, 7:02 PMandroid:fitsSystemWindows to false and we're using the Scaffold composable at the top level of all of our screens (single activity)eygraber
03/09/2023, 9:16 PMandroid:fitsSystemWindows to true and used adjustResize (I didn't add WindowCompat.setDecorFitsSystemWindows(window, false)) and that seems to be working on all API levels, where WindowInsets.isImeVisible is working correctly, and the container is scrolling correctly to show the text field.Alex Vanyo
03/09/2023, 9:21 PMfitsSystemWindows is providing the inset handling, but since the app is getting notified more than with adjustPan, WindowInsets.isImeVisible is still giving the correct value.
If you want the nice synchronized IME animations, or to go edge-to-edge with more fine-tuned behavior, then you’ll probably want to turn fitSystemWindows back to false, and handle the insets directly at a per screen level (using imePadding and other modifiers)
But glad you found a solution that works for you as you are converting.eygraber
03/09/2023, 9:22 PMeygraber
03/09/2023, 10:02 PMadjustPan and it looks like it doesn't get notified at all on API 29 and below. Is that expected?eygraber
03/10/2023, 7:08 PMadjustPan and fitSystemWindows=false I was able to get scrolling and isImeVisible working correctly on API 29 and below by setting windowTranslucentStatus and windowTranslucentNavigation to false (they were both true previously).
However, now screens that aren't using Compose aren't handling insets correctly (i.e. there's padding added to the views). To fix that I call WindowCompat.setDecorFitsSystemWindows(window, false) in my Activity, but that causes isImeVisible to not work correctly again.Alex Vanyo
03/10/2023, 7:11 PMBut it sounds like you might want to have logic based on whether the text field is focused? If you’re using a hardware keyboard, you might want to have the border visible as well?If you’re just using
isImeVisible for that behavioreygraber
03/10/2023, 7:16 PMisImeVisible so I'd rather bite the bullet now and fix it before it becomes a problemAlex Vanyo
03/10/2023, 7:21 PMisImeVisible will likely be false. But the user could still be inputting text.eygraber
03/10/2023, 7:24 PMI'm just an engineer I don't have a say in these things 😬That was just my lame attempt at humor. I'm more concerned with the latter point that I raised.
Alex Vanyo
03/10/2023, 7:25 PMadjustResize for API 29 and below with WindowCompat.setDecorFitsSystemWindows(window, false) will give your app the most information in the long term, although then you will need to be sure to avoid overlapping issues and handle insets directly. I wouldn’t expect adjustPan to work reliably on API 29 and below as per https://issuetracker.google.com/issues/176400965Stylianos Gakis
03/10/2023, 7:28 PMIsn’tIs that true? I’ve always see this as being the de-facto way to get the best kind of backwards compatibility when using that +deprecated thoughadjustResize
WindowCompat.setDecorFitsSystemWindows(window, false). Is there any case where one would not want to use that? If thy were targeting minSdk = 30+ for example? I wonder if there’s any material in the docs regarding picking the right choice for you, among adjustResize and its alternativesAlex Vanyo
03/10/2023, 8:08 PMWindowCompat.setDecorFitsSystemWindows(window, false) is the simplest and most consistent way to get good behavior.
(Once your minSdk is API 30, you could probably switch to adjustNothing but I haven’t tested that in detail. And setting it dynamically instead of in the manifest in the meantime can be troublesome and quirky)eygraber
03/10/2023, 8:12 PMadjustNothing on API 30+ doesn't scroll to the focused TextFieldAlex Vanyo
03/10/2023, 8:20 PMimePadding() or similar?
To go edge-to-edge, get good IME inset animations, and the most consistent isImeVisible value, and want the most consistent behavior across API versions, the setup to go with is:
• adjustResize in manifest
• WindowCompat.setDecorFitsSystemWindows(window, false) in Activity.onCreate
Once you’re handling insets yourself completely, it is up to you to handle resizing scrolling views so that elements remain visible (Compose 1.4.0 has improvements there for LazyColumn in particular)
In some sense, the most reliable answers to isImeVisible are available only when you are going edge-to-edge and the app is handling all insets, instead of the platform.eygraber
03/10/2023, 8:32 PMimePadding in this case, together with the setup you specified.eygraber
03/10/2023, 8:37 PMadjustResize
• WindowCompat.setDecorFitsSystemWindows(window, false) in Activity.onCreate
• imePadding() on the text field
and this device is on API 33
(for now I stopped using isImeVisible just for simplicity)Csabi Szenczi
03/10/2023, 8:40 PMAlex Vanyo
03/10/2023, 8:43 PMeygraber
03/10/2023, 8:49 PMColumn with verticalScroll that lives in the content of a Scaffoldeygraber
03/10/2023, 8:52 PMAlex Vanyo
03/10/2023, 8:53 PMModifier.imePadding?eygraber
03/10/2023, 8:56 PMTextField (those boxes are all one `BasicTextField`; we're using a decorationBox to achieve that look)Alex Vanyo
03/10/2023, 8:57 PMColumn instead?Alex Vanyo
03/10/2023, 9:04 PMModifier.verticalScroll that’s thereeygraber
03/10/2023, 9:04 PMeygraber
03/10/2023, 9:08 PMisImeVisible is working as wellAlex Vanyo
03/10/2023, 9:11 PM1.10.0-rc01 of androidx.core for getting better IME animations on API 29 and below as wellAlex Vanyo
03/10/2023, 9:12 PM1.4.0 releases, LazyColumn should work the same way, if the LazyColumn itself becomes smaller. (contentPadding doesn’t work though with that though, that’s a known issue still)eygraber
03/10/2023, 9:16 PMLazyColumn needs imePadding as well?Alex Vanyo
03/10/2023, 9:16 PMeygraber
03/10/2023, 9:19 PMAlex Vanyo
03/10/2023, 9:24 PMeygraber
03/10/2023, 9:38 PMadjustNothing for API 30+ or stick with adjustResize?Alex Vanyo
03/10/2023, 9:40 PMadjustResize in the manifest for all API versions