Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8359b9f5 authored by Abdullah Tabassum's avatar Abdullah Tabassum Committed by Android (Google) Code Review
Browse files

Merge "Smooth scroll clock selection to center position" into main

parents 7748c8b9 c36b7de9
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat
import androidx.core.view.get
import androidx.core.view.isEmpty
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
@@ -551,14 +550,18 @@ object ClockFloatingSheetBinder {

                launch {
                    viewModel.previewingClockStyleOptionIndex.collect { indexToFocus ->
                        val offset =
                            if (!clockStyleList.isEmpty()) {
                                clockStyleList.get(0).width
                            } else {
                                0
                        clockStyleList.post {
                            val layoutManager =
                                clockStyleList.layoutManager as? LinearLayoutManager ?: return@post
                            val itemView = layoutManager.findViewByPosition(indexToFocus)

                            if (itemView != null) {
                                val parentCenter = clockStyleList.width / 2
                                val itemCenter = itemView.left + itemView.width / 2
                                val scrollBy = itemCenter - parentCenter
                                clockStyleList.smoothScrollBy(scrollBy, 0)
                            }
                        }
                        (clockStyleList.layoutManager as LinearLayoutManager)
                            .scrollToPositionWithOffset(indexToFocus, offset)
                    }
                }