Skip to content

Commit

Permalink
Simplify contentPadidng usage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LunarX committed Sep 25, 2024
1 parent e4064e4 commit 30cace9
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
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.PreviewMobile
import com.infomaniak.swisstransfer.ui.utils.PreviewTablet
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.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
Expand Down Expand Up @@ -54,12 +52,11 @@ private fun SentScreen(navType: NavigationSuiteType, 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()

BrandTobAppBarScaffold { paddingsValue ->
BrandTobAppBarScaffold {
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(
) {
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) }
Expand Down

0 comments on commit 30cace9

Please sign in to comment.