Skip to content

Commit

Permalink
[Paywalls V2] Cleans up after implementing color aliases (#2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayShortway authored Jan 27, 2025
1 parent 0ee7cf6 commit 55cda3b
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.revenuecat.purchases.paywalls.components.properties.Border
import com.revenuecat.purchases.paywalls.components.properties.ColorInfo
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme
import com.revenuecat.purchases.ui.revenuecatui.components.properties.BorderStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.rememberBorderStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toColorStyle

@JvmSynthetic
@Stable
Expand Down Expand Up @@ -118,29 +116,25 @@ private fun Border_Preview_LinearGradient(shape: Shape) {
.requiredSize(100.dp)
.background(Color.Red)
.border(
border = rememberBorderStyle(
Border(
width = 10.0,
color = ColorScheme(
light = ColorInfo.Gradient.Linear(
degrees = -45f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Cyan.toArgb(),
percent = 10f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0x00, green = 0x66, blue = 0xff).toArgb(),
percent = 30f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0xA0, green = 0x00, blue = 0xA0).toArgb(),
percent = 80f,
),
),
border = BorderStyle(
width = 10.dp,
color = ColorInfo.Gradient.Linear(
degrees = -45f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Cyan.toArgb(),
percent = 10f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0x00, green = 0x66, blue = 0xff).toArgb(),
percent = 30f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0xA0, green = 0x00, blue = 0xA0).toArgb(),
percent = 80f,
),
),
),
).toColorStyle(),
),
shape = shape,
),
Expand All @@ -155,28 +149,24 @@ private fun Border_Preview_RadialGradient(shape: Shape) {
.requiredSize(100.dp)
.background(Color.Red)
.border(
border = rememberBorderStyle(
Border(
width = 10.0,
color = ColorScheme(
light = ColorInfo.Gradient.Radial(
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Cyan.toArgb(),
percent = 80f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0x00, green = 0x66, blue = 0xff).toArgb(),
percent = 90f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0xA0, green = 0x00, blue = 0xA0).toArgb(),
percent = 96f,
),
),
border = BorderStyle(
width = 10.dp,
color = ColorInfo.Gradient.Radial(
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Cyan.toArgb(),
percent = 80f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0x00, green = 0x66, blue = 0xff).toArgb(),
percent = 90f,
),
ColorInfo.Gradient.Point(
color = Color(red = 0xA0, green = 0x00, blue = 0xA0).toArgb(),
percent = 96f,
),
),
),
).toColorStyle(),
),
shape = shape,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.revenuecat.purchases.paywalls.components.properties.ColorInfo
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme
import com.revenuecat.purchases.paywalls.components.properties.Shadow
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ShadowStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.rememberShadowStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toColorStyle

@JvmSynthetic
@Stable
Expand Down Expand Up @@ -87,15 +85,11 @@ private fun Shadow_Preview_Circle() {
modifier = Modifier
.requiredSize(100.dp)
.shadow(
shadow = rememberShadowStyle(
Shadow(
color = ColorScheme(
light = ColorInfo.Hex(Color.Black.toArgb()),
),
x = 5.0,
y = 5.0,
radius = 0.0,
),
shadow = ShadowStyle(
color = ColorStyle.Solid(Color.Black),
x = 5.dp,
y = 5.dp,
radius = 0.dp,
),
shape = shape,
)
Expand All @@ -118,15 +112,11 @@ private fun Shadow_Preview_Square() {
modifier = Modifier
.requiredSize(100.dp)
.shadow(
shadow = rememberShadowStyle(
Shadow(
color = ColorScheme(
light = ColorInfo.Hex(Color.Black.toArgb()),
),
x = 10.0,
y = 5.0,
radius = 20.0,
),
shadow = ShadowStyle(
color = ColorStyle.Solid(Color.Black),
x = 10.dp,
y = 5.dp,
radius = 20.dp,
),
shape = shape,
)
Expand All @@ -149,31 +139,27 @@ private fun Shadow_Preview_Gradient_CustomShape() {
text = "GET UNLIMITED RGB",
modifier = Modifier
.shadow(
shadow = rememberShadowStyle(
Shadow(
color = ColorScheme(
light = ColorInfo.Gradient.Linear(
degrees = 0f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Red.toArgb(),
percent = 10f,
),
ColorInfo.Gradient.Point(
color = Color.Green.toArgb(),
percent = 50f,
),
ColorInfo.Gradient.Point(
color = Color.Blue.toArgb(),
percent = 90f,
),
),
shadow = ShadowStyle(
color = ColorInfo.Gradient.Linear(
degrees = 0f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Red.toArgb(),
percent = 10f,
),
ColorInfo.Gradient.Point(
color = Color.Green.toArgb(),
percent = 50f,
),
ColorInfo.Gradient.Point(
color = Color.Blue.toArgb(),
percent = 90f,
),
),
x = 0.0,
y = 6.0,
radius = 9.5,
),
).toColorStyle(),
x = 0.dp,
y = 6.dp,
radius = 9.5.dp,
),
shape = shape,
)
Expand Down Expand Up @@ -202,15 +188,11 @@ private fun Shadow_Preview_Margin() {
.padding(margin)
.requiredSize(width = 50.dp, height = 50.dp)
.shadow(
shadow = rememberShadowStyle(
Shadow(
color = ColorScheme(
light = ColorInfo.Hex(Color.Black.toArgb()),
),
x = 0.0,
y = 5.0,
radius = 20.0,
),
shadow = ShadowStyle(
color = ColorStyle.Solid(Color.Black),
x = 0.dp,
y = 5.dp,
radius = 20.dp,
),
shape = shape,
)
Expand All @@ -224,15 +206,11 @@ private fun Shadow_Preview_Margin() {
.padding(margin)
.requiredSize(width = 50.dp, height = 50.dp)
.shadow(
shadow = rememberShadowStyle(
Shadow(
color = ColorScheme(
light = ColorInfo.Hex(Color.Black.toArgb()),
),
x = 0.0,
y = 5.0,
radius = 20.0,
),
shadow = ShadowStyle(
color = ColorStyle.Solid(Color.Black),
x = 0.dp,
y = 5.dp,
radius = 20.dp,
),
shape = shape,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,6 @@ internal fun rememberBackgroundStyle(background: BackgroundStyles): BackgroundSt
}
}

@JvmSynthetic
@Composable
internal fun Background.toBackgroundStyle(): BackgroundStyle =
when (this) {
is Background.Color -> BackgroundStyle.Color(color = value.toColorStyle())
is Background.Image -> {
val imageUrls = value.urlsForCurrentTheme
val contentScale = fitMode.toContentScale()
BackgroundStyle.Image(
painter = rememberAsyncImagePainter(
model = imageUrls.webp.toString(),
placeholder = rememberAsyncImagePainter(
model = imageUrls.webpLowRes.toString(),
error = null,
fallback = null,
contentScale = contentScale,
),
error = null,
fallback = null,
contentScale = contentScale,
),
contentScale = contentScale,
colorOverlay = colorOverlay?.toColorStyle(),
)
}
}

@Composable
private fun rememberAsyncImagePainter(imageUrls: ImageUrls, contentScale: ContentScale): AsyncImagePainter =
rememberAsyncImagePainter(
Expand All @@ -151,13 +124,7 @@ private fun Background_Preview_ColorHex() {
Box(
modifier = Modifier
.requiredSize(100.dp)
.background(
Background.Color(
ColorScheme(
light = ColorInfo.Hex(Color.Red.toArgb()),
),
).toBackgroundStyle(),
),
.background(BackgroundStyle.Color(ColorStyle.Solid(Color.Red))),
)
}

Expand All @@ -168,27 +135,25 @@ private fun Background_Preview_ColorGradientLinear() {
modifier = Modifier
.requiredSize(100.dp)
.background(
Background.Color(
ColorScheme(
light = ColorInfo.Gradient.Linear(
degrees = 0f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Red.toArgb(),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.Green.toArgb(),
percent = 50f,
),
ColorInfo.Gradient.Point(
color = Color.Blue.toArgb(),
percent = 100f,
),
BackgroundStyle.Color(
ColorInfo.Gradient.Linear(
degrees = 0f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Red.toArgb(),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.Green.toArgb(),
percent = 50f,
),
ColorInfo.Gradient.Point(
color = Color.Blue.toArgb(),
percent = 100f,
),
),
),
).toBackgroundStyle(),
).toColorStyle(),
),
),
)
}
Expand All @@ -200,26 +165,24 @@ private fun Background_Preview_ColorGradientRadial() {
modifier = Modifier
.requiredSize(100.dp)
.background(
Background.Color(
ColorScheme(
light = ColorInfo.Gradient.Radial(
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Red.toArgb(),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.Green.toArgb(),
percent = 50f,
),
ColorInfo.Gradient.Point(
color = Color.Blue.toArgb(),
percent = 100f,
),
BackgroundStyle.Color(
ColorInfo.Gradient.Radial(
points = listOf(
ColorInfo.Gradient.Point(
color = Color.Red.toArgb(),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.Green.toArgb(),
percent = 50f,
),
ColorInfo.Gradient.Point(
color = Color.Blue.toArgb(),
percent = 100f,
),
),
),
).toBackgroundStyle(),
).toColorStyle(),
),
),
)
}
Expand Down
Loading

0 comments on commit 55cda3b

Please sign in to comment.