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

Commit c36b7de9 authored by abdullahirum's avatar abdullahirum
Browse files

Smooth scroll clock selection to center position

This CL smooth scrolls the clock selection to the center position

Fix: 422790332
Flag: com.android.systemui.shared.new_customization_picker_ui
Test: manual
Change-Id: I91bdc08bb6004eea7b0a1d2ba26699ae5f08d470
parent 62991477
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.get
import androidx.core.view.isEmpty
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
@@ -453,14 +452,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)
                    }
                }