Verified
Status Update
Comments
st...@google.com <st...@google.com>
st...@google.com <st...@google.com>
st...@google.com <st...@google.com>
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
commit 9ca3ba767c2803e5150a1a170a476a5615b183c7
Author: stevebower <stevebower@google.com>
Date: Tue Oct 25 12:03:41 2022
Fix rememberPickerState to update PickerState after inputs change
PickerState was not updated by rememberPickerState when inputs changed, so composables did not show the updated values.
Bug: 255323197
Test: Added test to androidx.wear.compose.material
Relnote: "We have fixed a bug in rememberPickerState where updated inputs were not saved, so that composables were not updated after changes to the inputs."
Change-Id: I49ff67e95da966aecbdc3d9b9cdd93bec9f662ba
M wear/compose/compose-material/src/androidAndroidTest/kotlin/androidx/wear/compose/material/PickerTest.kt
M wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/Picker.kt
https://android-review.googlesource.com/2268786
Branch: androidx-main
commit 9ca3ba767c2803e5150a1a170a476a5615b183c7
Author: stevebower <stevebower@google.com>
Date: Tue Oct 25 12:03:41 2022
Fix rememberPickerState to update PickerState after inputs change
PickerState was not updated by rememberPickerState when inputs changed, so composables did not show the updated values.
Bug: 255323197
Test: Added test to androidx.wear.compose.material
Relnote: "We have fixed a bug in rememberPickerState where updated inputs were not saved, so that composables were not updated after changes to the inputs."
Change-Id: I49ff67e95da966aecbdc3d9b9cdd93bec9f662ba
M wear/compose/compose-material/src/androidAndroidTest/kotlin/androidx/wear/compose/material/PickerTest.kt
M wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/Picker.kt
ro...@google.com <ro...@google.com>
na...@google.com <na...@google.com> #4
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.wear.compose:compose-material:1.1.0-rc01
na...@google.com <na...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.wear.compose:compose-material:1.4.0-rc01
Description
Function
rememberPickerState
is returning same instance ofPickerState
after recomposition, even when the input has changed.It looks like the issue is because line .
rememberPickerState
is not passing its parameters (initialNumberOfOptions
,initiallySelectedOption
andrepeatItems
) torememberSaveable
function in thisComponent used: rememberPickerState
Version used: 1.0.2
Devices/Android versions reproduced on: N/A
If this is a bug in the library, we would appreciate if you could attach:
I've added unit tests in this commit showing the issue and a proposed solution:https://github.com/luizgrp/horologist/blob/2be07856616edd7a3f833b96b706339897da10ab/sample/src/androidTest/java/androidx/wear/compose/material/PickerTest.kt
testOriginalFunction
test shows that after changing the value ofviewModel. _selectedOption
,MyComposable
does NOT show the new value.testFunctionWithFix
shows that after changing the value ofviewModel. _selectedOption
,MyComposableFixed
shows the new value.rememberPickerStateFixed
is the proposed fix for this issue.This issue was reported by a Googler while using Horologist's TimePicker. The value displayed on the TimePicker is not changing after the values are changed in the ViewModel. To demonstrate that on a simple screen, please see the video attached.
A simple composable displays the hash code value of two
PickerState
objects when the input value is changed, after recomposition. The first line uses the currentrememberPickerState
and the hash code does not change. The second line usesrememberPickerStateFixed
and the hash code changes.