Fixed
Status Update
Comments
cl...@google.com <cl...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 79be84210f95f4b9d2298448ce34b7cd0e21440e
Author: Zach Klippenstein <zachklipp@squareup.com>
Date: Thu May 28 14:02:20 2020
Remove Any upper bound on StateFlow.collectAsFlow extension function.
The only reason to give collectAsState a non-null bound is to reserve null
to mean not initialized. Since StateFlow always has a value, this isn't
required, and the extension should support StateFlows of any type, even
nullable ones.
This change also removes the `collectAsFlow` overload on `Flow<T>` that
automatically uses null as an initial value instead of requiring it to be
passed explicitly. Null can only safely be used to indicate "lack of value"
if the `Flow` can't emit null, by having an `Any` upper bound. However, giving
this overload an `Any` upper bound prevents the compiler from being able to
choose between it and the new `StateFlow` extension when the actual type is
non-nullable. It's safer to just require an explicit initial value in this case.
Fixes: b/157674865
Test: Added unit tests for MutableStateFlow containing null, as well as non-StateFlows with nullable types.
Relnote: Deprecate Flow<T>.collectAsState() with no initial value. Use StateFlow<T> or pass an explicit initial value instead.
Change-Id: I63f98eabd19d74c87bc951677cef15c678aeae2f
M compose/compose-runtime/api/0.1.0-dev14.txt
M compose/compose-runtime/api/current.txt
M compose/compose-runtime/api/public_plus_experimental_0.1.0-dev14.txt
M compose/compose-runtime/api/public_plus_experimental_current.txt
M compose/compose-runtime/api/restricted_0.1.0-dev14.txt
M compose/compose-runtime/api/restricted_current.txt
M compose/compose-runtime/samples/src/main/java/androidx/compose/samples/FlowAdapterSamples.kt
M compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/test/FlowAdapterTest.kt
M compose/compose-runtime/src/jvmMain/kotlin/androidx/compose/FlowAdapter.kt
https://android-review.googlesource.com/1321701
Branch: androidx-master-dev
commit 79be84210f95f4b9d2298448ce34b7cd0e21440e
Author: Zach Klippenstein <zachklipp@squareup.com>
Date: Thu May 28 14:02:20 2020
Remove Any upper bound on StateFlow.collectAsFlow extension function.
The only reason to give collectAsState a non-null bound is to reserve null
to mean not initialized. Since StateFlow always has a value, this isn't
required, and the extension should support StateFlows of any type, even
nullable ones.
This change also removes the `collectAsFlow` overload on `Flow<T>` that
automatically uses null as an initial value instead of requiring it to be
passed explicitly. Null can only safely be used to indicate "lack of value"
if the `Flow` can't emit null, by having an `Any` upper bound. However, giving
this overload an `Any` upper bound prevents the compiler from being able to
choose between it and the new `StateFlow` extension when the actual type is
non-nullable. It's safer to just require an explicit initial value in this case.
Fixes:
Test: Added unit tests for MutableStateFlow containing null, as well as non-StateFlows with nullable types.
Relnote: Deprecate Flow<T>.collectAsState() with no initial value. Use StateFlow<T> or pass an explicit initial value instead.
Change-Id: I63f98eabd19d74c87bc951677cef15c678aeae2f
M compose/compose-runtime/api/0.1.0-dev14.txt
M compose/compose-runtime/api/current.txt
M compose/compose-runtime/api/public_plus_experimental_0.1.0-dev14.txt
M compose/compose-runtime/api/public_plus_experimental_current.txt
M compose/compose-runtime/api/restricted_0.1.0-dev14.txt
M compose/compose-runtime/api/restricted_current.txt
M compose/compose-runtime/samples/src/main/java/androidx/compose/samples/FlowAdapterSamples.kt
M compose/compose-runtime/src/androidAndroidTest/kotlin/androidx/compose/test/FlowAdapterTest.kt
M compose/compose-runtime/src/jvmMain/kotlin/androidx/compose/FlowAdapter.kt
Description
Compose version: 0.1.0-dev12
The only reason to give
collectAsState
a non-null bound is to reservenull
to meannot initialized
. SinceStateFlow
always has a value, this isn't required, and the extension should supportStateFlow
s of any type, even nullable ones.