From 8fb69561a10c7b511dfdbb28739366e3cc4f4c71 Mon Sep 17 00:00:00 2001 From: Giannis Stamatopoulos Date: Mon, 2 Dec 2024 18:35:32 +0200 Subject: [PATCH] Refactor: Improves BottomBarButton padding logic. - Refactor bottom bar buttons to receive a modifier for padding instead of PaddingValues. - Update usages of bottom bar buttons in SuccessScreen, SelectCertificateScreen, and SelectQtspScreen to pass padding via modifier. - Update ContentScreen to calculate paddings for sticky bottom content based on screen padding and layout direction. - Update ScreenPadding.kt with a new function to calculate sticky bottom paddings. --- .../ui/component/content/ContentScreen.kt | 9 +++++- .../ui/component/utils/ScreenPadding.kt | 15 +++++++++ .../ui/component/wrap/WrapBottomBarButton.kt | 31 +++++++------------ .../SelectCertificateScreen.kt | 4 ++- .../ui/select_qtsp/SelectQtspScreen.kt | 4 ++- .../presentation/ui/success/SuccessScreen.kt | 4 ++- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/content/ContentScreen.kt b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/content/ContentScreen.kt index 1402490..8bb16f6 100644 --- a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/content/ContentScreen.kt +++ b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/content/ContentScreen.kt @@ -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 @@ -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 @@ -181,7 +183,12 @@ internal fun ContentScreen( .zIndex(Z_STICKY), contentAlignment = Alignment.Center ) { - stickyBottomContent(screenPaddings(padding)) + stickyBottomContent( + stickyBottomPaddings( + contentScreenPaddings = screenPaddings(padding), + layoutDirection = LocalLayoutDirection.current + ) + ) } } } diff --git a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/utils/ScreenPadding.kt b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/utils/ScreenPadding.kt index 921fdfb..5d73286 100644 --- a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/utils/ScreenPadding.kt +++ b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/utils/ScreenPadding.kt @@ -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 { @@ -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 diff --git a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/wrap/WrapBottomBarButton.kt b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/wrap/WrapBottomBarButton.kt index d0c82ce..27941dd 100644 --- a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/wrap/WrapBottomBarButton.kt +++ b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/component/wrap/WrapBottomBarButton.kt @@ -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 @@ -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 @@ -44,32 +40,32 @@ 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, ) } @@ -77,9 +73,9 @@ internal fun WrapBottomBarSecondaryButton( @Composable private fun WrapStickyBottomBar( config: StickyBottomBarConfig, + stickyBottomContentModifier: Modifier = Modifier, buttonText: String, enabled: Boolean, - padding: PaddingValues, onButtonClick: () -> Unit, ) { Column( @@ -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 ) { @@ -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 = {}, ) } @@ -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 = {}, ) } diff --git a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_certificate/SelectCertificateScreen.kt b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_certificate/SelectCertificateScreen.kt index c5d6174..82ad6ee 100644 --- a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_certificate/SelectCertificateScreen.kt +++ b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_certificate/SelectCertificateScreen.kt @@ -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 diff --git a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_qtsp/SelectQtspScreen.kt b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_qtsp/SelectQtspScreen.kt index a9c332e..4fe97de 100644 --- a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_qtsp/SelectQtspScreen.kt +++ b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/select_qtsp/SelectQtspScreen.kt @@ -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 diff --git a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/success/SuccessScreen.kt b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/success/SuccessScreen.kt index 77d067a..d20a6e0 100644 --- a/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/success/SuccessScreen.kt +++ b/rqes-ui-sdk/src/main/java/eu/europa/ec/eudi/rqesui/presentation/ui/success/SuccessScreen.kt @@ -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