Fixed
Status Update
Comments
mv...@google.com <mv...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-master-dev
commit b90079595f33f58fece04026a97faa0d243acdb1
Author: Yuichi Araki <yaraki@google.com>
Date: Wed Sep 18 16:55:49 2019
Change the way to detect mismatch between POJO and query
This fixes cursor mismatch warnings with expandProjection.
Bug: 140759491
Test: QueryMethodProcessorTest
Change-Id: I7659002e5e0d1ef60fc1af2a625c0c36da0664d8
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/testing/TestProcessor.kt
https://android-review.googlesource.com/1123258
https://goto.google.com/android-sha1/b90079595f33f58fece04026a97faa0d243acdb1
Branch: androidx-master-dev
commit b90079595f33f58fece04026a97faa0d243acdb1
Author: Yuichi Araki <yaraki@google.com>
Date: Wed Sep 18 16:55:49 2019
Change the way to detect mismatch between POJO and query
This fixes cursor mismatch warnings with expandProjection.
Bug: 140759491
Test: QueryMethodProcessorTest
Change-Id: I7659002e5e0d1ef60fc1af2a625c0c36da0664d8
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/testing/TestProcessor.kt
Description
Background
The current Android architecture guidance recommends collecting flows in the UI in a lifecycle-aware manner. This allows the app to save expensive resources when not needed, for example, when the app is in the background.
Keeping expensive resources (e.g. Firabase queries, location or network updates, etc.) alive when not needed could impact the performance of the app and user's device.
To make it easier for developers to comply with the recommended best practices, APIs that do this should be added to the Lifecycle library.
Limitations with StateFlow
Ideally, there should exist APIs for both
Flow
andStateFlow
types. The latter is important since most flows consumed in Compose code will be of that type. If a helper function forStateFlow
doesn't exist, the UI (Compose code) would need to give those new functions an initial value (same as with Compose'sproduceState
or Flow'sstateIn
operator). That violates layering responsibilities since deciding the initial value belongs to the ViewModel/state holder, not the UI.However, as stated in the refdocs , the
StateFlow
interface is not stable for inheritance in 3rd party libraries, which makes it a tough call to create extensions functions on the type even though only the currentvalue
would be used.Proposed implementation #1
The
collectAsStateWithLifecycle
composable function is added to a newlifecycle-runtime-compose
artifact.Typically, this
collectAsStateWithLifecycle
API would be used like:Proposed implementation #2
To avoid passing the
initialValue
every time forStateFlow
types, another alternative could be therememberStateWithLifecycle
API. This API would also be added to a newlifecycle-runtime-compose
artifact.This would be used as follows:
This API would also offer a method overload that can take a
Flow
and aninitialValue
as parameters.