diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BottomStickyButtonScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BottomStickyButtonScaffold.kt index d842bcba3..5f1e1ce07 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BottomStickyButtonScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/BottomStickyButtonScaffold.kt @@ -19,14 +19,16 @@ package com.infomaniak.swisstransfer.ui.components import androidx.compose.foundation.background import androidx.compose.foundation.layout.* -import androidx.compose.material3.* +import androidx.compose.material3.SnackbarHost +import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Surface +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.style.TextAlign import com.infomaniak.swisstransfer.R -import com.infomaniak.swisstransfer.ui.theme.Dimens import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow @@ -41,7 +43,7 @@ fun BottomStickyButtonScaffold( bottomButton: @Composable ((Modifier) -> Unit)? = null, content: @Composable BoxScope.() -> Unit, ) { - Scaffold( + SinglePaneScaffold( snackbarHost = { snackbarHostState?.let { SnackbarHost(hostState = it) } }, topBar = topBar, ) { contentPaddings -> @@ -53,8 +55,7 @@ fun BottomStickyButtonScaffold( ) { Box( modifier = Modifier - .weight(1.0f) - .widthIn(max = Dimens.MaxSinglePaneScreenWidth), + .weight(1.0f), content = content, ) DoubleButtonCombo( diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SinglePaneScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SinglePaneScaffold.kt new file mode 100644 index 000000000..545dea914 --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SinglePaneScaffold.kt @@ -0,0 +1,71 @@ +/* + * Infomaniak SwissTransfer - Android + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.swisstransfer.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import com.infomaniak.swisstransfer.ui.theme.Dimens +import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme +import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow +import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark + +@Composable +fun SinglePaneScaffold( + topBar: @Composable () -> Unit = {}, + bottomBar: @Composable () -> Unit = {}, + snackbarHost: @Composable () -> Unit = {}, + content: @Composable (PaddingValues) -> Unit, +) { + Scaffold( + topBar = topBar, + bottomBar = bottomBar, + snackbarHost = snackbarHost, + ) { contentPadding -> + Box( + contentAlignment = Alignment.TopCenter, + modifier = Modifier.fillMaxWidth(), + ) { + Box(Modifier.widthIn(max = Dimens.MaxSinglePaneScreenWidth)) { + content(contentPadding) + } + } + } +} + +@PreviewLightAndDark +@PreviewLargeWindow +@Composable +private fun Preview() { + SwissTransferTheme { + Surface { + SinglePaneScaffold { + Box( + Modifier + .fillMaxSize() + .background(Color.Cyan) + ) + } + } + } +}