Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Fix Lazy grid item paddings

Simona Stojanovic728fe630865a
diff --git a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt
index f53525e36..f4ad00aed 100644
--- a/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt
+++ b/feature-foryou/src/main/java/com/google/samples/apps/nowinandroid/feature/foryou/ForYouScreen.kt
@@ -62,6 +62,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.layout.layout
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.testTag
@@ -177,7 +178,7 @@ fun ForYouScreen(
LazyVerticalGrid(
columns = Adaptive(300.dp),
contentPadding = PaddingValues(16.dp),
- horizontalArrangement = Arrangement.spacedBy(32.dp),
+ horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalArrangement = Arrangement.spacedBy(24.dp),
modifier = modifier
.padding(innerPadding)
@@ -190,7 +191,19 @@ fun ForYouScreen(
interestsSelectionState = interestsSelectionState,
onAuthorCheckedChanged = onAuthorCheckedChanged,
onTopicCheckedChanged = onTopicCheckedChanged,
- saveFollowedTopics = saveFollowedTopics
+ saveFollowedTopics = saveFollowedTopics,
+ // Custom LayoutModifier to remove the enforced parent 16.dp contentPadding
+ // from the LazyVerticalGrid and enable edge-to-edge scrolling for this section
+ interestsItemModifier = Modifier.layout { measurable, constraints ->
+ val placeable = measurable.measure(
+ constraints.copy(
+ maxWidth = constraints.maxWidth + 32.dp.roundToPx()
+ )
+ )
+ layout(placeable.width, placeable.height) {
+ placeable.place(0, 0)
+ }
+ }
)
newsFeed(
@@ -223,7 +236,8 @@ private fun LazyGridScope.interestsSelection(
interestsSelectionState: ForYouInterestsSelectionUiState,
onAuthorCheckedChanged: (String, Boolean) -> Unit,
onTopicCheckedChanged: (String, Boolean) -> Unit,
- saveFollowedTopics: () -> Unit
+ saveFollowedTopics: () -> Unit,
+ interestsItemModifier: Modifier = Modifier
) {
when (interestsSelectionState) {
ForYouInterestsSelectionUiState.Loading -> {
@@ -240,7 +254,7 @@ private fun LazyGridScope.interestsSelection(
ForYouInterestsSelectionUiState.NoInterestsSelection -> Unit
is ForYouInterestsSelectionUiState.WithInterestsSelection -> {
item(span = { GridItemSpan(maxLineSpan) }) {
- Column {
+ Column(modifier = interestsItemModifier) {
Text(
text = stringResource(R.string.onboarding_guidance_title),
textAlign = TextAlign.Center,