fix: continue not to animate avatars

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-12-21 21:21:36 +01:00
parent 872940900a
commit bcfdcd6496
2 changed files with 14 additions and 7 deletions

View File

@ -21,17 +21,18 @@ fun RemoteImage(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
contentScale: ContentScale = ContentScale.Crop, contentScale: ContentScale = ContentScale.Crop,
width: Int = 0, width: Int = 0,
height: Int = 0 height: Int = 0,
allowAnimation: Boolean = true
) { ) {
val context = LocalContext.current val context = LocalContext.current
fun pxAsDp(px: Int): Dp { fun pxAsDp(px: Int): Dp {
return ( return (
px / ( px / (
context.resources context.resources
.displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT .displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT
) )
).dp ).dp
} }
GlideImage( GlideImage(
@ -41,6 +42,9 @@ fun RemoteImage(
modifier = modifier modifier = modifier
.width(pxAsDp(width)) .width(pxAsDp(width))
.height(pxAsDp(height)), .height(pxAsDp(height)),
transition = CrossFade transition = CrossFade,
requestBuilderTransform = { rb ->
if (!allowAnimation) rb.dontAnimate() else rb
}
) )
} }

View File

@ -91,6 +91,7 @@ fun UserAvatar(
size: Dp = 40.dp, size: Dp = 40.dp,
presenceSize: Dp = 16.dp, presenceSize: Dp = 16.dp,
shape: Shape = RoundedCornerShape(LoadedSettings.avatarRadius), shape: Shape = RoundedCornerShape(LoadedSettings.avatarRadius),
allowAnimation: Boolean = false,
onLongClick: (() -> Unit)? = null, onLongClick: (() -> Unit)? = null,
onClick: (() -> Unit)? = null onClick: (() -> Unit)? = null
) { ) {
@ -104,6 +105,7 @@ fun UserAvatar(
url = rawUrl ?: "$REVOLT_FILES/avatars/${avatar.id}", url = rawUrl ?: "$REVOLT_FILES/avatars/${avatar.id}",
contentScale = ContentScale.Crop, contentScale = ContentScale.Crop,
description = stringResource(id = R.string.avatar_alt, username), description = stringResource(id = R.string.avatar_alt, username),
allowAnimation = allowAnimation,
modifier = Modifier modifier = Modifier
.clip(shape) .clip(shape)
.size(size) .size(size)
@ -123,6 +125,7 @@ fun UserAvatar(
RemoteImage( RemoteImage(
url = "$REVOLT_BASE/users/${userId.ifBlank { "0".repeat(26) }}/default_avatar", url = "$REVOLT_BASE/users/${userId.ifBlank { "0".repeat(26) }}/default_avatar",
description = stringResource(id = R.string.avatar_alt, username), description = stringResource(id = R.string.avatar_alt, username),
allowAnimation = allowAnimation,
modifier = Modifier modifier = Modifier
.clip(shape) .clip(shape)
.size(size) .size(size)