Fixed
Status Update
Comments
il...@google.com <il...@google.com>
sa...@google.com <sa...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 9f854289a3f2199754cb5d1fe5fba72f1a46a222
Author: Sanura N'Jaka <sanura@google.com>
Date: Fri Aug 19 21:29:02 2022
Preserve initial value of StateFlow in FlowLiveData's asLiveData
Currently, when FlowLiveData creates a LiveData object
from a given Flow using its asLiveData function, it does
not contain any initial value. Meaning that if the Flow
is a StateFlow, which always contains an initial value,
that initial value will not be initially accessible in
the LiveData. We will now preserve this initial value.
RelNote: "`FlowLiveData`'s `asLiveData` function will now
preserve the initial value of a `StateFlow` when creating
the new `LiveData` object."
Test: asLiveData_preserveStateFlowInitialValue
Fixes: 157380488
Change-Id: I3f53068b1a071e2f334f2cbab2819e7f7a4c60b2
M lifecycle/lifecycle-livedata-ktx/src/androidTest/java/androidx.lifecycle/FlowAsLiveDataIntegrationTest.kt
M lifecycle/lifecycle-livedata-ktx/build.gradle
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/FlowLiveData.kt
https://android-review.googlesource.com/2190406
Branch: androidx-main
commit 9f854289a3f2199754cb5d1fe5fba72f1a46a222
Author: Sanura N'Jaka <sanura@google.com>
Date: Fri Aug 19 21:29:02 2022
Preserve initial value of StateFlow in FlowLiveData's asLiveData
Currently, when FlowLiveData creates a LiveData object
from a given Flow using its asLiveData function, it does
not contain any initial value. Meaning that if the Flow
is a StateFlow, which always contains an initial value,
that initial value will not be initially accessible in
the LiveData. We will now preserve this initial value.
RelNote: "`FlowLiveData`'s `asLiveData` function will now
preserve the initial value of a `StateFlow` when creating
the new `LiveData` object."
Test: asLiveData_preserveStateFlowInitialValue
Fixes: 157380488
Change-Id: I3f53068b1a071e2f334f2cbab2819e7f7a4c60b2
M lifecycle/lifecycle-livedata-ktx/src/androidTest/java/androidx.lifecycle/FlowAsLiveDataIntegrationTest.kt
M lifecycle/lifecycle-livedata-ktx/build.gradle
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/FlowLiveData.kt
il...@google.com <il...@google.com> #3
This has been fixed internally and will be available in Lifecycle 2.6.0-alpha02.
na...@google.com <na...@google.com> #4
This bug was linked in a change in the following release(s):
androidx.lifecycle:lifecycle-livedata-ktx:2.6.0-alpha02
Description
Component used: lifecycle-livedata-ktx
Version used: 2.3.0-alpha03
StateFlow
SharedFlow
LiveData
created by theasLiveData
extension methods onFlow
in FlowLiveData.kt. It would be nice if the initial value was available asvalue
on the createdLiveData
to help reduce unnecessary UI updates that happen when the values arrive on theFlow
after the lifecycle method responsible for creating the initial view has already finished.Here is a failing test for
StateFlow
that should work, IMHO: