Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit a6959dd0680092b3089faad171277acafd07143f
Author: Jeremy Woods <jbwoods@google.com>
Date: Fri Sep 17 16:30:40 2021
Add lint rule for right lifecycle in addMenuProvider
The new MenuHost addMenuProvider APIs take a LifecycleOwner and for
fragments, they should pass it the viewLifecycleOwner instead of
themselves.
This new lint rule identifies whether a fragment calls addMenuProvider
on a class that extends MenuHost and if the fragment attempts to pass
itself as the LifecycleOwner is notifies the user they should be using
the fragment's viewLifecycleOwner instead.
Also fixed an issue in the FragmentLiveDataObserveDetectorTest where it
was passing improperly when a fragment was being used as the
LifecycleOwner to observe data.
RelNote: "Lint will now warn you when attempting to pass a fragment as
the LifecycleOwner to addMenuProvider methods."
Test: added AddMenuProviderDetectorTest
Bug: 200326272
Change-Id: I1813147e1db42b557942955725b50acabe8e49f6
A fragment/fragment-lint/src/test/java/androidx/fragment/lint/AddMenuProviderDetectorTest.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/stubs/Stubs.kt
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/FragmentIssueRegistry.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/FragmentLiveDataObserveDetectorTest.kt
https://android-review.googlesource.com/1830457
Branch: androidx-main
commit a6959dd0680092b3089faad171277acafd07143f
Author: Jeremy Woods <jbwoods@google.com>
Date: Fri Sep 17 16:30:40 2021
Add lint rule for right lifecycle in addMenuProvider
The new MenuHost addMenuProvider APIs take a LifecycleOwner and for
fragments, they should pass it the viewLifecycleOwner instead of
themselves.
This new lint rule identifies whether a fragment calls addMenuProvider
on a class that extends MenuHost and if the fragment attempts to pass
itself as the LifecycleOwner is notifies the user they should be using
the fragment's viewLifecycleOwner instead.
Also fixed an issue in the FragmentLiveDataObserveDetectorTest where it
was passing improperly when a fragment was being used as the
LifecycleOwner to observe data.
RelNote: "Lint will now warn you when attempting to pass a fragment as
the LifecycleOwner to addMenuProvider methods."
Test: added AddMenuProviderDetectorTest
Bug: 200326272
Change-Id: I1813147e1db42b557942955725b50acabe8e49f6
A fragment/fragment-lint/src/test/java/androidx/fragment/lint/AddMenuProviderDetectorTest.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/stubs/Stubs.kt
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/FragmentIssueRegistry.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/FragmentLiveDataObserveDetectorTest.kt
jb...@google.com <jb...@google.com> #3
This has been added internally and will be available in the Fragment 1.4.0-alpha10
release.
Description
The new MenuHost API has addMenuProvider methods that can take a Lifecycle and handles the association of the Fragment to the menu based on that Lifecycle. Fragments should pass their ViewLifecycleOwner to the addMenuProvider methods so ensure that the menu items are properly tied to the fragment's view.
We should add a lint rule to help inform developers of this.