Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 5454704f7df97d04e72124db4fd7c8fa2c372f52
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Mar 23 11:33:28 2020
Disable FragmentLifecycle lint for DialogFragment
The rules around setting a lifecycle observer for a view in a Fragment
does not apply to DialogFragments. But because DialogFragment is a
subclass of Fragment, the lint rules are applied there to. We should
disable the lint rules for viewLifecycleOwner in dialog fragments.
Test: added a FragmentLiveDataObserveDetectorTest
Bug: 151765086
Change-Id: Ie6fd9073172897bc531c7b07cbec5de809373f2f
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/FragmentLiveDataObserveDetectorTest.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/stubs/Stubs.kt
https://android-review.googlesource.com/1266061
Branch: androidx-master-dev
commit 5454704f7df97d04e72124db4fd7c8fa2c372f52
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Mar 23 11:33:28 2020
Disable FragmentLifecycle lint for DialogFragment
The rules around setting a lifecycle observer for a view in a Fragment
does not apply to DialogFragments. But because DialogFragment is a
subclass of Fragment, the lint rules are applied there to. We should
disable the lint rules for viewLifecycleOwner in dialog fragments.
Test: added a FragmentLiveDataObserveDetectorTest
Bug: 151765086
Change-Id: Ie6fd9073172897bc531c7b07cbec5de809373f2f
M fragment/fragment-lint/src/main/java/androidx/fragment/lint/UnsafeFragmentLifecycleObserverDetector.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/FragmentLiveDataObserveDetectorTest.kt
M fragment/fragment-lint/src/test/java/androidx/fragment/lint/stubs/Stubs.kt
an...@google.com <an...@google.com> #3
jb...@google.com <jb...@google.com> #4
This has been addressed internally and will be available in the Fragment 1.2.4 and 1.3.0-alpha03 releases.
il...@google.com <il...@google.com> #5
Specifically, because DialogFragments cannot go onto the FragmentManager back stack, it makes no effective difference on whether you use this
or viewLifecycleOwner
for a DialogFragment, so the Lint check to verify that you're using the right one is unnecessary.
Description
Version used: 1.2.2
Devices/Android versions reproduced on: Pixel 3 running Android 10
If a DialogFragment doesn't return a View in onCreateView then onViewCreated isn't called. In such case if one tries to use viewLifecycleOwner he's probably doing it in onCreateDialog or earlier. But using viewLifecycleOwner isn't possible before view is created. There is a lint error with a message that explains that. But this message doesn't take into account that it's a DialogFragment which should be treated differently (viewLifecycleOwner shouldn't be used). It would be good to detect that viewLifecycleOwner is being used in DialogFragment and show a better message.