From 30cace9fcce48e3ead6e86fcb4a1a2154236ecd5 Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Wed, 25 Sep 2024 15:13:18 +0200 Subject: [PATCH] Simplify contentPadidng 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 --- .../main/components/BrandTobAppBarScaffold.kt | 2 +- .../main/components/PhoneTopAppBarScaffold.kt | 17 ++++++++++------- .../ui/screen/main/received/ReceivedScreen.kt | 3 +-- .../ui/screen/main/sent/SentEmptyScreen.kt | 6 +++--- .../ui/screen/main/sent/SentListScreen.kt | 8 ++------ .../ui/screen/main/sent/SentScreen.kt | 9 +++------ .../ui/screen/main/settings/SettingsScreen.kt | 5 ++--- .../main/settings/components/OptionScaffold.kt | 9 ++------- 8 files changed, 24 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTobAppBarScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTobAppBarScaffold.kt index 4d1049423..f84ff37c1 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTobAppBarScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/BrandTobAppBarScaffold.kt @@ -24,7 +24,7 @@ import com.infomaniak.swisstransfer.ui.components.BrandTobAppBar @Composable fun BrandTobAppBarScaffold( floatingActionButton: @Composable () -> Unit = {}, - content: @Composable (PaddingValues) -> Unit, + content: @Composable () -> Unit, ) { PhoneTopAppBarScaffold( phoneTopAppBar = { BrandTobAppBar() }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/PhoneTopAppBarScaffold.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/PhoneTopAppBarScaffold.kt index 133d33529..de6c8acb5 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/PhoneTopAppBarScaffold.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/components/PhoneTopAppBarScaffold.kt @@ -17,27 +17,30 @@ */ 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.material3.adaptive.navigationsuite.NavigationSuiteType import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable fun PhoneTopAppBarScaffold( phoneTopAppBar: @Composable () -> Unit = {}, floatingActionButton: @Composable () -> Unit = {}, - content: @Composable (PaddingValues) -> Unit, + content: @Composable () -> Unit, ) { + val isWindowSmall = LocalNavType.current == NavigationSuiteType.NavigationBar + Scaffold( - topBar = { if (LocalNavType.current == NavigationSuiteType.NavigationBar) phoneTopAppBar() }, + topBar = { if (isWindowSmall) phoneTopAppBar() }, floatingActionButton = floatingActionButton, ) { contentPadding -> - val paddingValues = if (LocalNavType.current == NavigationSuiteType.NavigationBar) { - contentPadding - } else { - PaddingValues(all = 0.dp) + val paddingValues = if (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 d2db9603e..b7ecc9ab0 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) { BrandTobAppBarScaffold( 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 c33bb7b29..d6d783b54 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.PreviewMobile import com.infomaniak.swisstransfer.ui.utils.PreviewTablet @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 e30f5656c..2b1390591 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.PreviewMobile import com.infomaniak.swisstransfer.ui.utils.PreviewTablet 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 f9afa22af..098e97a4c 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.navigationsuite.NavigationSuiteType 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(navType: NavigationSuiteType, 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 58ad0b0ab..795f440f9 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() - BrandTobAppBarScaffold { paddingsValue -> + BrandTobAppBarScaffold { 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 1db13707f..34df8bbd3 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( ) { PhoneTopAppBarScaffold( phoneTopAppBar = { SwissTransferTobAppBar(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) }