Skip to content

Commit

Permalink
Merge pull request #173 from Infomaniak/extract-emailsFlowRow
Browse files Browse the repository at this point in the history
refactor: Extract EmailsFlowRow to its own component
  • Loading branch information
KevinBoulongne authored Nov 13, 2024
2 parents 6e007da + 1d7a6f0 commit b451d8b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import com.infomaniak.swisstransfer.ui.theme.CustomShapes
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
Expand All @@ -38,6 +39,8 @@ fun EmailAddressChip(
label = {
Text(
text = text,
maxLines = 1,
overflow = TextOverflow.MiddleEllipsis,
style = SwissTransferTheme.typography.bodyRegular,
)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Infomaniak SwissTransfer - Android
* Copyright (C) 2024 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.swisstransfer.ui.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.PreviewParameter
import com.infomaniak.swisstransfer.ui.previewparameter.EmailsPreviewParameter
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun EmailsFlowRow(
emails: List<String>,
modifier: Modifier = Modifier,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
) {
FlowRow(
modifier = modifier,
horizontalArrangement = horizontalArrangement,
) {
emails.forEach {
EmailAddressChip(
text = it,
modifier = Modifier.padding(horizontal = Margin.Micro),
)
}
}
}

@PreviewLightAndDark
@Composable
private fun Preview(@PreviewParameter(EmailsPreviewParameter::class) emails: List<String>) {
SwissTransferTheme {
Surface {
EmailsFlowRow(emails)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,29 @@ fun UploadSuccessEmailScreen(
onClick = closeActivity,
)
},
content = { Content(emails) },
)
}

@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun Content(emails: List<String>) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(Margin.Medium),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(Margin.Medium),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {

IllustratedMessageBlock(
icon = AppIllus.Beers.image(),
title = TransferType.MAIL.titleRes,
description = pluralStringResource(TransferType.MAIL.descriptionRes!!, emails.count()),
)
IllustratedMessageBlock(
icon = AppIllus.Beers.image(),
title = TransferType.MAIL.titleRes,
description = pluralStringResource(TransferType.MAIL.descriptionRes!!, emails.count()),
)

Spacer(modifier = Modifier.height(Margin.Medium))
Spacer(modifier = Modifier.height(Margin.Medium))

FlowRow(
modifier = Modifier.widthIn(max = 800.dp),
horizontalArrangement = Arrangement.Center,
) {
emails.forEach {
EmailAddressChip(
text = it,
modifier = Modifier.padding(horizontal = Margin.Micro),
)
}
EmailsFlowRow(
emails = emails,
modifier = Modifier.widthIn(max = 800.dp),
horizontalArrangement = Arrangement.Center,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ val CustomLightColorScheme = CustomColorScheme(
transferTypeQrOnContainer = Color(green_main),
transferTypeProximityContainer = Color(specific3),
transferTypeProximityOnContainer = Color(specific4),
emailAddressChipColor = Color(green_contrast),
emailAddressChipColor = Color(green_secondary),
onEmailAddressChipColor = Color(green_dark),
qrCodeDarkPixels = Color(green_dark),
qrCodeLightPixels = Color(white),
Expand Down

0 comments on commit b451d8b

Please sign in to comment.