mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-01 08:28:08 +02:00
Add async image proxy for robohash images
This commit is contained in:
parent
b3f2a03295
commit
6403bd21f8
@ -1,6 +1,10 @@
|
||||
package com.vitorpamplona.amethyst.ui.components
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.ColorFilter
|
||||
@ -26,6 +30,48 @@ data class ResizeImage(val url: String?, val size: Dp) {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable fun AsyncUserImageProxy(
|
||||
pubkeyHex: String,
|
||||
model: ResizeImage,
|
||||
contentDescription: String?,
|
||||
modifier: Modifier = Modifier,
|
||||
alignment: Alignment = Alignment.Center,
|
||||
contentScale: ContentScale = ContentScale.Fit,
|
||||
alpha: Float = DefaultAlpha,
|
||||
colorFilter: ColorFilter? = null,
|
||||
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
|
||||
) {
|
||||
var loading by remember { mutableStateOf(false) }
|
||||
var error by remember { mutableStateOf(false) }
|
||||
|
||||
if (model.url == null || loading || error) {
|
||||
RoboHashAsyncImage(
|
||||
message = pubkeyHex,
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier,
|
||||
alignment = alignment,
|
||||
contentScale = contentScale,
|
||||
alpha = alpha,
|
||||
colorFilter = colorFilter,
|
||||
filterQuality = filterQuality,
|
||||
)
|
||||
} else {
|
||||
AsyncImage(
|
||||
model = model.proxyUrl(),
|
||||
contentDescription = contentDescription,
|
||||
modifier = modifier,
|
||||
onLoading = { loading = true },
|
||||
onSuccess = { loading = false; error = false },
|
||||
onError = { loading = false; error = true },
|
||||
alignment = alignment,
|
||||
contentScale = contentScale,
|
||||
alpha = alpha,
|
||||
colorFilter = colorFilter,
|
||||
filterQuality = filterQuality
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AsyncImageProxy(
|
||||
model: ResizeImage,
|
||||
|
Loading…
x
Reference in New Issue
Block a user