Skip to content

Commit

Permalink
Make button nullables and update previews
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Aug 16, 2024
1 parent ebdf2fe commit 883484c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import androidx.compose.ui.Modifier
fun BottomStickyButtonScaffold(
modifier: Modifier = Modifier,
topBar: @Composable () -> Unit,
topButton: @Composable (Modifier) -> Unit,
bottomButton: @Composable (Modifier) -> Unit,
topButton: @Composable ((Modifier) -> Unit)? = null,
bottomButton: @Composable ((Modifier) -> Unit)? = null,
content: @Composable BoxScope.() -> Unit,
) {
Scaffold(topBar = topBar) { contentPaddings ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ private val WIDTH_THRESHOLD = 500.dp

@Composable
fun ColumnScope.DoubleButtonCombo(
topButton: @Composable (Modifier) -> Unit,
bottomButton: @Composable (Modifier) -> Unit
topButton: @Composable ((Modifier) -> Unit)? = null,
bottomButton: @Composable ((Modifier) -> Unit)? = null
) {
BoxWithConstraints(
modifier = Modifier
.widthIn(max = WIDTH_LIMIT)
.align(Alignment.CenterHorizontally),
) {
if (maxWidth < WIDTH_THRESHOLD) {
VerticallyStackedButtons(topButton, bottomButton)
} else {
HorizontallyStackedButtons(topButton, bottomButton)
when {
topButton == null && bottomButton == null -> Unit
topButton != null && bottomButton != null -> {
if (maxWidth < WIDTH_THRESHOLD) {
VerticallyStackedButtons(topButton, bottomButton)
} else {
HorizontallyStackedButtons(topButton, bottomButton)
}
}
else -> SingleButton(button = topButton ?: bottomButton!!)
}
}
}
Expand Down Expand Up @@ -84,3 +90,13 @@ private fun HorizontallyStackedButtons(
bottomButton(Modifier.weight(1f))
}
}

@Composable
private fun SingleButton(button: @Composable (Modifier) -> Unit) {
button(
Modifier
.fillMaxWidth()
.widthIn(WIDTH_LIMIT / 2)
.padding(bottom = Margin.Large, start = Margin.Medium, end = Margin.Medium),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.infomaniak.swisstransfer.ui.components

import android.content.res.Configuration
import androidx.annotation.StringRes
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -81,31 +82,21 @@ enum class ButtonType(val buttonColors: @Composable () -> ButtonColors) {
}),
}

@Preview
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL)
@Preview(name = "Light")
@Preview(name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL)
@Composable
private fun LargeButtonPreview() {
SwissTransferTheme {
Column {
LargeButton(
titleRes = R.string.appName,
imageVector = AppIcons.Add,
onClick = {},
)
Spacer(modifier = Modifier.height(Margin.Small))
LargeButton(
titleRes = R.string.appName,
imageVector = AppIcons.Add,
style = ButtonType.SECONDARY,
onClick = {},
)
Spacer(modifier = Modifier.height(Margin.Small))
LargeButton(
titleRes = R.string.appName,
imageVector = AppIcons.Add,
style = ButtonType.TERTIARY,
onClick = {},
)
Column(modifier = Modifier.background(SwissTransferTheme.materialColors.background)) {
ButtonType.entries.forEach {
LargeButton(
titleRes = R.string.appName,
style = it,
imageVector = AppIcons.Add,
onClick = {},
)
Spacer(modifier = Modifier.height(Margin.Small))
}
}
}
}

0 comments on commit 883484c

Please sign in to comment.