Skip to content
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

Paywalls: backwards compatible blurring #1327

Merged
Next Next commit
update the code to use a blur transformation instead of a modifier
  • Loading branch information
aboedo committed Oct 18, 2023
commit 4b22c1f9e03a2696f4257e3bfbeffa609bd9493a
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.BlurredEdgeTreatment
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.blur
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
Expand All @@ -18,6 +15,10 @@ import com.revenuecat.purchases.ui.revenuecatui.extensions.defaultBackgroundPlac

@Composable
internal fun BoxScope.PaywallBackground(templateConfiguration: TemplateConfiguration) {
val transformation = if (templateConfiguration.configuration.blurredBackgroundImage)
BlurTransformation(radius = BackgroundUIConstants.blurSize, scale = BackgroundUIConstants.blurScale)
else null

val modifier = Modifier
.matchParentSize()
.conditional(templateConfiguration.configuration.blurredBackgroundImage) {
Expand All @@ -39,13 +40,16 @@ internal fun BoxScope.PaywallBackground(templateConfiguration: TemplateConfigura
urlString = it.toString(),
modifier = modifier,
contentScale = BackgroundUIConstants.contentScale,
transformation = transformation,
alpha = BackgroundUIConstants.blurAlpha
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now applying the alpha even when there's no blur.

)
}
}
}

private object BackgroundUIConstants {
val blurSize = 40.dp
// todo: make this adapt to different pixel densities
const val blurSize = 40
const val blurAlpha = 0.7f
val contentScale = ContentScale.Crop
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.revenuecat.purchases.ui.revenuecatui.composables

import BlurTransformation
import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
Expand All @@ -11,6 +12,7 @@ import coil.compose.AsyncImage
import coil.compose.AsyncImagePainter
import coil.disk.DiskCache
import coil.request.ImageRequest
import coil.transform.Transformation
import com.revenuecat.purchases.ui.revenuecatui.UIConstant
import com.revenuecat.purchases.ui.revenuecatui.helpers.Logger

Expand All @@ -20,16 +22,25 @@ internal fun RemoteImage(
modifier: Modifier = Modifier,
contentScale: ContentScale = ContentScale.Fit,
contentDescription: String? = null,
transformation: Transformation? = null,
alpha: Float = 1f
) {
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(urlString)
.crossfade(durationMillis = UIConstant.defaultAnimationDurationMillis)
.build(),

val requestBuilder = ImageRequest.Builder(LocalContext.current)
.data(urlString)
.crossfade(durationMillis = UIConstant.defaultAnimationDurationMillis)

transformation?.let {
requestBuilder.transformations(listOf(it))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this can be simplified:

.transformations(listOfNotNull(transformation))


return AsyncImage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I don't think we need the return here right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, fixed

model = requestBuilder.build(),
contentDescription = contentDescription,
imageLoader = LocalContext.current.getRevenueCatUIImageLoader(),
modifier = modifier,
contentScale = contentScale,
alpha = alpha,
onState = {
when (it) {
is AsyncImagePainter.State.Error -> {
Expand All @@ -41,6 +52,7 @@ internal fun RemoteImage(
)
}


private const val MAX_CACHE_SIZE_BYTES = 25 * 1024 * 1024L // 25 MB

@Composable
Expand Down