Skip to content

Commit

Permalink
fix(adaptive): remove padding in compact mode.
Browse files Browse the repository at this point in the history
* Remove padding for schedule grid screen
* Remove padding for speaker grid screen
* Remove padding for partner grid screen
  • Loading branch information
GerardPaligot committed Mar 22, 2024
1 parent 4312e83 commit c94ba4e
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ androidx-annotation = "1.7.1"
androidx-appcompat = "1.6.1"
androidx-browser = "1.8.0"
androidx-camera = "1.3.2"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.03.00"
androidx-compose-compiler = "1.5.8"
androidx-lifecycle = "2.7.0"
androidx-navigation-compose = "2.7.6"
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ include(":theme-m3:event-list:event-list-ui")
include(":theme-m3:event-list:event-list-feature")
include(":theme-m3:event-list:event-list-di")
include(":theme-m3:navigation")
include(":theme-m3:style:components:adaptive")
include(":theme-m3:style:components:markdown")
include(":theme-m3:style:components:permissions")
include(":theme-m3:style:components:placeholder")
Expand Down
1 change: 1 addition & 0 deletions theme-m3/main/main/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(projects.themeM3.infos.infosFeature)
implementation(projects.themeM3.eventList.eventListFeature)
implementation(projects.themeM3.navigation)
implementation(projects.themeM3.style.components.adaptive)
implementation(projects.shared.core)
implementation(projects.shared.uiModels)
implementation(projects.shared.resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import org.gdglille.devfest.android.theme.m3.schedules.feature.ScheduleDetailOri
import org.gdglille.devfest.android.theme.m3.schedules.feature.ScheduleGridAdaptive
import org.gdglille.devfest.android.theme.m3.speakers.feature.SpeakerAdaptive
import org.gdglille.devfest.android.theme.m3.speakers.feature.SpeakerDetailVM
import org.gdglille.devfest.android.theme.m3.style.adaptive.isCompat
import org.gdglille.devfest.android.theme.m3.style.adaptive.isMedium
import org.gdglille.devfest.android.theme.m3.style.appbars.iconColor
import org.gdglille.devfest.models.ui.ExportNetworkingUi
import org.gdglille.devfest.models.ui.VCardModel
Expand Down Expand Up @@ -211,8 +213,8 @@ fun MainNavigation(
composable(Screen.PartnerList.route) {
PartnersAdaptive(
showBackInDetail = adaptiveInfo.windowSizeClass.widthSizeClass.isCompat,
onLinkClicked = { launchUrl(it) },
onItineraryClicked = onItineraryClicked,
onLinkClicked = { launchUrl(it) },
)
}
composable(
Expand Down
1 change: 1 addition & 0 deletions theme-m3/partners/partners-feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(projects.themeM3.partners.partnersScreens)
implementation(projects.themeM3.partners.partnersUi)
implementation(projects.themeM3.navigation)
implementation(projects.themeM3.style.components.adaptive)
implementation(projects.themeM3.style.partners)
implementation(projects.themeM3.style.theme)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package org.gdglille.devfest.android.theme.m3.partners.feature
import androidx.compose.material3.adaptive.AnimatedPane
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.ListDetailPaneScaffold
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldDefaults
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import org.gdglille.devfest.android.theme.m3.style.adaptive.calculateStandardPaneScaffoldDirectiveAdaptive
import org.gdglille.devfest.android.theme.m3.style.adaptive.windowInsetsAdaptive

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
Expand All @@ -20,10 +24,13 @@ fun PartnersAdaptive(
onLinkClicked: (url: String) -> Unit,
modifier: Modifier = Modifier
) {
val navigator = rememberListDetailPaneScaffoldNavigator()
val scaffoldDirective =
calculateStandardPaneScaffoldDirectiveAdaptive(currentWindowAdaptiveInfo())
val navigator = rememberListDetailPaneScaffoldNavigator(scaffoldDirective)
var selectedItem: String? by rememberSaveable { mutableStateOf(null) }
ListDetailPaneScaffold(
scaffoldState = navigator.scaffoldState,
windowInsets = ListDetailPaneScaffoldDefaults.windowInsetsAdaptive,
modifier = modifier,
listPane = {
AnimatedPane(Modifier) {
Expand All @@ -43,11 +50,13 @@ fun PartnersAdaptive(
onLinkClicked = onLinkClicked,
onItineraryClicked = onItineraryClicked,
navigationIcon = if (showBackInDetail) {
@Composable { Back {
if (navigator.canNavigateBack()) {
navigator.navigateBack()
@Composable {
Back {
if (navigator.canNavigateBack()) {
navigator.navigateBack()
}
}
} }
}
} else null
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun PartnersGridScreen(
modifier = modifier,
hasScrollBehavior = false
) {
BoxWithConstraints(modifier = Modifier.padding(it)) {
BoxWithConstraints(modifier = Modifier.padding(top = it.calculateTopPadding())) {
val minSize = 100.dp
val mediumSpacing = SpacingTokens.MediumSpacing.toDp()
val widthSize = this.maxWidth - (mediumSpacing * NbHorizontalPadding)
Expand Down
1 change: 1 addition & 0 deletions theme-m3/schedules/schedules-feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {
implementation(projects.themeM3.navigation)
implementation(projects.themeM3.style.schedules)
implementation(projects.themeM3.style.theme)
implementation(projects.themeM3.style.components.adaptive)

implementation(libs.koin.androidx.compose)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package org.gdglille.devfest.android.theme.m3.schedules.feature
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.SupportingPaneScaffold
import androidx.compose.material3.adaptive.SupportingPaneScaffoldDefaults
import androidx.compose.material3.adaptive.calculateStandardPaneScaffoldDirective
import androidx.compose.material3.adaptive.calculateSupportingPaneScaffoldState
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import org.gdglille.devfest.android.theme.m3.style.adaptive.calculateStandardPaneScaffoldDirectiveAdaptive
import org.gdglille.devfest.android.theme.m3.style.adaptive.windowInsetsAdaptive

@OptIn(
ExperimentalMaterial3AdaptiveApi::class,
Expand All @@ -20,9 +26,14 @@ fun ScheduleGridAdaptive(
onTalkClicked: (id: String) -> Unit,
showFilterIcon: Boolean,
modifier: Modifier = Modifier,
isSmallSize: Boolean = false,
isSmallSize: Boolean = false
) {
val scaffoldDirective =
calculateStandardPaneScaffoldDirectiveAdaptive(currentWindowAdaptiveInfo())
val scaffoldState = calculateSupportingPaneScaffoldState(scaffoldDirective)
SupportingPaneScaffold(
scaffoldState = scaffoldState,
windowInsets = SupportingPaneScaffoldDefaults.windowInsetsAdaptive,
modifier = modifier,
mainPane = {
ScheduleGridVM(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ fun ScheduleGridScreen(
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = minSize),
modifier = modifier,
contentPadding = PaddingValues(vertical = SpacingTokens.LargeSpacing.toDp()),
contentPadding = PaddingValues(
vertical = SpacingTokens.LargeSpacing.toDp(),
horizontal = SpacingTokens.MediumSpacing.toDp()
),
verticalArrangement = Arrangement.spacedBy(mediumSpacing),
horizontalArrangement = Arrangement.spacedBy(mediumSpacing)
) {
Expand Down
1 change: 1 addition & 0 deletions theme-m3/speakers/speakers-feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(projects.themeM3.speakers.speakersScreens)
implementation(projects.themeM3.navigation)
implementation(projects.themeM3.style.theme)
implementation(projects.themeM3.style.components.adaptive)

implementation(libs.koin.androidx.compose)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package org.gdglille.devfest.android.theme.m3.speakers.feature
import androidx.compose.material3.adaptive.AnimatedPane
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.ListDetailPaneScaffold
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldDefaults
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import org.gdglille.devfest.android.theme.m3.style.adaptive.calculateStandardPaneScaffoldDirectiveAdaptive
import org.gdglille.devfest.android.theme.m3.style.adaptive.windowInsetsAdaptive

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
Expand All @@ -20,10 +24,13 @@ fun SpeakerAdaptive(
onLinkClicked: (url: String) -> Unit,
modifier: Modifier = Modifier
) {
val navigator = rememberListDetailPaneScaffoldNavigator()
val scaffoldDirective =
calculateStandardPaneScaffoldDirectiveAdaptive(currentWindowAdaptiveInfo())
val navigator = rememberListDetailPaneScaffoldNavigator(scaffoldDirective)
var selectedItem: String? by rememberSaveable { mutableStateOf(null) }
ListDetailPaneScaffold(
scaffoldState = navigator.scaffoldState,
windowInsets = ListDetailPaneScaffoldDefaults.windowInsetsAdaptive,
modifier = modifier,
listPane = {
AnimatedPane(Modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ fun SpeakersGridScreen(
state = state,
verticalArrangement = Arrangement.spacedBy(SpacingTokens.MediumSpacing.toDp()),
horizontalArrangement = Arrangement.spacedBy(SpacingTokens.MediumSpacing.toDp()),
contentPadding = PaddingValues(vertical = SpacingTokens.ExtraLargeSpacing.toDp()),
contentPadding = PaddingValues(
vertical = SpacingTokens.ExtraLargeSpacing.toDp(),
horizontal = SpacingTokens.MediumSpacing.toDp()
),
content = {
items(speakers.toList(), key = { it.id }) {
LargeSpeakerItem(
Expand Down
1 change: 1 addition & 0 deletions theme-m3/style/components/adaptive/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
15 changes: 15 additions & 0 deletions theme-m3/style/components/adaptive/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("conferences4hall.android.library")
id("conferences4hall.android.library.compose")
id("conferences4hall.quality")
}

android {
namespace = "org.gdglille.devfest.android.theme.m3.style.adaptive"
}

dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.material3.adaptive)
implementation(libs.androidx.compose.material3.windowsizeclass)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.gdglille.devfest.android.theme.m3.style.adaptive

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldDefaults
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable

/**
* By default, list detail scaffold configure a window inset as if it was used
* without NavigationSuiteScaffold component and add a vertical padding.
* This padding is useful when we display more than one pane on the screen but when
* we are in compact mode, we don't want any vertical padding.
*/
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
val ListDetailPaneScaffoldDefaults.windowInsetsAdaptive: WindowInsets
@Composable
get() {
val windowSizeClass = currentWindowAdaptiveInfo()
return if (windowSizeClass.windowSizeClass.widthSizeClass.isCompat) {
WindowInsets(0, 0, 0, 0)
} else {
windowInsets
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.gdglille.devfest.android.theme.m3.style.adaptive

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.HingePolicy
import androidx.compose.material3.adaptive.PaneScaffoldDirective
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
import androidx.compose.material3.adaptive.calculateStandardPaneScaffoldDirective
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
* By default, adaptive scaffold configure a content padding as if it was used
* without NavigationSuiteScaffold component and add a padding around the main pane.
* This padding is useful when we display more than one pane on the screen but when
* we are in compact mode, we don't want any padding.
*/
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
fun calculateStandardPaneScaffoldDirectiveAdaptive(
windowAdaptiveInfo: WindowAdaptiveInfo,
verticalHingePolicy: HingePolicy = HingePolicy.AvoidSeparating
): PaneScaffoldDirective {
val directive = calculateStandardPaneScaffoldDirective(windowAdaptiveInfo, verticalHingePolicy)
return if (windowAdaptiveInfo.windowSizeClass.widthSizeClass.isCompat) {
directive.copy(contentPadding = PaddingValues(0.dp))
} else {
directive
}
}

@Suppress("LongParameterList")
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
fun PaneScaffoldDirective.copy(
contentPadding: PaddingValues = this.contentPadding,
maxHorizontalPartitions: Int = this.maxHorizontalPartitions,
horizontalPartitionSpacerSize: Dp = this.horizontalPartitionSpacerSize,
maxVerticalPartitions: Int = this.maxVerticalPartitions,
verticalPartitionSpacerSize: Dp = this.verticalPartitionSpacerSize,
excludedBounds: List<Rect> = this.excludedBounds
): PaneScaffoldDirective = PaneScaffoldDirective(
contentPadding = contentPadding,
maxHorizontalPartitions = maxHorizontalPartitions,
horizontalPartitionSpacerSize = horizontalPartitionSpacerSize,
maxVerticalPartitions = maxVerticalPartitions,
verticalPartitionSpacerSize = verticalPartitionSpacerSize,
excludedBounds = excludedBounds
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.gdglille.devfest.android.theme.m3.style.adaptive

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.SupportingPaneScaffoldDefaults
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable

/**
* By default, supporting page scaffold configure a window inset as if it was used
* without NavigationSuiteScaffold component and add a vertical padding.
* This padding is useful when we display more than one pane on the screen but when
* we are in compact mode, we don't want any vertical padding.
*/
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
val SupportingPaneScaffoldDefaults.windowInsetsAdaptive: WindowInsets
@Composable
get() {
val windowSizeClass = currentWindowAdaptiveInfo()
return if (windowSizeClass.windowSizeClass.widthSizeClass.isCompat) {
WindowInsets(0, 0, 0, 0)
} else {
windowInsets
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gdglille.devfest.android.theme
package org.gdglille.devfest.android.theme.m3.style.adaptive

import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
Expand Down

0 comments on commit c94ba4e

Please sign in to comment.