Fixed
Status Update
Comments
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #2
We'll track fixing specifically DialogFragment
in this issue.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 75ee4a9efb5e1f8ff1b1dfca5bfeb151a7605f54
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Feb 22 15:44:08 2021
Set ViewTree owners for dialogs in DialogFragment
While Fragments with a view set their ViewTree owners automatically,
since DialogFragments do not always have a view (as in the case of only
using onCreateDialog), it is possible to have a DialogFragment but no
ViewTree owners set.
We should set the ViewTree owners on the DialogFragment dialog's decor
view. This way it can be accessed.
RelNote: "Dialogs within a DialogFragment can now get access to ViewTree
owners through their DecorView"
Test: testDialogFragmentViewTree
Bug: 180691023
Change-Id: Ib92905306e16dcaee63c985f22b5e36b6718dd39
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentViewTreeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
https://android-review.googlesource.com/1600577
Branch: androidx-main
commit 75ee4a9efb5e1f8ff1b1dfca5bfeb151a7605f54
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Feb 22 15:44:08 2021
Set ViewTree owners for dialogs in DialogFragment
While Fragments with a view set their ViewTree owners automatically,
since DialogFragments do not always have a view (as in the case of only
using onCreateDialog), it is possible to have a DialogFragment but no
ViewTree owners set.
We should set the ViewTree owners on the DialogFragment dialog's decor
view. This way it can be accessed.
RelNote: "Dialogs within a DialogFragment can now get access to ViewTree
owners through their DecorView"
Test: testDialogFragmentViewTree
Bug: 180691023
Change-Id: Ib92905306e16dcaee63c985f22b5e36b6718dd39
A fragment/fragment/src/androidTest/java/androidx/fragment/app/DialogFragmentViewTreeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/DialogFragment.java
jb...@google.com <jb...@google.com> #4
This has been fixed internally and will be released as part of the Fragment 1.3.1
version.
You can verify this by following the 7166224
and switching your fragment dependency to 1.4.0-SNAPSHOT
.
jb...@google.com <jb...@google.com>
ma...@gwplc.com <ma...@gwplc.com> #5
With this bug essentially meaning that DialogFragments cannot be used with Compose, would it be possible to please backport this fix into the Fragment 1.3.0
version?
Description
Version used:
androidx.activity:activity-compose:1.3.0-alpha02
androidx.fragment:fragment-ktx:1.3.0-beta01
androidx.compose.runtime:runtime:1.0.0-alpah12
Devices/Android versions reproduced on:
emulator Pixel 3 API 29
Sample code:
From any fragment calling TestDialogFragment using
TestDialogFragment().show(childFragmentManager, "Test")
or Navigation way:
findNavController().navigate(MainFragmentDirections.actionToTestDialog())
class TestDialogFragment : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
) = ComposeView(requireContext()).apply {
setContent {
Surface {
TestDialogLayout()
}
}
}
}
Will cause the exception:
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from DecorView@bec849f[MainActivity]
at androidx.compose.ui.platform.WindowRecomposerKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.kt:231)
Can be manually fixed by setting the ViewTreeLifecycleOwner in onCreateView at the beginning:
dialog?.window?.decorView?.let {
ViewTreeLifecycleOwner.set(it, viewLifecycleOwner)
}