Skip to content

[FragmentStrictMode] Detect <fragment> tag usage - #141

Closed
simonschiller wants to merge 1 commit into
androidx:androidx-mainfrom
simonschiller:feature/fragment-tag
Closed

[FragmentStrictMode] Detect <fragment> tag usage#141
simonschiller wants to merge 1 commit into
androidx:androidx-mainfrom
simonschiller:feature/fragment-tag

Conversation

@simonschiller

Copy link
Copy Markdown
Contributor

Proposed Changes

  • Detect <fragment> tag usage inside XML layouts

Testing

Test: See FragmentStrictModeTest#detectFragmentTagUsage

Issues Fixed

Fixes: 153738235

@dlam
dlam requested a review from jbw0033 March 15, 2021 19:19
+ "re-attached via the <fragment> tag: id=0x" + Integer.toHexString(id));
}
}
FragmentStrictMode.onFragmentTagUsage(fragment);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should make the call on line 74 before we check the ID and tag. The idea being that if you are using strict mode, we should throw this before we even check if you are using tag correctly.

@simonschiller simonschiller Mar 16, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wanted to do that originally, but the problem there is that we don't have a Fragment instance yet. If there is a reliable way to traverse up the FragmentManager hierarchy without a concrete Fragment instance, that would also work, but I couldn't find one. We need the traversal to figure out the correct policy.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a package private findFragmentManager that finds the FragmentManager associated with a given view, but I don't think that helps here much.

@jbw0033
jbw0033 requested a review from ianhanniballake March 16, 2021 20:09
@simonschiller
simonschiller deleted the feature/fragment-tag branch March 23, 2021 15:56
harryzz pushed a commit to harryzz/compose-multiplatform-core that referenced this pull request Jul 28, 2026
## Proposed Changes

  - Detect `<fragment>` tag usage inside XML layouts

## Testing

Test: See `FragmentStrictModeTest#detectFragmentTagUsage`

## Issues Fixed

Fixes: 153738235

This is an imported pull request from androidx#141.

Resolves JetBrains#141
Github-Pr-Head-Sha: 4ea0525
GitOrigin-RevId: 62e7487
Change-Id: Iae48578e85e4e4897f806d7ade2e2a660adf9479
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants