Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify contentPadding usage #79

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.infomaniak.swisstransfer.ui.components.BrandTopAppBar
@Composable
fun BrandTopAppBarScaffold(
floatingActionButton: @Composable () -> Unit = {},
content: @Composable (PaddingValues) -> Unit,
content: @Composable () -> Unit,
) {
SmallWindowTopAppBarScaffold(
smallWindowTopAppBar = { BrandTopAppBar() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.components

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.infomaniak.swisstransfer.ui.theme.LocalWindowAdaptiveInfo
import com.infomaniak.swisstransfer.ui.utils.isWindowSmall
Expand All @@ -28,19 +31,17 @@ import com.infomaniak.swisstransfer.ui.utils.isWindowSmall
fun SmallWindowTopAppBarScaffold(
smallWindowTopAppBar: @Composable () -> Unit = {},
floatingActionButton: @Composable () -> Unit = {},
content: @Composable (PaddingValues) -> Unit,
content: @Composable () -> Unit,
) {
val windowAdaptiveInfo = LocalWindowAdaptiveInfo.current

Scaffold(
topBar = { if (windowAdaptiveInfo.isWindowSmall()) smallWindowTopAppBar() },
floatingActionButton = floatingActionButton,
) { contentPadding ->
val paddingValues = if (windowAdaptiveInfo.isWindowSmall()) {
contentPadding
} else {
PaddingValues(all = 0.dp)
val paddingValues = if (windowAdaptiveInfo.isWindowSmall()) contentPadding else PaddingValues(all = 0.dp)
Box(modifier = Modifier.padding(paddingValues)) {
content()
}
content(paddingValues)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ fun ReceivedScreen(
private fun ReceivedScreen(areTransfersEmpty: () -> Boolean) {
BrandTopAppBarScaffold(
floatingActionButton = { ReceivedEmptyFab(areTransfersEmpty) },
) { contentPadding ->
) {
EmptyState(
icon = AppIllus.MascotSearching,
title = R.string.noTransferReceivedTitle,
description = R.string.noTransferReceivedDescription,
modifier = Modifier.padding(contentPadding),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow
import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow

@Composable
fun SentEmptyScreen(modifier: Modifier) {
fun SentEmptyScreen() {
Column(
modifier = modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Expand Down Expand Up @@ -91,7 +91,7 @@ fun SentEmptyScreen(modifier: Modifier) {
private fun SentEmptyScreenPreview() {
SwissTransferTheme {
Surface {
SentEmptyScreen(modifier = Modifier)
SentEmptyScreen()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLargeWindow
import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow
import java.util.UUID

@Composable
fun SentListScreen(
modifier: Modifier = Modifier,
transfers: List<Any>,
) {
LazyColumn(modifier) {
fun SentListScreen(transfers: List<Any>) {
LazyColumn {
items(items = transfers, key = { UUID.randomUUID() }) {
Text(text = "Sent screen")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.sent

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infomaniak.swisstransfer.ui.components.NewTransferFab
Expand Down Expand Up @@ -54,12 +52,11 @@ private fun SentScreen(transfers: List<Any>?) {
NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR)
}
},
) { contentPadding ->
val modifier = Modifier.padding(contentPadding)
) {
if (transfers.isEmpty()) {
SentEmptyScreen(modifier)
SentEmptyScreen()
} else {
SentListScreen(modifier, transfers)
SentListScreen(transfers)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ fun SettingsScreen(
) {
val selectedSetting = getSelectedSetting()

BrandTopAppBarScaffold { paddingsValue ->
BrandTopAppBarScaffold {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.selectableGroup()
.padding(paddingsValue),
.selectableGroup(),
) {
Text(
modifier = Modifier.padding(horizontal = Margin.Medium, vertical = Margin.Large),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.infomaniak.swisstransfer.ui.screen.main.settings.components

import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -48,12 +47,8 @@ fun OptionScaffold(
) {
SmallWindowTopAppBarScaffold(
smallWindowTopAppBar = { SwissTransferTopAppBar(topAppBarTitleRes, TopAppBarButton.backButton(navigateBack ?: {})) },
) { paddingsValue ->
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(paddingsValue),
) {
) {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
OptionTitle(titleRes = optionTitleRes)

var selectedItem by rememberSaveable { mutableIntStateOf(selectedSettingOptionPosition) }
Expand Down
Loading