From 8b6c35826654ac085b7c7b2a8994a01a95389322 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sat, 16 Nov 2024 18:44:54 +0800 Subject: [PATCH] Avoid consuming click event if the image is loaded --- .../hippo/ehviewer/ui/main/EhAsyncThumb.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/EhAsyncThumb.kt b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/EhAsyncThumb.kt index bff3a9431..9a8f715cb 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/ui/main/EhAsyncThumb.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/ui/main/EhAsyncThumb.kt @@ -2,11 +2,13 @@ package com.hippo.ehviewer.ui.main import androidx.compose.animation.SharedTransitionScope import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.Card import androidx.compose.material3.ShapeDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.NonRestartableComposable +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -28,6 +30,7 @@ import com.hippo.ehviewer.ui.tools.SETNodeGenerator import com.hippo.ehviewer.ui.tools.TransitionsVisibilityScope import com.hippo.ehviewer.ui.tools.sharedBounds import com.hippo.ehviewer.ui.tools.shouldCrop +import com.hippo.ehviewer.ui.tools.thenIf @Composable @NonRestartableComposable @@ -108,18 +111,17 @@ fun EhThumbCard( } }, ) - Card( - onClick = { - if (painter.state.value is AsyncImagePainter.State.Error) { - painter.restart() - } - }, - modifier = modifier, - ) { + val state by painter.state.collectAsState() + Card(modifier = modifier) { Image( painter = painter, contentDescription = null, - modifier = Modifier.imageRequest(request).fillMaxSize().sharedBounds(key = "${key.gid}").clip(ShapeDefaults.Medium), + modifier = Modifier.thenIf(state !is AsyncImagePainter.State.Success) { + // Keep applying this when state is `Loading` to avoid cutting off the ripple + clickable { + if (state is AsyncImagePainter.State.Error) painter.restart() + } + }.imageRequest(request).fillMaxSize().sharedBounds(key = "${key.gid}").clip(ShapeDefaults.Medium), contentScale = contentScale, ) }