Member-only story
How to Fix Keyboard Issues Introduced in the Latest Jetpack Compose (1.4.0)
Overcoming the issue that I encountered
Recently (March 22, 2023) Google released a new Jetpack Compose stable version 1.4.0. Our team got excited and wanted to try it out, so we found some time to migrate a few days later. At first, everything was working fine. It seemed like we could just bump the version and prepare the PR for review.
A few tests later we found out that the keyboard is not working at all in Dialog Fragments with ComposeView, so basically 20% of our app was broken (all DialogFragments
and BottomSheetDialogFragments
).
Here is an example of the problem:
We have a full-screen DialogFragment with ComposeView. Inside it, there’s only a top bar and a text field. The keyboard should appear after clicking on the text field, but unfortunately, it’s not working.
Let’s have a look a the code:
We start with a simple DialogFragment. In my case, I used a custom style to make it a full-screen dialog. In onCreateView
new ComposeView is returned with Composable content. We will discuss both dialogFragmentComposeView(...)
and DialogContent()
in the next steps:
Next, I declared a dialog content Composable
with Scaffold and one text field to make things easy to see and understand:
Last, but not least is the dialogFragmentComposeView(...)
extension that is used to quickly create a ComposeView
to be used inside a DialogFragment
. Our setup only needs a few things:
- The layout params should be set to
MATCH_PARENT
, just to be sure that our dialog will be full-screen, - The view composition strategy should be set to…