Skip to content

Commit

Permalink
Fix bottom padding for responsive() SLC (#1826)
Browse files Browse the repository at this point in the history
* Fix bottom padding for SLC

* Fix bottom padding for SLC

* Fix bottom padding for SLC

* Fix bottom padding for SLC

* 🤖 reformat

* Fix bottom padding for SLC

* Fix bottom padding for SLC

* 🤖 reformat

* 🤖 Updates screenshots

* Fix copyright warning

* Add top padding guide

* 🤖 reformat

* 🤖 Updates screenshots

* Update screenshots

* 🤖 Updates screenshots

* Fix

* Fix

* 🤖 reformat

* 🤖 Updates screenshots

---------

Co-authored-by: yschimke <yschimke@users.noreply.github.com>
  • Loading branch information
yschimke and yschimke authored Nov 22, 2023
1 parent 61404ae commit 1aa843a
Show file tree
Hide file tree
Showing 45 changed files with 255 additions and 59 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -165,44 +165,58 @@ public object ScalingLazyColumnDefaults {
val configuration = LocalConfiguration.current
val screenWidthDp = configuration.screenWidthDp.toFloat()
val screenHeightDp = configuration.screenHeightDp.toFloat()
val padding = screenWidthDp * horizontalPaddingPercent
val topPaddingDp: Dp = if (firstItemIsFullWidth && configuration.isScreenRound) {
calculateVerticalOffsetForChip(screenWidthDp, horizontalPaddingPercent)
} else {
32.dp
}

val sizeRatio = ((screenWidthDp - 192) / (233 - 192).toFloat()).coerceIn(0f, 1.5f)
val presetRatio = 0f
return remember {
val padding = screenWidthDp * horizontalPaddingPercent
val topPaddingDp: Dp = if (firstItemIsFullWidth && configuration.isScreenRound) {
calculateVerticalOffsetForChip(screenWidthDp, horizontalPaddingPercent)
} else {
32.dp
}
val bottomPaddingDp: Dp = if (configuration.isScreenRound) {
calculateVerticalOffsetForChip(screenWidthDp, horizontalPaddingPercent)
} else {
0.dp
}
val contentPadding = PaddingValues(
start = padding.dp,
end = padding.dp,
top = topPaddingDp,
bottom = bottomPaddingDp,
)

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 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 = minElementHeight,
maxElementHeight = maxElementHeight,
minTransitionArea = minTransitionArea,
maxTransitionArea = maxTransitionArea,
)
val scalingParams = ScalingLazyColumnDefaults.scalingParams(
minElementHeight = minElementHeight,
maxElementHeight = maxElementHeight,
minTransitionArea = minTransitionArea,
maxTransitionArea = maxTransitionArea,
)

return remember {
val screenHeightPx =
with(density) { screenHeightDp.dp.roundToPx() }
val topPaddingPx = with(density) { topPaddingDp.roundToPx() }
val topScreenOffsetPx = screenHeightPx / 2 - topPaddingPx

val initialScrollPosition = ScalingLazyColumnState.ScrollPosition(
index = 0,
offsetPx = topScreenOffsetPx,
)
ScalingLazyColumnState(
initialScrollPosition = ScalingLazyColumnState.ScrollPosition(
index = 0,
offsetPx = topScreenOffsetPx,
),
initialScrollPosition = initialScrollPosition,
autoCentering = null,
anchorType = ScalingLazyListAnchorType.ItemStart,
rotaryMode = RotaryMode.Scroll,
verticalArrangement = verticalArrangement,
horizontalAlignment = Alignment.CenterHorizontally,
contentPadding = PaddingValues(horizontal = padding.dp),
contentPadding = contentPadding,
scalingParams = scalingParams,
)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ fun ScalingLazyColumnDecoder(factory: ScalingLazyColumnState.Factory) {
with(density) { columnState.contentPadding.calculateLeftPadding(layoutDirection).toPx() }
val rightPadding =
with(density) { columnState.contentPadding.calculateRightPadding(layoutDirection).toPx() }
val topPadding = with(density) { columnState.contentPadding.calculateTopPadding().toPx() }
val scalingParams = columnState.scalingParams
Canvas(modifier = Modifier.fillMaxSize()) {
drawLine(
Expand Down Expand Up @@ -156,6 +157,13 @@ fun ScalingLazyColumnDecoder(factory: ScalingLazyColumnState.Factory) {
size.height / 2 + 25,
paint,
)
if (topPadding > 0f) {
drawLine(
Color.Yellow,
Offset(0f, topPadding),
Offset(size.width, topPadding),
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import com.google.android.horologist.media.ui.state.model.DownloadMediaUiModel
import com.google.android.horologist.media.ui.state.model.PlaylistUiModel
import com.google.android.horologist.screenshots.FixedTimeSource

class MediaPlayerLibraryTest(device: Device) : ScreenSizeTest(device = device, showTimeText = true) {
class MediaPlayerLibraryTest(device: Device) : ScreenSizeTest(device = device, showTimeText = false) {

@Composable
override fun Content() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,22 @@

package com.google.android.horologist.screensizes

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.AppCard
import androidx.wear.compose.material.Text
import com.google.android.horologist.composables.SectionedList
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
import com.google.android.horologist.compose.material.Title
import com.google.android.horologist.compose.tools.Device
import com.google.android.horologist.sample.R
import com.google.android.horologist.sample.Screen
import org.junit.Test

class ScalingLazyColumnDefaultsTest(device: Device) :
Expand All @@ -37,4 +51,92 @@ class ScalingLazyColumnDefaultsTest(device: Device) :
fun belowTimeText() {
runTest { BelowTimeText() }
}

@Test
fun standard_end() {
runTest {
val columnState = ScalingLazyColumnDefaults.scalingLazyColumnDefaults().create()

SampleMenu(columnState = columnState)

LaunchedEffect(Unit) {
columnState.state.scrollToItem(100, 0)
}
}
}

@Test
fun responsive_end() {
runTest {
val columnState = ScalingLazyColumnDefaults.responsive().create()

SampleMenu(columnState = columnState)

LaunchedEffect(Unit) {
columnState.state.scrollToItem(100, 0)
}
}
}

@Test
fun belowTimeText_end() {
runTest {
val columnState = ScalingLazyColumnDefaults.belowTimeText().create()

SampleMenu(columnState = columnState)

LaunchedEffect(Unit) {
columnState.state.scrollToItem(100, 0)
}
}
}

@Composable
fun SampleMenu(columnState: ScalingLazyColumnState, modifier: Modifier = Modifier) {
SectionedList(
columnState = columnState,
modifier = modifier.fillMaxSize(),
) {
section(
listOf(
Pair(
R.string.sectionedlist_stateless_sections_menu,
Screen.SectionedListStatelessScreen.route,
),
Pair(
R.string.sectionedlist_stateful_sections_menu,
Screen.SectionedListStatefulScreen.route,
),
Pair(
R.string.sectionedlist_expandable_sections_menu,
Screen.SectionedListExpandableScreen.route,
),
),
) {
header {
Title(
stringResource(R.string.sectionedlist_samples_title),
Modifier.padding(vertical = 8.dp),
)
}

loaded {
AppCard(
onClick = { },
appName = {
Text("App Name")
},
time = {
Text("12:05")
},
title = {
Text("Title")
},
) {
Text("Content\nContent\nContent")
}
}
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1aa843a

Please sign in to comment.