From 7798540d8204ee1d62a93af96fbe224a46f4a47e Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Tue, 31 Oct 2023 14:48:36 +0000 Subject: [PATCH] Use floats --- .../layout/ScalingLazyColumnDefaults.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/compose-layout/src/main/java/com/google/android/horologist/compose/layout/ScalingLazyColumnDefaults.kt b/compose-layout/src/main/java/com/google/android/horologist/compose/layout/ScalingLazyColumnDefaults.kt index 7abfd5fba3..0254b105a2 100644 --- a/compose-layout/src/main/java/com/google/android/horologist/compose/layout/ScalingLazyColumnDefaults.kt +++ b/compose-layout/src/main/java/com/google/android/horologist/compose/layout/ScalingLazyColumnDefaults.kt @@ -148,13 +148,13 @@ public object ScalingLazyColumnDefaults { ): Dp { val childViewHeight: Float = ChipDefaults.Height.value val childViewWidth: Float = viewportDiameter * (1.0f - (2f * horizontalPaddingPercent)) - val radius = viewportDiameter / 2.0 + val radius = viewportDiameter / 2f return ( radius - sqrt( - (radius - childViewHeight + childViewWidth * 0.5) * (radius - childViewWidth * 0.5), + (radius - childViewHeight + childViewWidth * 0.5f) * (radius - childViewWidth * 0.5f), ) - - childViewHeight * 0.5 + childViewHeight * 0.5f ).dp } @@ -172,13 +172,19 @@ public object ScalingLazyColumnDefaults { 32.dp } - val sizeRatio = (screenWidthDp - 192) / (233 - 192).toFloat() + val sizeRatio = ((screenWidthDp - 192) / (233 - 192).toFloat()).coerceIn(0f, 1.5f) val presetRatio = 0f + + val minElementHeight = lerp(0.2f, 0.157f, sizeRatio) + val maxElementHeight = lerp(0.6f, 0.216f, sizeRatio).coerceAtLeast(minElementHeight) + val minTransitionArea = lerp(0.35f, lerp(0.35f, 0.393f, presetRatio), sizeRatio) + val maxTransitionArea = lerp(0.55f, lerp(0.55f, 0.593f, presetRatio), sizeRatio) + val scalingParams = ScalingLazyColumnDefaults.scalingParams( - minElementHeight = lerp(0.2f, 0.157f, sizeRatio), - maxElementHeight = lerp(0.6f, 0.216f, sizeRatio), - minTransitionArea = lerp(0.35f, lerp(0.35f, 0.393f, presetRatio), sizeRatio), - maxTransitionArea = lerp(0.55f, lerp(0.55f, 0.593f, presetRatio), sizeRatio), + minElementHeight = minElementHeight, + maxElementHeight = maxElementHeight, + minTransitionArea = minTransitionArea, + maxTransitionArea = maxTransitionArea, ) return remember {