From 728fe630865af58b9be8ec0dd96c4d6ace6f22c8 Mon Sep 17 00:00:00 2001 From: Simona Stojanovic Date: Fri, 19 Aug 2022 14:02:52 +0100 Subject: [PATCH] Fix Lazy grid item paddings Change-Id: I3441ed1964d9f680fcef468d4209fc1fdec55a24 --- .../feature/foryou/ForYouScreen.kt | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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,