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

Commit e35972a7 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Remove observing offset in composition" into main

parents bbdd0c0d de6a2867
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ import androidx.compose.ui.unit.dp
import kotlin.math.absoluteValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import platform.test.motion.compose.values.MotionTestValueKey
import platform.test.motion.compose.values.motionTestValues

@Composable
fun PagerDots(
@@ -93,13 +95,22 @@ fun PagerDots(
    }

    Row(
        modifier = modifier.wrapContentWidth().pagerDotsSemantics(pagerState, coroutineScope),
        modifier =
            modifier
                .motionTestValues { activeMarkerWidth exportAs PagerDotsMotionKeys.indicatorWidth }
                .wrapContentWidth()
                .pagerDotsSemantics(pagerState, coroutineScope),
        horizontalArrangement = spacedBy(spaceSize),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        // This means that the active rounded rect has to be drawn between the current page
        // and the previous one (as we are animating back), or the current one if not transitioning
        val withPrevious = pagerState.currentPageOffsetFraction <= 0 || pagerState.isOverscrolling()
        val withPrevious by
            remember(pagerState) {
                derivedStateOf {
                    pagerState.currentPageOffsetFraction <= 0 || pagerState.isOverscrolling()
                }
            }
        repeat(pagerState.pageCount) { page ->
            Canvas(Modifier.size(dotSize)) {
                val rtl = layoutDirection == LayoutDirection.Rtl
@@ -127,6 +138,10 @@ fun PagerDots(
    }
}

object PagerDotsMotionKeys {
    val indicatorWidth = MotionTestValueKey<Dp>("indicatorWidth")
}

private fun Modifier.pagerDotsSemantics(
    pagerState: PagerState,
    coroutineScope: CoroutineScope,