Skip to content

Commit

Permalink
Merge pull request #32 from niscy-eudiw/refactor/sticky_bottom_rework
Browse files Browse the repository at this point in the history
Refactor: Improves BottomBarButton padding logic.
  • Loading branch information
stzouvaras authored Dec 2, 2024
2 parents 192b4b2 + 8fb6956 commit 118bbdf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.SoftwareKeyboardController
import androidx.compose.ui.text.style.TextOverflow
Expand All @@ -58,6 +59,7 @@ import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.SPACING_SMALL
import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.TopSpacing
import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.Z_STICKY
import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.screenPaddings
import eu.europa.ec.eudi.rqesui.presentation.ui.component.utils.stickyBottomPaddings
import eu.europa.ec.eudi.rqesui.presentation.ui.component.wrap.WrapIcon
import eu.europa.ec.eudi.rqesui.presentation.ui.component.wrap.WrapIconButton

Expand Down Expand Up @@ -181,7 +183,12 @@ internal fun ContentScreen(
.zIndex(Z_STICKY),
contentAlignment = Alignment.Center
) {
stickyBottomContent(screenPaddings(padding))
stickyBottomContent(
stickyBottomPaddings(
contentScreenPaddings = screenPaddings(padding),
layoutDirection = LocalLayoutDirection.current
)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package eu.europa.ec.eudi.rqesui.presentation.ui.component.utils

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp

internal enum class TopSpacing {
Expand All @@ -33,6 +36,18 @@ internal fun screenPaddings(
bottom = SPACING_LARGE.dp + (append?.calculateBottomPadding() ?: 0.dp)
)

internal fun stickyBottomPaddings(
contentScreenPaddings: PaddingValues,
layoutDirection: LayoutDirection
): PaddingValues {
return PaddingValues(
start = contentScreenPaddings.calculateStartPadding(layoutDirection),
end = contentScreenPaddings.calculateEndPadding(layoutDirection),
top = contentScreenPaddings.calculateBottomPadding(),
bottom = contentScreenPaddings.calculateBottomPadding()
)
}

private fun calculateTopSpacing(topSpacing: TopSpacing): Int = when (topSpacing) {
TopSpacing.WithToolbar -> SPACING_SMALL
TopSpacing.WithoutToolbar -> SPACING_EXTRA_LARGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ package eu.europa.ec.eudi.rqesui.presentation.ui.component.wrap

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.HorizontalDivider
Expand All @@ -30,7 +27,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import eu.europa.ec.eudi.rqesui.infrastructure.theme.values.divider
import eu.europa.ec.eudi.rqesui.presentation.ui.component.preview.PreviewTheme
Expand All @@ -44,42 +40,42 @@ private sealed interface StickyBottomBarConfig {

@Composable
internal fun WrapBottomBarPrimaryButton(
stickyBottomContentModifier: Modifier = Modifier,
buttonText: String,
enabled: Boolean = true,
padding: PaddingValues,
onButtonClick: () -> Unit,
) {
WrapStickyBottomBar(
config = StickyBottomBarConfig.Primary,
stickyBottomContentModifier = stickyBottomContentModifier,
buttonText = buttonText,
enabled = enabled,
padding = padding,
onButtonClick = onButtonClick,
)
}

@Composable
internal fun WrapBottomBarSecondaryButton(
stickyBottomContentModifier: Modifier = Modifier,
buttonText: String,
enabled: Boolean = true,
padding: PaddingValues,
onButtonClick: () -> Unit,
) {
WrapStickyBottomBar(
config = StickyBottomBarConfig.Secondary,
stickyBottomContentModifier = stickyBottomContentModifier,
buttonText = buttonText,
enabled = enabled,
padding = padding,
onButtonClick = onButtonClick,
)
}

@Composable
private fun WrapStickyBottomBar(
config: StickyBottomBarConfig,
stickyBottomContentModifier: Modifier = Modifier,
buttonText: String,
enabled: Boolean,
padding: PaddingValues,
onButtonClick: () -> Unit,
) {
Column(
Expand All @@ -93,14 +89,7 @@ private fun WrapStickyBottomBar(
)

Row(
modifier = Modifier
.fillMaxWidth()
.padding(
top = padding.calculateBottomPadding(),
bottom = padding.calculateBottomPadding(),
start = padding.calculateStartPadding(LayoutDirection.Ltr),
end = padding.calculateEndPadding(LayoutDirection.Ltr)
),
modifier = stickyBottomContentModifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Expand Down Expand Up @@ -156,8 +145,10 @@ private fun ConfigBasedButton(
private fun WrapBottomBarPrimaryButtonPreview() {
PreviewTheme {
WrapBottomBarPrimaryButton(
stickyBottomContentModifier = Modifier
.fillMaxWidth()
.padding(SPACING_LARGE.dp),
buttonText = "Sign",
padding = PaddingValues(SPACING_LARGE.dp),
onButtonClick = {},
)
}
Expand All @@ -168,8 +159,10 @@ private fun WrapBottomBarPrimaryButtonPreview() {
private fun WrapBottomBarSecondaryButtonPreview() {
PreviewTheme {
WrapBottomBarSecondaryButton(
stickyBottomContentModifier = Modifier
.fillMaxWidth()
.padding(SPACING_LARGE.dp),
buttonText = "Sign",
padding = PaddingValues(SPACING_LARGE.dp),
onButtonClick = {},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ internal fun SelectCertificateScreen(
contentErrorConfig = state.error,
stickyBottom = { paddingValues ->
WrapBottomBarPrimaryButton(
stickyBottomContentModifier = Modifier
.fillMaxWidth()
.padding(paddingValues),
buttonText = state.bottomBarButtonText,
enabled = state.isBottomBarButtonEnabled,
padding = paddingValues,
onButtonClick = {
viewModel.setEvent(
Event.BottomBarButtonPressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ internal fun SelectQtspScreen(
contentErrorConfig = state.error,
stickyBottom = { paddingValues ->
WrapBottomBarPrimaryButton(
stickyBottomContentModifier = Modifier
.fillMaxWidth()
.padding(paddingValues),
buttonText = state.bottomBarButtonText,
padding = paddingValues,
onButtonClick = {
viewModel.setEvent(
Event.BottomBarButtonPressed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ internal fun SuccessScreen(
contentErrorConfig = state.error,
stickyBottom = { paddingValues ->
WrapBottomBarSecondaryButton(
stickyBottomContentModifier = Modifier
.fillMaxWidth()
.padding(paddingValues),
buttonText = state.bottomBarButtonText,
enabled = state.isBottomBarButtonEnabled,
padding = paddingValues,
onButtonClick = {
viewModel.setEvent(
Event.BottomBarButtonPressed
Expand Down

0 comments on commit 118bbdf

Please sign in to comment.