Fixed
Status Update
Comments
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit a09f35ee1a81b8dcafcc6004065baf785be14e0a
Author: sanura <sanura@google.com>
Date: Tue Aug 29 21:23:14 2023
Set initial value on map() and switchMap()
If the LiveData you're calling map() or switchMap() already has a value set (checked via isInitialized), we should immediately set the value on the resulting LiveData to avoid any time where the value is not set.
RelNote: "The `LiveData.map()` and `LiveData.switchMap()` extensions now sets the `value` of the returned `LiveData` if the previous `LiveData` has had a value set on it."
Test: testMap_initialValueIsSet, testSwitchMap_initialValueIsSet
Bug: 269479952
Change-Id: I91d2b286b609976a43b740c45c99975317274b63
M lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/Transformations.kt
M lifecycle/lifecycle-livedata/src/test/java/androidx/lifecycle/TransformationsTest.kt
https://android-review.googlesource.com/2732077
Branch: androidx-main
commit a09f35ee1a81b8dcafcc6004065baf785be14e0a
Author: sanura <sanura@google.com>
Date: Tue Aug 29 21:23:14 2023
Set initial value on map() and switchMap()
If the LiveData you're calling map() or switchMap() already has a value set (checked via isInitialized), we should immediately set the value on the resulting LiveData to avoid any time where the value is not set.
RelNote: "The `LiveData.map()` and `LiveData.switchMap()` extensions now sets the `value` of the returned `LiveData` if the previous `LiveData` has had a value set on it."
Test: testMap_initialValueIsSet, testSwitchMap_initialValueIsSet
Bug: 269479952
Change-Id: I91d2b286b609976a43b740c45c99975317274b63
M lifecycle/lifecycle-livedata/src/main/java/androidx/lifecycle/Transformations.kt
M lifecycle/lifecycle-livedata/src/test/java/androidx/lifecycle/TransformationsTest.kt
sa...@google.com <sa...@google.com>
g....@xe.gr <g....@xe.gr> #3
Thanks for your efforts! Any info about what release this is going to be included in?
il...@google.com <il...@google.com> #4
This will be included in Lifecycle 2.7.0-alpha02
pr...@google.com <pr...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.lifecycle:lifecycle-livedata:2.7.0-alpha02
Description
Component used: livecycle-livedata-ktx Version used: 2.5.1
distinctUntilChanged()
which does not set the initial value of the returned LiveData even if the source one was initialized. This caused unnecessary recompositions if observed withobserveAsState()
.However, I also noticed that the other two
Transformations
methods,map
andswitchMap
, suffer from the same symptom which means that they too will likely cause the same unnecessary recompositions.