From bcfdcd649624cba1e6f3f7287bd5cdb3dd664cfa Mon Sep 17 00:00:00 2001 From: Infi Date: Sat, 21 Dec 2024 21:21:36 +0100 Subject: [PATCH] fix: continue not to animate avatars Signed-off-by: Infi --- .../revolt/components/generic/RemoteImage.kt | 18 +++++++++++------- .../revolt/components/generic/UserAvatar.kt | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/chat/revolt/components/generic/RemoteImage.kt b/app/src/main/java/chat/revolt/components/generic/RemoteImage.kt index 2f130bbf..0829699d 100644 --- a/app/src/main/java/chat/revolt/components/generic/RemoteImage.kt +++ b/app/src/main/java/chat/revolt/components/generic/RemoteImage.kt @@ -21,17 +21,18 @@ fun RemoteImage( modifier: Modifier = Modifier, contentScale: ContentScale = ContentScale.Crop, width: Int = 0, - height: Int = 0 + height: Int = 0, + allowAnimation: Boolean = true ) { val context = LocalContext.current fun pxAsDp(px: Int): Dp { return ( - px / ( - context.resources - .displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT - ) - ).dp + px / ( + context.resources + .displayMetrics.densityDpi.toFloat() / DisplayMetrics.DENSITY_DEFAULT + ) + ).dp } GlideImage( @@ -41,6 +42,9 @@ fun RemoteImage( modifier = modifier .width(pxAsDp(width)) .height(pxAsDp(height)), - transition = CrossFade + transition = CrossFade, + requestBuilderTransform = { rb -> + if (!allowAnimation) rb.dontAnimate() else rb + } ) } diff --git a/app/src/main/java/chat/revolt/components/generic/UserAvatar.kt b/app/src/main/java/chat/revolt/components/generic/UserAvatar.kt index 1a8ab1c5..c8b7e899 100644 --- a/app/src/main/java/chat/revolt/components/generic/UserAvatar.kt +++ b/app/src/main/java/chat/revolt/components/generic/UserAvatar.kt @@ -91,6 +91,7 @@ fun UserAvatar( size: Dp = 40.dp, presenceSize: Dp = 16.dp, shape: Shape = RoundedCornerShape(LoadedSettings.avatarRadius), + allowAnimation: Boolean = false, onLongClick: (() -> Unit)? = null, onClick: (() -> Unit)? = null ) { @@ -104,6 +105,7 @@ fun UserAvatar( url = rawUrl ?: "$REVOLT_FILES/avatars/${avatar.id}", contentScale = ContentScale.Crop, description = stringResource(id = R.string.avatar_alt, username), + allowAnimation = allowAnimation, modifier = Modifier .clip(shape) .size(size) @@ -123,6 +125,7 @@ fun UserAvatar( RemoteImage( url = "$REVOLT_BASE/users/${userId.ifBlank { "0".repeat(26) }}/default_avatar", description = stringResource(id = R.string.avatar_alt, username), + allowAnimation = allowAnimation, modifier = Modifier .clip(shape) .size(size)