一些优化

This commit is contained in:
HapeLee committed 2026-05-17 21:03:25 +08:00
1 parent f4ca57f972
commit 3215adde42
3 files changed
+39 -18

No files matched your search

@@ -3,6 +3,8 @@ package io.legado.app.ui.widget.components.image.cover
import androidx.compose.animation.AnimatedVisibilityScope import androidx.compose.animation.AnimatedVisibilityScope
import androidx.compose.animation.ExperimentalSharedTransitionApi import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.SharedTransitionScope import androidx.compose.animation.SharedTransitionScope
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@@ -50,6 +52,18 @@ fun BookshelfCover(
sharedCoverKey = sharedCoverKey, sharedCoverKey = sharedCoverKey,
) )
// 使用 animatedVisibilityScope 的 animateEnterExit 为叠加层添加同步动画
val overlayModifier = Modifier.then(
if (animatedVisibilityScope != null) {
with(animatedVisibilityScope) {
Modifier.animateEnterExit(
enter = fadeIn(),
exit = fadeOut()
)
}
} else Modifier
)
if (!badgeText.isNullOrEmpty()) { if (!badgeText.isNullOrEmpty()) {
TextCard( TextCard(
text = badgeText, text = badgeText,
@@ -57,7 +71,8 @@ fun BookshelfCover(
iconSize = 12.dp, iconSize = 12.dp,
modifier = Modifier modifier = Modifier
.align(Alignment.TopEnd) .align(Alignment.TopEnd)
.padding(2.dp), .padding(2.dp)
.then(overlayModifier),
cornerRadius = 4.dp, cornerRadius = 4.dp,
horizontalPadding = 4.dp, horizontalPadding = 4.dp,
verticalPadding = 2.dp verticalPadding = 2.dp
@@ -71,7 +86,8 @@ fun BookshelfCover(
contentColor = LegadoTheme.colorScheme.onCardContainer, contentColor = LegadoTheme.colorScheme.onCardContainer,
modifier = Modifier modifier = Modifier
.align(Alignment.BottomStart) .align(Alignment.BottomStart)
.padding(2.dp), .padding(2.dp)
.then(overlayModifier),
cornerRadius = 4.dp, cornerRadius = 4.dp,
horizontalPadding = 4.dp, horizontalPadding = 4.dp,
verticalPadding = 2.dp verticalPadding = 2.dp
@@ -85,6 +101,7 @@ fun BookshelfCover(
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 4.dp, vertical = 6.dp) .padding(horizontal = 4.dp, vertical = 6.dp)
.height(3.dp) .height(3.dp)
.then(overlayModifier)
) )
} }
} }
@@ -81,6 +81,17 @@ fun CoilBookCover(
Box( Box(
modifier = modifier modifier = modifier
.aspectRatio(5f / 7f) .aspectRatio(5f / 7f)
.then(
with(sharedTransitionScope) {
if (this != null && animatedVisibilityScope != null && sharedCoverKey != null) {
Modifier.sharedElement(
sharedContentState = rememberSharedContentState(sharedCoverKey),
animatedVisibilityScope = animatedVisibilityScope,
renderInOverlayDuringTransition = true
)
} else Modifier
}
)
.then( .then(
if (CoverConfig.coverShowShadow) { if (CoverConfig.coverShowShadow) {
Modifier.shadow(4.dp, RoundedCornerShape(4.dp)) Modifier.shadow(4.dp, RoundedCornerShape(4.dp))
@@ -94,21 +105,6 @@ fun CoilBookCover(
) )
.clip(RoundedCornerShape(4.dp)) .clip(RoundedCornerShape(4.dp))
) { ) {
val imageContentModifier = Modifier
.fillMaxSize()
.then(
with(sharedTransitionScope) {
if (this != null && animatedVisibilityScope != null && sharedCoverKey != null) {
Modifier.sharedElement(
sharedContentState = rememberSharedContentState(sharedCoverKey),
animatedVisibilityScope = animatedVisibilityScope,
renderInOverlayDuringTransition = true
)
} else Modifier
}
)
Box(modifier = imageContentModifier) {
if (hasCustomDefault && !isOnlineCoverLoaded) { if (hasCustomDefault && !isOnlineCoverLoaded) {
AsyncImage( AsyncImage(
model = buildCoverImageRequest( model = buildCoverImageRequest(
@@ -117,6 +113,7 @@ fun CoilBookCover(
sourceOrigin = null, sourceOrigin = null,
loadOnlyWifi = false, loadOnlyWifi = false,
crossfade = showLoadingPlaceholder, crossfade = showLoadingPlaceholder,
memoryCacheKey = randomPath,
), ),
contentDescription = null, contentDescription = null,
imageLoader = koinInject(), imageLoader = koinInject(),
@@ -135,6 +132,7 @@ fun CoilBookCover(
sourceOrigin = sourceOrigin, sourceOrigin = sourceOrigin,
loadOnlyWifi = CoverConfig.loadCoverOnlyWifi, loadOnlyWifi = CoverConfig.loadCoverOnlyWifi,
crossfade = showLoadingPlaceholder, crossfade = showLoadingPlaceholder,
memoryCacheKey = finalPath,
), ),
contentDescription = null, contentDescription = null,
imageLoader = koinInject(), imageLoader = koinInject(),
@@ -156,7 +154,6 @@ fun CoilBookCover(
onLoadFinish?.invoke() onLoadFinish?.invoke()
} }
} }
}
if (showLoadingPlaceholder && !isOnlineCoverLoaded) { if (showLoadingPlaceholder && !isOnlineCoverLoaded) {
if (!hasCustomDefault) { if (!hasCustomDefault) {
@@ -9,11 +9,18 @@ fun buildCoverImageRequest(
sourceOrigin: String?, sourceOrigin: String?,
loadOnlyWifi: Boolean, loadOnlyWifi: Boolean,
crossfade: Boolean = true, crossfade: Boolean = true,
memoryCacheKey: String? = null,
configure: ImageRequest.Builder.() -> Unit = {}, configure: ImageRequest.Builder.() -> Unit = {},
): ImageRequest { ): ImageRequest {
return ImageRequest.Builder(context) return ImageRequest.Builder(context)
.data(data) .data(data)
.crossfade(crossfade) .crossfade(crossfade)
.apply {
if (memoryCacheKey != null) {
memoryCacheKey(memoryCacheKey)
placeholderMemoryCacheKey(memoryCacheKey)
}
}
.setParameter("sourceOrigin", sourceOrigin) .setParameter("sourceOrigin", sourceOrigin)
.setParameter("loadOnlyWifi", loadOnlyWifi) .setParameter("loadOnlyWifi", loadOnlyWifi)
.apply(configure) .apply(configure)