Skip to content

Commit

Permalink
feat: Add SinglePaneScaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Dec 4, 2024
1 parent 1739bc7 commit 152c20a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ->
Expand All @@ -53,8 +55,7 @@ fun BottomStickyButtonScaffold(
) {
Box(
modifier = Modifier
.weight(1.0f)
.widthIn(max = Dimens.MaxSinglePaneScreenWidth),
.weight(1.0f),
content = content,
)
DoubleButtonCombo(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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)
)
}
}
}
}

0 comments on commit 152c20a

Please sign in to comment.