Skip to content

Migrates to Coil 3 #2028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ material = "1.6.0"
adsIdentifier = "17.0.1"
viewmodelCompose = "2.4.0"
paparrazzi = "1.3.1"
coil = "2.4.0"
coil = "3.0.4"
window = "1.1.0"
commonmark = "0.21.0"
activity-compose = "1.9.3"
Expand Down Expand Up @@ -140,9 +140,9 @@ compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
window = { module = "androidx.window:window", version.ref = "window" }
window-core = { module = "androidx.window:window-core", version.ref = "window" }

coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
coil-svg = { module = "io.coil-kt:coil-svg", version.ref = "coil" }
coil-test = { module = "io.coil-kt:coil-test", version.ref = "coil" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil" }
coil-test = { module = "io.coil-kt.coil3:coil-test", version.ref = "coil" }

commonmark = { module = "org.commonmark:commonmark", version.ref = "commonmark" }
commonmark-strikethrough = { module = "org.commonmark:commonmark-ext-gfm-strikethrough", version.ref = "commonmark" }
Expand Down
2 changes: 1 addition & 1 deletion purchases/consumer-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.Immutable
-dontwarn com.amazon.**
-dontwarn coil.**
-dontwarn coil3.**
# Adding temporarily to fix issue after adding kotlin serialization
-dontwarn java.lang.ClassValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.revenuecat.purchases.utils

import android.content.Context
import android.net.Uri
import coil.ImageLoader
import coil.disk.DiskCache
import coil.request.ImageRequest
import coil3.ImageLoader
import coil3.disk.DiskCache
import coil3.disk.directory
import coil3.request.ImageRequest

// Note: these values have to match those in RemoteImage
private const val MAX_CACHE_SIZE_BYTES = 25 * 1024 * 1024L // 25 MB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import coil3.annotation.ExperimentalCoilApi
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.PackageType
Expand All @@ -32,6 +33,7 @@ import com.revenuecat.purchases.ui.revenuecatui.data.processed.PaywallTemplate
import com.revenuecat.purchases.ui.revenuecatui.data.processed.TemplateConfiguration
import com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableDataProvider
import com.revenuecat.purchases.ui.revenuecatui.extensions.createDefault
import com.revenuecat.purchases.ui.revenuecatui.helpers.PreviewImagesAsPrimaryColor
import com.revenuecat.purchases.ui.revenuecatui.helpers.ResourceProvider
import com.revenuecat.purchases.ui.revenuecatui.helpers.isInPreviewMode
import com.revenuecat.purchases.ui.revenuecatui.helpers.toLegacyPaywallState
Expand Down Expand Up @@ -212,12 +214,15 @@ private class LoadingViewModel(
}
}

@OptIn(ExperimentalCoilApi::class)
@Preview(showBackground = true)
@Composable
internal fun LoadingPaywallPreview() {
LoadingPaywall(
mode = PaywallMode.FULL_SCREEN,
shouldDisplayDismissButton = false,
onDismiss = {},
)
PreviewImagesAsPrimaryColor {
LoadingPaywall(
mode = PaywallMode.FULL_SCREEN,
shouldDisplayDismissButton = false,
onDismiss = {},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil3.annotation.ExperimentalCoilApi
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.paywalls.components.StackComponent
import com.revenuecat.purchases.paywalls.components.common.Background
Expand All @@ -40,6 +41,7 @@ import com.revenuecat.purchases.ui.revenuecatui.components.style.ImageComponentS
import com.revenuecat.purchases.ui.revenuecatui.composables.RemoteImage
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallState
import com.revenuecat.purchases.ui.revenuecatui.extensions.applyIfNotNull
import com.revenuecat.purchases.ui.revenuecatui.helpers.PreviewImagesAsDrawableResource
import com.revenuecat.purchases.ui.revenuecatui.helpers.getOrThrow
import com.revenuecat.purchases.ui.revenuecatui.helpers.nonEmptyMapOf
import com.revenuecat.purchases.ui.revenuecatui.helpers.toComponentsPaywallState
Expand Down Expand Up @@ -72,121 +74,138 @@ internal fun ImageComponentView(
.applyIfNotNull(imageState.shape) { clip(it) },
placeholderUrlString = imageState.imageUrls.webpLowRes.toString(),
contentScale = imageState.contentScale,
imagePreview = R.drawable.android,
)
}
}

@OptIn(ExperimentalCoilApi::class)
@Preview
@Composable
private fun ImageComponentView_Preview_Default() {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(),
state = previewEmptyState(),
)
PreviewImagesAsDrawableResource(R.drawable.android) {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(),
state = previewEmptyState(),
)
}
}
}

@OptIn(ExperimentalCoilApi::class)
@Preview
@Composable
private fun ImageComponentView_Preview_FixedWidthFitHeight() {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
size = Size(width = SizeConstraint.Fixed(72u), height = SizeConstraint.Fit),
contentScale = FitMode.FILL.toContentScale(),
),
state = previewEmptyState(),
)
PreviewImagesAsDrawableResource(R.drawable.android) {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
size = Size(width = SizeConstraint.Fixed(72u), height = SizeConstraint.Fit),
contentScale = FitMode.FILL.toContentScale(),
),
state = previewEmptyState(),
)
}
}
}

@OptIn(ExperimentalCoilApi::class)
@Preview
@Composable
private fun ImageComponentView_Preview_FitWidthFixedHeight() {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
size = Size(width = SizeConstraint.Fit, height = SizeConstraint.Fixed(72u)),
contentScale = FitMode.FILL.toContentScale(),
),
state = previewEmptyState(),
)
PreviewImagesAsDrawableResource(R.drawable.android) {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
size = Size(width = SizeConstraint.Fit, height = SizeConstraint.Fixed(72u)),
contentScale = FitMode.FILL.toContentScale(),
),
state = previewEmptyState(),
)
}
}
}

@OptIn(ExperimentalCoilApi::class)
@Preview
@Composable
private fun ImageComponentView_Preview_SmallerContainer() {
Box(modifier = Modifier.height(200.dp).background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(),
state = previewEmptyState(),
)
PreviewImagesAsDrawableResource(R.drawable.android) {
Box(modifier = Modifier.height(200.dp).background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(),
state = previewEmptyState(),
)
}
}
}

@OptIn(ExperimentalCoilApi::class)
@Suppress("MagicNumber")
@Preview
@Composable
private fun ImageComponentView_Preview_LinearGradient() {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
overlay = ColorScheme(
light = ColorInfo.Gradient.Linear(
degrees = -90f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.parseColor("#88FF0000"),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#8800FF00"),
percent = 0.5f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#880000FF"),
percent = 1f,
PreviewImagesAsDrawableResource(R.drawable.android) {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
overlay = ColorScheme(
light = ColorInfo.Gradient.Linear(
degrees = -90f,
points = listOf(
ColorInfo.Gradient.Point(
color = Color.parseColor("#88FF0000"),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#8800FF00"),
percent = 0.5f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#880000FF"),
percent = 1f,
),
),
),
),
),
),
state = previewEmptyState(),
)
state = previewEmptyState(),
)
}
}
}

@OptIn(ExperimentalCoilApi::class)
@Suppress("MagicNumber")
@Preview
@Composable
private fun ImageComponentView_Preview_RadialGradient() {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
overlay = ColorScheme(
light = ColorInfo.Gradient.Radial(
listOf(
ColorInfo.Gradient.Point(
color = Color.parseColor("#88FF0000"),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#8800FF00"),
percent = 0.5f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#880000FF"),
percent = 1f,
PreviewImagesAsDrawableResource(R.drawable.android) {
Box(modifier = Modifier.background(ComposeColor.Red)) {
ImageComponentView(
style = previewImageComponentStyle(
overlay = ColorScheme(
light = ColorInfo.Gradient.Radial(
listOf(
ColorInfo.Gradient.Point(
color = Color.parseColor("#88FF0000"),
percent = 0f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#8800FF00"),
percent = 0.5f,
),
ColorInfo.Gradient.Point(
color = Color.parseColor("#880000FF"),
percent = 1f,
),
),
),
),
),
),
state = previewEmptyState(),
)
state = previewEmptyState(),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.rememberAsyncImagePainter
import coil3.compose.rememberAsyncImagePainter
import com.revenuecat.purchases.paywalls.components.common.Background
import com.revenuecat.purchases.paywalls.components.properties.ColorInfo
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme
Expand Down
Loading