Skip to content

Commit

Permalink
refactor: Better spacings management
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Dec 5, 2024
1 parent 6bddbee commit efffb2c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ 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
import com.infomaniak.swisstransfer.ui.utils.PreviewSmallWindow

private val STICKY_BUTTON_VERTICAL_PADDING = Margin.Small

@Composable
fun BottomStickyButtonScaffold(
modifier: Modifier = Modifier,
Expand All @@ -49,18 +48,20 @@ fun BottomStickyButtonScaffold(
Column(
modifier = modifier
.fillMaxWidth()
.padding(contentPaddings)
.padding(vertical = STICKY_BUTTON_VERTICAL_PADDING),
.padding(contentPaddings),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Box(
modifier = Modifier
.padding(bottom = STICKY_BUTTON_VERTICAL_PADDING)
.weight(1.0f)
.widthIn(max = Dimens.MaxSinglePaneScreenWidth),
content = content,
)
DoubleButtonCombo(topButton, bottomButton)
DoubleButtonCombo(
modifier = Modifier.padding(vertical = Margin.Small),
topButton = topButton,
bottomButton = bottomButton
)
}
}
}
Expand All @@ -72,23 +73,8 @@ private fun Preview() {
SwissTransferTheme {
Surface {
BottomStickyButtonScaffold(
topBar = {
Text(
modifier = Modifier
.fillMaxWidth()
.background(Color.DarkGray),
text = "topBar",
textAlign = TextAlign.Center,
)
},
topButton = { modifier ->
SwissTransferButton(
modifier = modifier,
style = ButtonType.PRIMARY,
onClick = {},
content = { Text("sticky button") },
)
},
topBar = { BrandTopAppBar() },
topButton = { modifier -> LargeButton(R.string.appName, onClick = {}, modifier = modifier) },
) {
Text(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ private val WIDTH_THRESHOLD = 500.dp

@Composable
fun ColumnScope.DoubleButtonCombo(
modifier: Modifier = Modifier,
topButton: @Composable ((Modifier) -> Unit)? = null,
bottomButton: @Composable ((Modifier) -> Unit)? = null
) {
BoxWithConstraints(
modifier = Modifier
modifier = modifier
.widthIn(max = Dimens.DoubleButtonMaxWidth)
.align(Alignment.CenterHorizontally),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ private fun ImportFilesScreen(
content = {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
FilesToImport(files, removeFileByUid, addFiles, shouldStartByPromptingUserForFiles)
Spacer(Modifier.height(Margin.Medium))
ImportTextFields(
modifier = Modifier
.padding(horizontal = Margin.Medium)
.fillMaxWidth(),
modifier = Modifier.padding(horizontal = Margin.Medium),
transferMessage = transferMessage,
selectedTransferType = selectedTransferType.get,
)
Expand Down Expand Up @@ -194,27 +193,29 @@ private fun FilesToImport(

ImportFilesTitle(modifier = Modifier.padding(horizontal = Margin.Medium), titleRes = R.string.myFilesTitle)
ImportedFilesCard(
modifier = Modifier.padding(Margin.Medium),
modifier = Modifier.padding(horizontal = Margin.Medium),
files = files,
pickFiles = ::pickFiles,
removeFileByUid = removeFileByUid,
)
}

@Composable
private fun ColumnScope.ImportTextFields(
private fun ImportTextFields(
modifier: Modifier,
transferMessage: GetSetCallbacks<String>,
selectedTransferType: () -> TransferTypeUi,
) {
EmailAddressesTextFields(modifier, selectedTransferType)
SwissTransferTextField(
modifier = modifier,
label = stringResource(R.string.transferMessagePlaceholder),
isRequired = false,
minLineNumber = 3,
onValueChange = transferMessage.set,
)
Column(modifier) {
EmailAddressesTextFields(Modifier.fillMaxWidth(), selectedTransferType)
SwissTransferTextField(
modifier = Modifier.fillMaxWidth(),
label = stringResource(R.string.transferMessagePlaceholder),
isRequired = false,
minLineNumber = 3,
onValueChange = transferMessage.set,
)
}
}

@Composable
Expand Down Expand Up @@ -242,7 +243,7 @@ private fun ColumnScope.EmailAddressesTextFields(modifier: Modifier, selectedTra

@Composable
private fun SendByOptions(selectedTransferType: GetSetCallbacks<TransferTypeUi>) {
ImportFilesTitle(Modifier.padding(Margin.Medium), titleRes = R.string.transferTypeTitle)
ImportFilesTitle(Modifier.padding(horizontal = Margin.Medium), titleRes = R.string.transferTypeTitle)
TransferTypeButtons(selectedTransferType)
}

Expand All @@ -255,7 +256,7 @@ private fun TransferOptions(transferOptionsCallbacks: TransferOptionsCallbacks)
showTransferOption = null
}

ImportFilesTitle(Modifier.padding(Margin.Medium), titleRes = R.string.advancedSettingsTitle)
ImportFilesTitle(Modifier.padding(horizontal = Margin.Medium), titleRes = R.string.advancedSettingsTitle)
TransferOptionsTypes(
modifier = Modifier.padding(horizontal = Margin.Medium),
transferOptionsStates = transferOptionsCallbacks.transferOptionsStates,
Expand Down Expand Up @@ -302,7 +303,7 @@ private fun TransferOptionsDialogs(
@Composable
private fun ImportFilesTitle(modifier: Modifier = Modifier, @StringRes titleRes: Int) {
Text(
modifier = modifier,
modifier = modifier.padding(vertical = Margin.Medium),
style = SwissTransferTheme.typography.bodySmallRegular,
text = stringResource(titleRes),
)
Expand Down Expand Up @@ -394,7 +395,7 @@ private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files:
filesToImportCount = { 0 },
currentSessionFilesCount = { 0 },
transferMessage = GetSetCallbacks(get = { "" }, set = {}),
selectedTransferType = GetSetCallbacks(get = { TransferTypeUi.QR_CODE }, set = {}),
selectedTransferType = GetSetCallbacks(get = { TransferTypeUi.MAIL }, set = {}),
transferOptionsCallbacks = transferOptionsCallbacks,
removeFileByUid = {},
addFiles = {},
Expand Down

0 comments on commit efffb2c

Please sign in to comment.