Status Update
Comments
lp...@google.com <lp...@google.com> #2
Which API level are you seeing the issue here with?
di...@google.com <di...@google.com> #3
My hunch is that this is related to DialogFragment
or ComponentDialog
adds a new Window
that the contained ComposeView
is not aware of.
lp...@google.com <lp...@google.com> #4
I've only tested this on API level 33 and 26 so far, and out of these two I'm seeing this only on 33
lp...@google.com <lp...@google.com> #5
Hello,
We're also experiencing this issue starting from compose 1.4.0-alpha03 and API level >= 30.
Attaching min repro project. Similar issue was filed in Aug 25, 2021 here
di...@google.com <di...@google.com> #6
Experiencing the same issue. Slowly migrating the project to compose and i still need the some compose views to be inside a DialogFragment.
di...@google.com <di...@google.com> #7
Faced the same and like #3 mentioned, compose switched to use a DialogWindowProvider
to figure out its window.
To workaround it in the meantime I copied ComposeView and made it report my dialog window. Not easy, but you cant get past creating a subclass.
internal abstract class ComposeBottomSheetFragment : BottomSheetDialogFragment() { // Can be simple DialogFragment
@Composable protected abstract fun Content()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return ComposeDialogView(requireContext()).also {
it.consumeWindowInsets = false
it.layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT)
it.setContent {
OurTheme { Content() }
}
}
}
// Copy of ComposeView that is able to supply the dialog window to compose.
// I used inner class but you can also pass a lambda to the view and lazily request the window
inner class ComposeDialogView(context: Context) : AbstractComposeView(context, null, 0), DialogWindowProvider {
// The important bit
override val window get() = requireDialog().window!!
private val content = mutableStateOf<(@Composable () -> Unit)?>(null)
override var shouldCreateCompositionOnAttachedToWindow: Boolean = false
private set
@Composable
override fun Content() {
content.value?.invoke()
}
override fun getAccessibilityClassName(): CharSequence = ComposeView::class.java.name
/**
* Set the Jetpack Compose UI content for this view.
* Initial composition will occur when the view becomes attached to a window or when
* [createComposition] is called, whichever comes first.
*/
fun setContent(content: @Composable () -> Unit) {
shouldCreateCompositionOnAttachedToWindow = true
this.content.value = content
if (isAttachedToWindow) createComposition()
}
}
private var ComposeDialogView.consumeWindowInsets: Boolean
get() = getTag(androidx.compose.ui.R.id.consume_window_insets_tag) as? Boolean ?: true
set(value) {
setTag(androidx.compose.ui.R.id.consume_window_insets_tag, value)
}
}
lp...@google.com <lp...@google.com> #8
That workaround should work, due to this line:
Only seeing this issue on API 30 and above also makes sense, due to the underlying mechanics.
di...@google.com <di...@google.com> #9
I tested with the stable 1.4.0 version, having the same problem.
di...@google.com <di...@google.com> #11
override val window by lazy {
requireDialog().window!!
}
lp...@google.com <lp...@google.com> #12
It looks like in my case that it tries to fetch the window to close the soft keyboard after the dialog window has disappeared
java.lang.NullPointerException
at com.xyz.compose.ComposeDialogFragment$windowProvider$2$1.getWindow(ComposeFragment.kt:101)
at com.xyz.compose.ComposeDialogFragment$ComposeDialogView.getWindow(Unknown Source:2)
at androidx.compose.ui.text.input.ImmHelper30.findWindow(InputMethodManager.kt:159)
at androidx.compose.ui.text.input.ImmHelper30.getInsetsControllerCompat(InputMethodManager.kt:133)
at androidx.compose.ui.text.input.ImmHelper30.hideSoftInput(InputMethodManager.kt:152)
at androidx.compose.ui.text.input.InputMethodManagerImpl.hideSoftInput(InputMethodManager.kt:83)
at androidx.compose.ui.text.input.TextInputServiceAndroid.setKeyboardVisibleImmediately(TextInputServiceAndroid.android.kt:397)
at androidx.compose.ui.text.input.TextInputServiceAndroid.processInputCommands(TextInputServiceAndroid.android.kt:302)
at androidx.compose.ui.text.input.TextInputServiceAndroid.sendInputCommand$lambda$1(TextInputServiceAndroid.android.kt:209)
at androidx.compose.ui.text.input.TextInputServiceAndroid.$r8$lambda$tFIm8sXGny3G873nGUe23EJe7OY(Unknown Source:0)
at androidx.compose.ui.text.input.TextInputServiceAndroid$$ExternalSyntheticLambda0.run(Unknown Source:2)
at androidx.compose.ui.text.input.TextInputServiceAndroid_androidKt.asExecutor$lambda$1$lambda$0(TextInputServiceAndroid.android.kt:504)
at androidx.compose.ui.text.input.TextInputServiceAndroid_androidKt.$r8$lambda$RYljF3nl5HRu6JKEM8xFRHwbGFg(Unknown Source:0)
at androidx.compose.ui.text.input.TextInputServiceAndroid_androidKt$$ExternalSyntheticLambda0.doFrame(Unknown Source:2)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1229)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
at android.view.Choreographer.doCallbacks(Choreographer.java:899)
at android.view.Choreographer.doFrame(Choreographer.java:827)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
di...@google.com <di...@google.com> #13
Any progress on this issue? Seems like it breaks a lot of things, I can't migrate to 1.4
lp...@google.com <lp...@google.com> #14
Branch: androidx-main
commit 1763fd0e7b7e11e0ac928762c2c6d16f0c049762
Author: Zach Klippenstein <klippenstein@google.com>
Date: Thu Apr 13 14:34:16 2023
Fix keyboard not showing when text field is in non-Compose dialog.
Fixes:
Test: TextFieldFocusCustomDialogTest
Relnote: "Fixed regression where keyboard wasn't showing for text fields
inside dialogs not created by the `Dialog` composable."
Change-Id: I825512cde7e41dadfc8b7491bd24190d21b14729
M compose/foundation/foundation/build.gradle
M compose/foundation/foundation/src/androidAndroidTest/AndroidManifest.xml
A compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/textfield/TextFieldFocusCustomDialogTest.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/text/input/InputMethodManager.kt
lp...@google.com <lp...@google.com> #15
There is any plan about which version is the bug fix planned to be released in?
ap...@google.com <ap...@google.com> #17
Thanks for the explanation, so the BOM versions will also be updated within a month (like 2023.04.xx)? If so, that will be great!
ap...@google.com <ap...@google.com> #18
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.foundation:foundation:1.4.2
androidx.compose.ui:ui:1.4.2
na...@google.com <na...@google.com> #19
Branch: androidx-main
commit 7545cec3617ab5d1ea83d66822bc094e7f03c562
Author: José Figueroa Santos <serniebanders@google.com>
Date: Wed Apr 19 16:04:18 2023
[Material3][gradle] Update compose dependencies to 1.4.2
Upgrade needed to intake the following bug fix:
Bug: 268380384
Bug: 272483584
RelNote: ModalBottomSheet now can display IME keyboard
Test: Manual
Change-Id: Idc5082008acb547cac2100a69cab4be7db85f50f
M compose/material3/material3/build.gradle
M compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/BottomSheetSamples.kt
Description
To re-land this we need to figure out what the behavior should be for containerSize in this case.