Skip to content

Commit

Permalink
refactor: better compute for adaptive layout counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Feb 17, 2024
1 parent 78668e4 commit 6705cdf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import org.gdglille.devfest.android.theme.m3.style.placeholder
import org.gdglille.devfest.android.theme.m3.style.toDp
import org.gdglille.devfest.models.ui.PartnerGroupsUi

const val NbHorizontalPadding = 2

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun PartnersGridScreen(
Expand All @@ -47,10 +49,10 @@ fun PartnersGridScreen(
BoxWithConstraints(modifier = Modifier.padding(it)) {
val minSize = 100.dp
val mediumSpacing = SpacingTokens.MediumSpacing.toDp()
val count = floor((this.maxWidth - mediumSpacing * 2) / minSize).toInt()
val widthSize = this.maxWidth - (mediumSpacing * NbHorizontalPadding)
val count = floor(widthSize / minSize).toInt()
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = minSize),
horizontalArrangement = Arrangement.spacedBy(mediumSpacing),
verticalArrangement = Arrangement.spacedBy(mediumSpacing),
contentPadding = PaddingValues(
vertical = SpacingTokens.LargeSpacing.toDp(),
Expand All @@ -67,6 +69,7 @@ fun PartnersGridScreen(
url = it.logoUrl,
contentDescription = it.name,
modifier = Modifier
.padding(horizontal = SpacingTokens.SmallSpacing.toDp())
.fillMaxWidth()
.aspectRatio(1f)
.placeholder(visible = isLoading),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.gdglille.devfest.android.theme.m3.style.toDp
import org.gdglille.devfest.models.ui.AgendaUi
import org.gdglille.devfest.models.ui.TalkItemUi

const val NbHorizontalPadding = 2

@Composable
fun ScheduleGridScreen(
agenda: AgendaUi,
Expand All @@ -43,13 +45,15 @@ fun ScheduleGridScreen(
} else {
BoxWithConstraints {
val minSize = 260.dp
val count = floor(this.maxWidth / minSize).toInt()
val mediumSpacing = SpacingTokens.MediumSpacing.toDp()
val widthSize = this.maxWidth - (mediumSpacing * NbHorizontalPadding)
val count = floor(widthSize / minSize).toInt()
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = minSize),
modifier = modifier,
contentPadding = PaddingValues(vertical = SpacingTokens.LargeSpacing.toDp()),
verticalArrangement = Arrangement.spacedBy(SpacingTokens.MediumSpacing.toDp()),
horizontalArrangement = Arrangement.spacedBy(SpacingTokens.MediumSpacing.toDp())
verticalArrangement = Arrangement.spacedBy(mediumSpacing),
horizontalArrangement = Arrangement.spacedBy(mediumSpacing)
) {
agenda.talks.entries.forEach { slot ->
item(span = { GridItemSpan(count) }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fun SpeakerAdaptive(
modifier = modifier,
listPane = {
AnimatedPane(Modifier) {
SpeakersListCompactVM(
SpeakersGridVM(
onSpeakerClicked = {
selectedItem = it
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.gdglille.devfest.android.theme.m3.style.R
import org.koin.androidx.compose.koinViewModel

@Composable
fun SpeakersListCompactVM(
fun SpeakersGridVM(
onSpeakerClicked: (id: String) -> Unit,
modifier: Modifier = Modifier,
viewModel: SpeakersListViewModel = koinViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.gdglille.devfest.android.theme.m3.speakers.screens

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand All @@ -15,6 +16,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlin.math.floor
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
Expand All @@ -41,7 +43,7 @@ fun SpeakersGridScreen(
hasScrollBehavior = false
) {
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = 150.dp),
columns = GridCells.Adaptive(minSize = 130.dp),
modifier = Modifier
.padding(top = it.calculateTopPadding())
.fillMaxWidth(),
Expand Down

0 comments on commit 6705cdf

Please sign in to comment.