From df80f141d817c7b4f397495ccc5caa98015111dc Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Wed, 25 Sep 2024 15:13:18 +0200 Subject: [PATCH] Simplify contentPadding usage Avoid passing the content padding through too many files when we don't need to. The freedom to handle the contentPaddings manually everywhere down the line is not needed. --- .../main/components/BrandTopAppBarScaffold.kt | 2 +- .../main/components/SmallWindowTopAppBarScaffold.kt | 13 +++++++------ .../ui/screen/main/received/ReceivedScreen.kt | 3 +-- .../ui/screen/main/sent/SentEmptyScreen.kt | 6 +++--- .../ui/screen/main/sent/SentListScreen.kt | 8 ++------ .../swisstransfer/ui/screen/main/sent/SentScreen.kt | 9 +++------ .../ui/screen/main/settings/SettingsScreen.kt | 5 ++--- .../main/settings/components/OptionScaffold.kt | 9 ++------- 8 files changed, 21 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTopAppBarScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTopAppBarScaffold.kt index 9e208e027..440866178 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTopAppBarScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTopAppBarScaffold.kt @@ -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() }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/SmallWindowTopAppBarScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/SmallWindowTopAppBarScaffold.kt index 4a8b3ec54..15ce10723 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/SmallWindowTopAppBarScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/SmallWindowTopAppBarScaffold.kt @@ -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 @@ -28,7 +31,7 @@ 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 @@ -36,11 +39,9 @@ fun SmallWindowTopAppBarScaffold( 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) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt index 04165bdf4..5a6be0f45 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/received/ReceivedScreen.kt @@ -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), ) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt index 445c2d074..dafa8336b 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentEmptyScreen.kt @@ -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, ) { @@ -91,7 +91,7 @@ fun SentEmptyScreen(modifier: Modifier) { private fun SentEmptyScreenPreview() { SwissTransferTheme { Surface { - SentEmptyScreen(modifier = Modifier) + SentEmptyScreen() } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt index a5b257ae9..36a0977e8 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentListScreen.kt @@ -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, -) { - LazyColumn(modifier) { +fun SentListScreen(transfers: List) { + LazyColumn { items(items = transfers, key = { UUID.randomUUID() }) { Text(text = "Sent screen") } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt index f638b47b7..716aa01ba 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/sent/SentScreen.kt @@ -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 @@ -54,12 +52,11 @@ private fun SentScreen(transfers: List?) { NewTransferFab(newTransferFabType = NewTransferFabType.BOTTOM_BAR) } }, - ) { contentPadding -> - val modifier = Modifier.padding(contentPadding) + ) { if (transfers.isEmpty()) { - SentEmptyScreen(modifier) + SentEmptyScreen() } else { - SentListScreen(modifier, transfers) + SentListScreen(transfers) } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt index f13586d4c..486377ab5 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsScreen.kt @@ -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), diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt index 3cc029391..e9f8fcd33 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/components/OptionScaffold.kt @@ -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 @@ -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) }