Fixed
Status Update
Comments
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit b85eb67c37d808e728cd7f3292ee75238b27dfbe
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Apr 21 17:04:57 2022
Update back stack remember lint rule to require key
We have a lint rule to ensure that calls to `getBackStackEntry` within a
composition are always wrapped with a `remember`. Navigation Compose has a
unique scenario where the underlying data may change, but we do not want
to actually animate since you are on the same screen (i.e. singleTop,
canceled animations, etc.). Because we don't want to animate we have to
consider the content the "same" and that choice causes `remember` without
any keys to be insufficient as the content in the remember would not be
disposed.
This change modifies the existing lint rule to ensure a
NavBackStackEntry key is provided to the `remember` function.
Relnote: "The `UnrememberedGetBackStackEntryDetector` lint rule has been
updated to ensure that the `remember` call surrounding the call to
`getBackStackEntry()` also passes in a `NavBackStackEntry` object as a
key."
Bug: 227382831
Test: new Nav lint tests
Change-Id: Ib708126a32c865f758d5967ea177cc9d2c7692d5
M compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/libraries/Libraries.kt
M navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/UnrememberedGetBackStackEntryDetectorTest.kt
M navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/UnrememberedGetBackStackEntryDetector.kt
https://android-review.googlesource.com/2066987
Branch: androidx-main
commit b85eb67c37d808e728cd7f3292ee75238b27dfbe
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Apr 21 17:04:57 2022
Update back stack remember lint rule to require key
We have a lint rule to ensure that calls to `getBackStackEntry` within a
composition are always wrapped with a `remember`. Navigation Compose has a
unique scenario where the underlying data may change, but we do not want
to actually animate since you are on the same screen (i.e. singleTop,
canceled animations, etc.). Because we don't want to animate we have to
consider the content the "same" and that choice causes `remember` without
any keys to be insufficient as the content in the remember would not be
disposed.
This change modifies the existing lint rule to ensure a
NavBackStackEntry key is provided to the `remember` function.
Relnote: "The `UnrememberedGetBackStackEntryDetector` lint rule has been
updated to ensure that the `remember` call surrounding the call to
`getBackStackEntry()` also passes in a `NavBackStackEntry` object as a
key."
Bug: 227382831
Test: new Nav lint tests
Change-Id: Ib708126a32c865f758d5967ea177cc9d2c7692d5
M compose/integration-tests/docs-snippets/src/main/java/androidx/compose/integration/docs/libraries/Libraries.kt
M navigation/navigation-compose-lint/src/test/java/androidx/navigation/compose/lint/UnrememberedGetBackStackEntryDetectorTest.kt
M navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/UnrememberedGetBackStackEntryDetector.kt
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 00d8a4650c80d2e0009863ed743f57424ec75b03
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Apr 18 17:36:18 2022
Add lint util for remember with key
Added a lint util for help write lint rules for adding a remember with
a specified key as a value argument.
Test: used by the old rule, all tests pass
Bug: 227382831
Change-Id: I2f1ae90268c8c8d4b3e8bbd52d878f71d281e903
M compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/UnrememberedMutableStateDetector.kt
M compose/animation/animation-core-lint/src/main/java/androidx/compose/animation/core/lint/UnrememberedAnimatableDetector.kt
M navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/UnrememberedGetBackStackEntryDetector.kt
M compose/lint/common/src/main/java/androidx/compose/lint/ComposableUtils.kt
https://android-review.googlesource.com/2064730
Branch: androidx-main
commit 00d8a4650c80d2e0009863ed743f57424ec75b03
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Apr 18 17:36:18 2022
Add lint util for remember with key
Added a lint util for help write lint rules for adding a remember with
a specified key as a value argument.
Test: used by the old rule, all tests pass
Bug: 227382831
Change-Id: I2f1ae90268c8c8d4b3e8bbd52d878f71d281e903
M compose/runtime/runtime-lint/src/main/java/androidx/compose/runtime/lint/UnrememberedMutableStateDetector.kt
M compose/animation/animation-core-lint/src/main/java/androidx/compose/animation/core/lint/UnrememberedAnimatableDetector.kt
M navigation/navigation-compose-lint/src/main/java/androidx/navigation/compose/lint/UnrememberedGetBackStackEntryDetector.kt
M compose/lint/common/src/main/java/androidx/compose/lint/ComposableUtils.kt
jb...@google.com <jb...@google.com> #4
This has been added internally and will be available in the Navigation 2.5.0-rc01
release.
Description
Having just a
remember { }
around calls togetBackStackEntry(route)
causes new entries with the same id to use the old remember scope which can cause crashes. We should instead be telling devs to useremember(entry) { }
using the entry from thecomposable
function lambda scope as the input to theremember
calculation. This way, whenever the entry object changes, we also recompose theremember
and we never get a stale entry.