diff --git a/catalog/src/main/java/kiwi/orbit/compose/catalog/screens/ChoiceTileScreen.kt b/catalog/src/main/java/kiwi/orbit/compose/catalog/screens/ChoiceTileScreen.kt index 844749f5e..e7cfd12f0 100644 --- a/catalog/src/main/java/kiwi/orbit/compose/catalog/screens/ChoiceTileScreen.kt +++ b/catalog/src/main/java/kiwi/orbit/compose/catalog/screens/ChoiceTileScreen.kt @@ -1,6 +1,5 @@ package kiwi.orbit.compose.catalog.screens -import androidx.compose.foundation.Image import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -25,16 +24,12 @@ import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import kiwi.orbit.compose.catalog.components.CustomPlaceholder import kiwi.orbit.compose.icons.Icons -import kiwi.orbit.compose.illustrations.Illustrations import kiwi.orbit.compose.ui.controls.BadgeInfoSubtle -import kiwi.orbit.compose.ui.controls.BadgeNeutral import kiwi.orbit.compose.ui.controls.ChoiceTile -import kiwi.orbit.compose.ui.controls.ChoiceTileCentered import kiwi.orbit.compose.ui.controls.Icon import kiwi.orbit.compose.ui.controls.Scaffold import kiwi.orbit.compose.ui.controls.Stepper @@ -205,66 +200,5 @@ private fun ChoiceTileScreenInner() { onSelect = { selectedD = !selectedD }, content = { }, ) - - // Vertical padding to avoid clip issues on Android 12+ when over-scrolling. - // https://issuetracker.google.com/issues/215652703 - var selectedE by rememberSaveable { mutableIntStateOf(-1) } - Row( - Modifier - .height(IntrinsicSize.Max) - .padding(horizontal = 16.dp) - .padding(top = 12.dp) // half of the badge - .padding(top = 2.dp, bottom = 4.dp), // over-scroll workaround - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - ChoiceTileCentered( - modifier = Modifier - .fillMaxHeight() - .weight(1f), - selected = selectedE == 0, - onSelect = { selectedE = 0 }, - title = { Text("Plus Support") }, - description = { Text("Everyone sits together") }, - price = { BadgeNeutral { Text("Included") } }, - ) - - ChoiceTileCentered( - modifier = Modifier - .fillMaxHeight() - .weight(1f), - selected = selectedE == 1, - onSelect = { selectedE = 1 }, - icon = { - Image( - painter = Illustrations.Boarding, - contentDescription = null, - Modifier.height(60.dp), - ) - }, - title = { Text("Plus Support") }, - description = { Text("Everyone sits together") }, - price = { Text("+ 10 €") }, - ) - - ChoiceTileCentered( - modifier = Modifier - .fillMaxHeight() - .weight(1f), - selected = selectedE == 2, - onSelect = { selectedE = 2 }, - badgeContent = { - Text( - "Recommended Very Much", - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - }, - icon = { Icon(painter = Icons.BaggageSet, contentDescription = null) }, - title = { Text("Plus Support") }, - description = { Text("Everyone sits together") }, - price = { Text("+ 10 €") }, - largeHeading = false, - ) - } } } diff --git a/ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/controls/ChoiceTileCentered.kt b/ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/controls/ChoiceTileCentered.kt deleted file mode 100644 index 7d68d7f7e..000000000 --- a/ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/controls/ChoiceTileCentered.kt +++ /dev/null @@ -1,209 +0,0 @@ -package kiwi.orbit.compose.ui.controls - -import androidx.compose.animation.animateColorAsState -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.interaction.MutableInteractionSource -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.IntrinsicSize -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.RowScope -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.layout.layout -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.semantics.error -import androidx.compose.ui.semantics.selected -import androidx.compose.ui.semantics.semantics -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex -import kiwi.orbit.compose.icons.Icons -import kiwi.orbit.compose.ui.OrbitTheme -import kiwi.orbit.compose.ui.R -import kiwi.orbit.compose.ui.controls.internal.OrbitPreviews -import kiwi.orbit.compose.ui.controls.internal.Preview -import kiwi.orbit.compose.ui.foundation.ContentEmphasis -import kiwi.orbit.compose.ui.foundation.ProvideContentEmphasis -import kiwi.orbit.compose.ui.foundation.ProvideMergedTextStyle - -@Composable -public fun ChoiceTileCentered( - selected: Boolean, - onSelect: () -> Unit, - title: @Composable () -> Unit, - description: @Composable () -> Unit, - price: @Composable () -> Unit, - modifier: Modifier = Modifier, - isError: Boolean = false, - badgeContent: @Composable (RowScope.() -> Unit)? = null, - icon: @Composable () -> Unit = {}, - largeHeading: Boolean = true, - interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, -) { - val errorMessage = stringResource(R.string.orbit_field_default_error) - val color by animateColorAsState( - targetValue = when (selected) { - true -> OrbitTheme.colors.info.normal - false -> Color.Transparent - }, - label = "ChoiceTileCenteredBorderColor", - ) - Box( - modifier = modifier.semantics { - this.selected = selected - if (isError) this.error(errorMessage) - }, - propagateMinConstraints = true, - ) { - ChoiceTileBadge(badgeContent) - SurfaceCard( - onClick = onSelect, - interactionSource = interactionSource, - border = BorderStroke(2.dp, color), - ) { - Column( - Modifier - .padding(horizontal = 16.dp) - .padding(top = 22.dp, bottom = 16.dp), - verticalArrangement = Arrangement.SpaceBetween, - horizontalAlignment = Alignment.CenterHorizontally, - ) { - ChoiceTileContent( - selected = selected, - icon = icon, - title = title, - description = description, - price = price, - largeHeading = largeHeading, - ) - ChoiceTileFooter( - selected = selected, - isError = isError, - ) - } - } - } -} - -@Composable -private fun ChoiceTileBadge(badgeContent: @Composable (RowScope.() -> Unit)?) { - if (badgeContent == null) return - - Box(Modifier.zIndex(1f)) { - BadgeInfo( - modifier = Modifier - .align(Alignment.TopCenter) - .layout { measurable, constraints -> - val placeable = measurable.measure(constraints) - layout(placeable.width, placeable.height) { - placeable.placeRelative(0, placeable.height / -2) - } - }, - content = badgeContent, - ) - } -} - -@Composable -private fun ChoiceTileContent( - selected: Boolean, - icon: @Composable () -> Unit, - title: @Composable () -> Unit, - description: @Composable () -> Unit, - price: @Composable () -> Unit, - largeHeading: Boolean, -) { - Column( - verticalArrangement = Arrangement.spacedBy(4.dp), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - // Provide default icon size to 24.dp - ProvideMergedTextStyle(OrbitTheme.typography.title3) { - icon() - } - val headingStyle = when (largeHeading) { - true -> OrbitTheme.typography.title3 - false -> OrbitTheme.typography.title4 - }.copy(textAlign = TextAlign.Center) - ProvideMergedTextStyle(headingStyle) { - title() - } - ProvideContentEmphasis(ContentEmphasis.Minor) { - ProvideMergedTextStyle( - value = OrbitTheme.typography.bodyNormal.copy( - textAlign = TextAlign.Center, - ), - ) { - description() - } - } - ProvideMergedTextStyle( - value = OrbitTheme.typography.title3.copy( - textAlign = TextAlign.Center, - color = when (selected) { - true -> OrbitTheme.colors.info.normal - false -> Color.Unspecified - }, - ), - ) { - price() - } - } -} - -@Composable -private fun ChoiceTileFooter( - selected: Boolean, - isError: Boolean, -) { - Radio( - selected = selected, - onClick = null, - isError = isError, - modifier = Modifier - .padding(top = 12.dp) - .padding(2.dp), - ) -} - -@OrbitPreviews -@Composable -internal fun ChoiceTileCenteredPreview() { - Preview { - Row( - modifier = Modifier.height(IntrinsicSize.Max), - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - ChoiceTileCentered( - modifier = Modifier - .weight(1f) - .fillMaxHeight(), - selected = false, - onSelect = {}, - icon = { Icon(painter = Icons.BaggageSet, contentDescription = null) }, - title = { Text("Plus Support") }, - description = { Text("Everyone sits together") }, - price = { Text("+ 10 €") }, - ) - ChoiceTileCentered( - modifier = Modifier - .weight(1f) - .fillMaxHeight(), - selected = true, - onSelect = {}, - title = { Text("Minus Support") }, - description = {}, - price = { Text("+ 10 €") }, - ) - } - } -} diff --git a/ui/src/androidUnitTest/kotlin/kiwi/orbit/compose/ui/ScreenshotTest.kt b/ui/src/androidUnitTest/kotlin/kiwi/orbit/compose/ui/ScreenshotTest.kt index 7121d586c..06ea01ea0 100644 --- a/ui/src/androidUnitTest/kotlin/kiwi/orbit/compose/ui/ScreenshotTest.kt +++ b/ui/src/androidUnitTest/kotlin/kiwi/orbit/compose/ui/ScreenshotTest.kt @@ -31,7 +31,6 @@ import kiwi.orbit.compose.ui.controls.ButtonTextLinkPreview import kiwi.orbit.compose.ui.controls.CardPreview import kiwi.orbit.compose.ui.controls.CheckboxFieldPreview import kiwi.orbit.compose.ui.controls.CheckboxPreview -import kiwi.orbit.compose.ui.controls.ChoiceTileCenteredPreview import kiwi.orbit.compose.ui.controls.ChoiceTilePreview import kiwi.orbit.compose.ui.controls.CircularProgressIndicatorPreview import kiwi.orbit.compose.ui.controls.ClickableFieldPreview @@ -195,11 +194,6 @@ internal class ScreenshotTest { snapshot { ChoiceTilePreview() } } - @Test - fun choiceTileCentered() { - snapshot { ChoiceTileCenteredPreview() } - } - @Test fun circularProgressIndicator() { snapshot { CircularProgressIndicatorPreview() } diff --git a/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered.png b/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered.png deleted file mode 100644 index 64b7d471d..000000000 --- a/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f8afcc1e2a8066fa26f270e8c847e65e5c8f7a4cc23758d141e41104996fc5c6 -size 43408 diff --git a/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered_big.png b/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered_big.png deleted file mode 100644 index 2acaa788f..000000000 --- a/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered_big.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:e8ff05ead82d8eea7e7880b4edb8cf2cf8a069052e91874d1dbbb143eed1416f -size 65738 diff --git a/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered_dark.png b/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered_dark.png deleted file mode 100644 index 36ca9593e..000000000 --- a/ui/src/test/snapshots/images/kiwi.orbit.compose.ui_ScreenshotTest_choiceTileCentered_dark.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3ade91120d284aa29091fdfd75415b4eb52481414d6f120808ba61f888f0b342 -size 42360