Skip to content

Commit

Permalink
Made overlayType nullable and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Saidu Ernest Kamara committed Sep 10, 2023
1 parent 64f2b6b commit 128757c
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,88 @@
package net.skyscanner.backpack.compose.graphicpromotion

import net.skyscanner.backpack.compose.BpkSnapshotTest
import net.skyscanner.backpack.demo.compose.GraphicPromoStoryTopAligned
import net.skyscanner.backpack.compose.overlay.BpkOverlayType
import net.skyscanner.backpack.demo.compose.BpkGraphicPromoSample
import net.skyscanner.backpack.demo.compose.GraphicPromoStoryDefault
import org.junit.Test

class BpkGraphicPromoTest : BpkSnapshotTest() {

@Test
fun default() = snap {
GraphicPromoStoryTopAligned()
GraphicPromoStoryDefault()
}

@Test
fun defaultWithOverlay() = snap {
BpkGraphicPromoSample(
headline = "Three Parks Challenge",
overlayType = BpkOverlayType.SolidHigh,
)
}

@Test
fun topAlignedKickerAvailable() = snap {
BpkGraphicPromoSample(
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
)
}

@Test
fun topAlignedKickerSubHeadlineAvailable() = snap {
BpkGraphicPromoSample(
kicker = "Travel tips",
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
)
}

@Test
fun topAlignedKickerSubHeadlineSponsoredAvailable() = snap {
BpkGraphicPromoSample(
kicker = "Travel tips",
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
sponsor = Sponsor(
accessibilityLabel = "Sponsored",
logo = "https://images.kiwi.com/airlines/64/FR.png",
title = "Sponsored",
),
)
}

@Test
fun bottomAlignedKickerAvailable() = snap {
BpkGraphicPromoSample(
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
verticalAlignment = VerticalAlignment.Bottom,
)
}

@Test
fun bottomAlignedKickerSubHeadlineAvailable() = snap {
BpkGraphicPromoSample(
kicker = "Travel tips",
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
verticalAlignment = VerticalAlignment.Bottom,
)
}

@Test
fun bottomAlignedKickerSubHeadlineSponsoredAvailable() = snap {
BpkGraphicPromoSample(
kicker = "Travel tips",
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
sponsor = Sponsor(
accessibilityLabel = "Sponsored",
logo = "https://images.kiwi.com/airlines/64/FR.png",
title = "Sponsored",
),
verticalAlignment = VerticalAlignment.Bottom,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,11 @@ import net.skyscanner.backpack.demo.meta.ComposeStory

@Composable
@GraphicPromoComponent
@ComposeStory(name = "Top aligned")
internal fun GraphicPromoStoryTopAligned(modifier: Modifier = Modifier) {
@ComposeStory
internal fun GraphicPromoStoryDefault(modifier: Modifier = Modifier) {
Column(modifier) {
BpkGraphicPromoSample(
kicker = "Travel tips",
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
)
}
}

@Composable
@GraphicPromoComponent
@ComposeStory(name = "Bottom aligned")
internal fun GraphicPromoStoryBottomAligned(modifier: Modifier = Modifier) {
Column(modifier) {
BpkGraphicPromoSample(
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
)
}
}

@Composable
@GraphicPromoComponent
@ComposeStory(name = "Top aligned - Sponsored")
internal fun GraphicPromoStoryTopAlignedSponsored(modifier: Modifier = Modifier) {
Column(modifier) {
BpkGraphicPromoSample(
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
sponsor = Sponsor(
accessibilityLabel = "Sponsored",
logo = "https://images.kiwi.com/airlines/64/FR.png",
title = "Sponsored",
),
)
}
}

@Composable
@GraphicPromoComponent
@ComposeStory(name = "Bottom aligned - Sponsored")
internal fun GraphicPromoStoryBottomAlignedSponsored(modifier: Modifier = Modifier) {
Column(modifier) {
BpkGraphicPromoSample(
kicker = "Travel tips",
headline = "Three Parks Challenge",
subHeadline = "How to complete the climb in 3 days",
sponsor = Sponsor(
accessibilityLabel = "Sponsored",
logo = "https://images.kiwi.com/airlines/64/FR.png",
title = "Sponsored",
),
)
}
}
Expand All @@ -102,7 +53,7 @@ internal fun BpkGraphicPromoSample(
subHeadline: String? = null,
kicker: String? = null,
verticalAlignment: VerticalAlignment = VerticalAlignment.Top,
overlayType: BpkOverlayType = BpkOverlayType.SolidHigh,
overlayType: BpkOverlayType? = null,
sponsor: Sponsor? = null,
) {
BpkGraphicPromo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fun BpkGraphicPromo(
modifier: Modifier = Modifier,
kicker: String? = null,
subHeadline: String? = null,
overlayType: BpkOverlayType = BpkOverlayType.SolidHigh,
overlayType: BpkOverlayType? = null,
variant: Variant = Variant.OnDark,
verticalAlignment: VerticalAlignment = VerticalAlignment.Top,
sponsor: Sponsor? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@ internal fun BpkGraphicPromoImpl(
modifier: Modifier = Modifier,
kicker: String? = null,
subHeadline: String? = null,
overlayType: BpkOverlayType = BpkOverlayType.SolidHigh,
overlayType: BpkOverlayType? = null,
variant: Variant = Variant.OnDark,
verticalAlignment: VerticalAlignment = VerticalAlignment.Top,
sponsor: Sponsor? = null,
sponsorLogo: @Composable () -> Unit? = {},
tapAction: () -> Unit = {},
) {
val roundedCornerShape = RoundedCornerShape(BpkBorderRadius.Sm)
val textColor: Color = when (variant) {
Variant.OnDark -> BpkTheme.colors.textOnDark
Variant.OnLight -> BpkTheme.colors.textOnLight
}

val contentDescription = listOfNotNull(kicker, headline, subHeadline, sponsor?.accessibilityLabel)
.joinToString(separator = ", ")

Expand All @@ -62,49 +57,35 @@ internal fun BpkGraphicPromoImpl(
this.contentDescription = contentDescription
},
) {
BpkOverlay(
modifier = Modifier.fillMaxSize(),
overlayType = overlayType,
foregroundContent = {
Column(modifier = Modifier.padding(BpkSpacing.Lg)) {
when (verticalAlignment) {
VerticalAlignment.Top -> {
MessageOverlay(
headline = headline,
kicker = kicker,
subHeadline = subHeadline,
textColor = textColor,
)

Spacer(Modifier.weight(1f))

SponsorOverlayView(
sponsor = sponsor,
textColor = textColor,
sponsorLogo = sponsorLogo,
)
}
VerticalAlignment.Bottom -> {
SponsorOverlayView(
sponsor = sponsor,
textColor = textColor,
sponsorLogo = sponsorLogo,
)

Spacer(Modifier.weight(1f))

MessageOverlay(
headline = headline,
kicker = kicker,
subHeadline = subHeadline,
textColor = textColor,
)
}
}
}
},
) {
overlayType?.let {
BpkOverlay(
modifier = Modifier.fillMaxSize(),
overlayType = it,
foregroundContent = {
ForegroundContent(
headline = headline,
kicker = kicker,
subHeadline = subHeadline,
variant = variant,
verticalAlignment = verticalAlignment,
sponsor = sponsor,
sponsorLogo = sponsorLogo,
)
},
) {
image()
}
} ?: run {
image()
ForegroundContent(
headline = headline,
kicker = kicker,
subHeadline = subHeadline,
variant = variant,
verticalAlignment = verticalAlignment,
sponsor = sponsor,
sponsorLogo = sponsorLogo,
)
}
}
}
Expand Down Expand Up @@ -160,5 +141,58 @@ private fun MessageOverlay(
}
}

@Composable
private fun ForegroundContent(
headline: String,
kicker: String? = null,
subHeadline: String? = null,
variant: Variant = Variant.OnDark,
verticalAlignment: VerticalAlignment = VerticalAlignment.Top,
sponsor: Sponsor? = null,
sponsorLogo: @Composable () -> Unit? = {},
) {
val textColor: Color = when (variant) {
Variant.OnDark -> BpkTheme.colors.textOnDark
Variant.OnLight -> BpkTheme.colors.textOnLight
}

Column(modifier = Modifier.padding(BpkSpacing.Lg)) {
when (verticalAlignment) {
VerticalAlignment.Top -> {
MessageOverlay(
headline = headline,
kicker = kicker,
subHeadline = subHeadline,
textColor = textColor,
)

Spacer(Modifier.weight(1f))

SponsorOverlayView(
sponsor = sponsor,
textColor = textColor,
sponsorLogo = sponsorLogo,
)
}
VerticalAlignment.Bottom -> {
SponsorOverlayView(
sponsor = sponsor,
textColor = textColor,
sponsorLogo = sponsorLogo,
)

Spacer(Modifier.weight(1f))

MessageOverlay(
headline = headline,
kicker = kicker,
subHeadline = subHeadline,
textColor = textColor,
)
}
}
}
}

const val RATIO_PORTRAIT: Float = 3 / 4f
const val SPONSOR_LOGO_HEIGHT = 60

0 comments on commit 128757c

Please sign in to comment.