diff --git a/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarDayCell.kt b/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarDayCell.kt index 9145fa886f..d5d2e5135d 100644 --- a/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarDayCell.kt +++ b/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarDayCell.kt @@ -18,6 +18,7 @@ package net.skyscanner.backpack.compose.calendar.internal +import androidx.compose.animation.Crossfade import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable @@ -65,94 +66,97 @@ internal fun BpkCalendarDayCell( onClick: (CalendarCell.Day) -> Unit, ) { - val selection = model.selection - val inactive = model.inactive - - val status = model.info.status - val style = model.info.style - val label = model.info.label - - Column( - verticalArrangement = Arrangement.Top, - horizontalAlignment = Alignment.CenterHorizontally, - modifier = modifier - .padding(bottom = BpkSpacing.Lg) - .clickable( - indication = null, - enabled = !inactive, - onClick = { onClick(model) }, - onClickLabel = model.onClickLabel, - interactionSource = remember { MutableInteractionSource() }, - ) - .semantics { - if (model.stateDescription != null) { - stateDescription = model.stateDescription!! - } else { - selected = selection != null && selection != Selection.Middle - } - }, - ) { - Box( - contentAlignment = Alignment.Center, - modifier = Modifier - .fillMaxWidth() - .cellSelectionBackground( - surfaceSubtle = BpkTheme.colors.surfaceSubtle, - selection = selection, - ), - ) { + Crossfade(model, label = "Day cell selection transition") { mModel -> + val selection = mModel.selection + val inactive = mModel.inactive - Spacer( - Modifier - .size(BpkCalendarSizes.SelectionHeight) - .cellDayBackground( - coreAccent = BpkTheme.colors.coreAccent, + val status = mModel.info.status + val style = mModel.info.style + val label = mModel.info.label + + Column( + verticalArrangement = Arrangement.Top, + horizontalAlignment = Alignment.CenterHorizontally, + modifier = modifier + .padding(bottom = BpkSpacing.Lg) + .clickable( + indication = null, + enabled = !inactive, + onClick = { onClick(mModel) }, + onClickLabel = mModel.onClickLabel, + interactionSource = remember { MutableInteractionSource() }, + ) + .semantics { + if (mModel.stateDescription != null) { + stateDescription = mModel.stateDescription!! + } else { + selected = selection != null && selection != Selection.Middle + } + }, + ) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillMaxWidth() + .cellSelectionBackground( surfaceSubtle = BpkTheme.colors.surfaceSubtle, selection = selection, ), - ) + ) { - BpkText( - text = model.text.toString(), - modifier = Modifier.semantics { - contentDescription = model.contentDescription - }, - overflow = TextOverflow.Ellipsis, - maxLines = 1, - style = BpkTheme.typography.label1, - color = dateColor(selection, status, inactive, style), - ) - } + Spacer( + Modifier + .size(BpkCalendarSizes.SelectionHeight) + .cellDayBackground( + coreAccent = BpkTheme.colors.coreAccent, + surfaceSubtle = BpkTheme.colors.surfaceSubtle, + selection = selection, + ), + ) - if (!inactive) { - when (val cellLabel = model.info.label) { - is CellLabel.Text -> { - if (cellLabel.text.isNotBlank()) { - BpkText( - text = cellLabel.text, - modifier = Modifier - .padding(horizontal = BpkSpacing.Sm), - overflow = TextOverflow.Ellipsis, - textAlign = TextAlign.Center, - maxLines = 2, - style = BpkTheme.typography.caption, - color = labelColor(status, style), - ) - } - } - is CellLabel.Icon -> { - cellLabel.resId.let { resId -> - BpkIcon.findBySmall(resId)?.let { bpkIcon -> - val iconTint = cellLabel.tint - ?.let { colorRes -> ContextCompat.getColor(LocalContext.current, colorRes) } - ?.let { Color(it) } ?: LocalContentColor.current - BpkIcon( - icon = bpkIcon, - tint = iconTint, - contentDescription = null, + BpkText( + text = mModel.text.toString(), + modifier = Modifier.semantics { + contentDescription = mModel.contentDescription + }, + overflow = TextOverflow.Ellipsis, + maxLines = 1, + style = BpkTheme.typography.label1, + color = dateColor(selection, status, inactive, style), + ) + } + + if (!inactive) { + when (val cellLabel = mModel.info.label) { + is CellLabel.Text -> { + if (cellLabel.text.isNotBlank()) { + BpkText( + text = cellLabel.text, + modifier = Modifier + .padding(horizontal = BpkSpacing.Sm), + overflow = TextOverflow.Ellipsis, + textAlign = TextAlign.Center, + maxLines = 2, + style = BpkTheme.typography.caption, + color = labelColor(status, style), ) } } + + is CellLabel.Icon -> { + cellLabel.resId.let { resId -> + BpkIcon.findBySmall(resId)?.let { bpkIcon -> + val iconTint = cellLabel.tint + ?.let { colorRes -> ContextCompat.getColor(LocalContext.current, colorRes) } + ?.let { Color(it) } ?: LocalContentColor.current + BpkIcon( + icon = bpkIcon, + tint = iconTint, + contentDescription = null, + ) + } + } + } } } } diff --git a/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarGrid.kt b/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarGrid.kt index c66a7cd986..9b57816823 100644 --- a/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarGrid.kt +++ b/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarGrid.kt @@ -72,7 +72,7 @@ internal fun BpkCalendarGrid( when (val item = state.cells[index]) { is CalendarCell.Day -> BpkCalendarDayCell(item) { onClick(CalendarInteraction.DateClicked(it)) } is CalendarCell.Header -> BpkCalendarHeaderCell(item) { onClick(CalendarInteraction.SelectMonthClicked(it)) } - is CalendarCell.Space -> BpkCalendarSpaceCell(item) + is CalendarCell.Space -> BpkCalendarSpaceCell() } }, ) diff --git a/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarSpaceCell.kt b/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarSpaceCell.kt index d29cb7b3c4..17a12bb01e 100644 --- a/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarSpaceCell.kt +++ b/backpack-compose/src/main/kotlin/net/skyscanner/backpack/compose/calendar/internal/BpkCalendarSpaceCell.kt @@ -18,25 +18,16 @@ package net.skyscanner.backpack.compose.calendar.internal -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import net.skyscanner.backpack.calendar2.data.CalendarCell -import net.skyscanner.backpack.compose.theme.BpkTheme -import net.skyscanner.backpack.compose.utils.applyIf @Composable internal fun BpkCalendarSpaceCell( - model: CalendarCell.Space, modifier: Modifier = Modifier, ) { Spacer( - modifier = modifier - .height(BpkCalendarSizes.SelectionHeight) - .applyIf(model.selected) { - background(BpkTheme.colors.surfaceSubtle) - }, + modifier = modifier.height(BpkCalendarSizes.SelectionHeight), ) }