Status Update
Comments
ap...@google.com <ap...@google.com> #2
We'll track fixing specifically DialogFragment
in this issue.
ap...@google.com <ap...@google.com> #3
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
ap...@google.com <ap...@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> #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?
de...@gmail.com <de...@gmail.com> #7
The problem is when 2 fragments try setResultListener with one same result key(
jb...@google.com <jb...@google.com> #8
As stated in
The Fragment result listeners are not stored in the Fragment, it is actually stored in the FragmentManager. So adding another listener, with the same key for two Fragments with the same FragmentManager will overwrite the first listener.
b9...@gmail.com <b9...@gmail.com> #9
LifecycleEventObserver observer = new LifecycleEventObserver() {
if (event == Lifecycle.Event.ON_DESTROY) {
lifecycle.removeObserver(this); // only remove observer when onDestroy
mResultListeners.remove(requestKey);
}
}
};
lifecycle.addObserver(observer);
I think it would be better remove observer right after the callback is fired, sometimes we don't want the observer keep listening. In that way we could wrap the whole task in one block (like coroutine style), more flexible.
il...@google.com <il...@google.com> #10
Re #9 - you can certainly clear out your FragmentResultListener
after you receive a result if that's the behavior you want for your business logic. The clean up mentioned in your comment is only to prevent memory leaks and not for business logic purposes.
Description
We should add a clean way of passing results between two Fragments.
It should be able to properly handle process death and with it, we can deprecate target fragment.
Target fragment requires directly accessing the instance of another Fragment and not only is that discouraged, but the state of the Fragment being accessed is unpredictable so it is also dangerous. Target fragment is also not supported in Navigation.
Long term, the Fragment Lifecycle methods will be driven with a LifecycleObserver and target fragment cannot exist in that world.