Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AndroidX fragments #957

Closed
wants to merge 1 commit into from
Closed

Conversation

passy
Copy link
Member

@passy passy commented Apr 1, 2020

Summary:
Fix #931

This is not how I would like to fix this, but it should do the job.
When the switch over to AndroidX was made, the overall abstraction
started to leak and we really need to remodel this in its entirety.
There's also the question of whether we want to support both support
fragments and AndroidX fragments or not. Right now it's kinda-sorta
supported but only under some circumstances, which is not great.

I also added some more defensive try/catches as there's some unsafe casting
involved and future changes may break this causing the entire layout to disappear.

Test Plan:
Changed the sample app to include some AndroidX fragments and they
now show up (again) in the view hierarchy:

Screenshot 2020-04-01 13 40 53

Change Log:
Fix support for AndroidX fragments in Layout Inspector.

Summary:
Fix #931

This is not how I would *like* to fix this, but it should do the job.
When the switch over to AndroidX was made, the overall abstraction
started to leak and we really need to remodel this in its entirety.
There's also the question of whether we want to support both support
fragments and AndroidX fragments or not. Right now it's kinda-sorta
supported but only under some circumstances, which is not great.

Test Plan:
Changed the sample app to include some AndroidX fragments and they
now show up (again) in the view hierarchy:
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 1, 2020
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@passy has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

if (fieldMAdded != null) {
fieldMAdded.setAccessible(true);
mFieldMAdded = fieldMAdded;
if (fragmentManager instanceof android.app.FragmentManager) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instanceof check here defeats the purpose of this abstraction a bit but this looks like a working fix otherwise.

@benoitdion
Copy link

@passy will you also be committing the changes to the example app to help catch regressions sooner?

@facebook-github-bot
Copy link
Contributor

@passy merged this pull request in 4be1b4d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not retrieve mAdded field from class androidx.fragment.app.FragmentManagerImpl
3 participants