commit | 3e05a1e92cbca40d3d1fe612e060ab376d42cb51 | [log] [tgz] |
---|---|---|
author | Alejandro Nijamkin <nijamkin@google.com> | Sun Jan 22 17:42:15 2023 -0800 |
committer | Alejandro Nijamkin <nijamkin@google.com> | Sun Jan 22 17:44:24 2023 -0800 |
tree | a3afebe2a3d08c404436eeb9fd85db00a00ad2ac | |
parent | dea718c88696fcda9eac25f0702532f227b774d4 [diff] |
Auto-scroll to the selected quick affordance. Fix: 266006047 Test: manually verified switching tabs or making selections correctly and beautifully scrolls such that the selected affordance is visible. Change-Id: I244c711eef4307528a361944b0dc03bab03aced4
diff --git a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt index 57e9401..e412020 100644 --- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt +++ b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
@@ -74,6 +74,16 @@ launch { viewModel.quickAffordances.collect { affordances -> affordancesAdapter.setItems(affordances) + + // Scroll the view to show the first selected affordance. + val selectedPosition = affordances.indexOfFirst { it.isSelected } + if (selectedPosition != -1) { + // We use "post" because we need to give the adapter item a pass to + // update the view. + affordancesView.post { + affordancesView.smoothScrollToPosition(selectedPosition) + } + } } }