Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit e84f9f947bc507c1d785a310b4f3e2861e3f12c6
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Oct 10 13:51:26 2019
Ensure FragmentContainerView properly inflates Fragments
When given a name, a FragmentContainerView should inflate a Fragment
with the given name and add it to the appropriate FragmentManager. When
the Fragment calls onInflate() the attributes passed from the
FragmentContainerView must be the ones from when the
FragmentContainerView is contructed, otherwise the attributes will be
incorrect.
This change uses a LayoutInflatorFactory to contruct the
FragmentContainerView and pass in the right FragmentManager at
construction time. This means that if a Fragment is created, it can call
onInflate() with the proper AttributesSet.
Test: Added test to mirror all test with the fragment tag. tested in app
BUG: 142421837
Change-Id: I65ff0030a975d3c9f9087660f5b9e4b0a5a6e24c
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentContainerInflatedFragmentTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentFactoryTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/NestedInflatedFragmentTest.kt
M fragment/fragment/src/androidTest/res/layout/inflated_fragment_container_view.xml
A fragment/fragment/src/androidTest/res/layout/nested_inflated_fragment_container_parent.xml
A fragment/fragment/src/androidTest/res/layout/nested_retained_inflated_fragment_container_parent.xml
M fragment/fragment/src/androidTest/res/layout/nested_retained_inflated_fragment_parent.xml
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentContainerView.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
https://android-review.googlesource.com/1138882
https://goto.google.com/android-sha1/e84f9f947bc507c1d785a310b4f3e2861e3f12c6
Branch: androidx-master-dev
commit e84f9f947bc507c1d785a310b4f3e2861e3f12c6
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Oct 10 13:51:26 2019
Ensure FragmentContainerView properly inflates Fragments
When given a name, a FragmentContainerView should inflate a Fragment
with the given name and add it to the appropriate FragmentManager. When
the Fragment calls onInflate() the attributes passed from the
FragmentContainerView must be the ones from when the
FragmentContainerView is contructed, otherwise the attributes will be
incorrect.
This change uses a LayoutInflatorFactory to contruct the
FragmentContainerView and pass in the right FragmentManager at
construction time. This means that if a Fragment is created, it can call
onInflate() with the proper AttributesSet.
Test: Added test to mirror all test with the fragment tag. tested in app
BUG: 142421837
Change-Id: I65ff0030a975d3c9f9087660f5b9e4b0a5a6e24c
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentContainerInflatedFragmentTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentFactoryTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentLifecycleTest.kt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/NestedInflatedFragmentTest.kt
M fragment/fragment/src/androidTest/res/layout/inflated_fragment_container_view.xml
A fragment/fragment/src/androidTest/res/layout/nested_inflated_fragment_container_parent.xml
A fragment/fragment/src/androidTest/res/layout/nested_retained_inflated_fragment_container_parent.xml
M fragment/fragment/src/androidTest/res/layout/nested_retained_inflated_fragment_parent.xml
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentContainerView.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
an...@google.com <an...@google.com> #3
b9...@gmail.com <b9...@gmail.com> #4
I have one question about FragmentContainerView flow for inflating Fragment. It inflate Fragment in onAttachedtoWindow, how do I find the Fragment in my Fragment lifecycle (callback)? I found that onAttachedtoWindow will be called after onActivityCreated.
jb...@google.com <jb...@google.com> #5
That was actually part of the problem here. With the change above, instead of inflating in onAttachedToWindow we now inflate in FragmentContainerView's constructor. That way you get the onInflate() callback when setContentView() is called on the Activity.
This has been fixed internally, and will be available in the Fragment 1.2.0-beta02 release.
This has been fixed internally, and will be available in the Fragment 1.2.0-beta02 release.
b9...@gmail.com <b9...@gmail.com> #6
Sorry I don't get it. I saw that the Fragment still being added in onAttachedToWindow callback:
```
.add(getId(), mContainerFragment, mTag)
```
So that we still have to find Fragment via findFragmentByTag(mTag) after onAttachedToWindow.
```
.add(getId(), mContainerFragment, mTag)
```
So that we still have to find Fragment via findFragmentByTag(mTag) after onAttachedToWindow.
il...@google.com <il...@google.com> #7
Re #6 - please file a new issue with a sample project that reproduces your issue.
b9...@gmail.com <b9...@gmail.com> #8
Re #7 - b/142520327
Description
The issue is caused because the attributes in an AttributeSet change over time, and by time FragmentContainerView attempts to call onInflate() on the new inflated fragment, the attributes from when FragmentContainerView was constructed are no longer available in the AttributeSet.