Simplify chapter item composable a bit

Closes #9442 because I just removed the rounding entirely...
This commit is contained in:
arkon 2023-05-26 23:02:16 -04:00
parent 152fdec855
commit 929a881943

View File

@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.sizeIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.DismissDirection import androidx.compose.material.DismissDirection
import androidx.compose.material.DismissValue import androidx.compose.material.DismissValue
import androidx.compose.material.SwipeToDismiss import androidx.compose.material.SwipeToDismiss
@ -26,8 +25,6 @@ import androidx.compose.material.icons.filled.FileDownloadOff
import androidx.compose.material.icons.filled.Visibility import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material.rememberDismissState import androidx.compose.material.rememberDismissState
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.LocalContentColor import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
@ -55,7 +52,6 @@ import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.presentation.core.components.material.ReadItemAlpha import tachiyomi.presentation.core.components.material.ReadItemAlpha
import tachiyomi.presentation.core.components.material.SecondaryItemAlpha import tachiyomi.presentation.core.components.material.SecondaryItemAlpha
import tachiyomi.presentation.core.util.selectedBackground import tachiyomi.presentation.core.util.selectedBackground
import kotlin.math.min
@Composable @Composable
fun MangaChapterListItem( fun MangaChapterListItem(
@ -102,6 +98,15 @@ fun MangaChapterListItem(
lastDismissDirection = null lastDismissDirection = null
}, },
) )
val dismissContentAlpha = if (lastDismissDirection != null) animateDismissContentAlpha else 1f
val backgroundColor = if (chapterSwipeEndEnabled && (dismissState.dismissDirection == DismissDirection.StartToEnd || lastDismissDirection == DismissDirection.StartToEnd)) {
MaterialTheme.colorScheme.primary
} else if (chapterSwipeStartEnabled && (dismissState.dismissDirection == DismissDirection.EndToStart || lastDismissDirection == DismissDirection.EndToStart)) {
MaterialTheme.colorScheme.primary
} else {
Color.Unspecified
}
LaunchedEffect(dismissState.currentValue) { LaunchedEffect(dismissState.currentValue) {
when (dismissState.currentValue) { when (dismissState.currentValue) {
DismissValue.DismissedToEnd -> { DismissValue.DismissedToEnd -> {
@ -123,17 +128,11 @@ fun MangaChapterListItem(
DismissValue.Default -> { } DismissValue.Default -> { }
} }
} }
SwipeToDismiss( SwipeToDismiss(
state = dismissState, state = dismissState,
directions = dismissDirections, directions = dismissDirections,
background = { background = {
val backgroundColor = if (chapterSwipeEndEnabled && (dismissState.dismissDirection == DismissDirection.StartToEnd || lastDismissDirection == DismissDirection.StartToEnd)) {
MaterialTheme.colorScheme.primary
} else if (chapterSwipeStartEnabled && (dismissState.dismissDirection == DismissDirection.EndToStart || lastDismissDirection == DismissDirection.EndToStart)) {
MaterialTheme.colorScheme.primary
} else {
Color.Unspecified
}
Box( Box(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -171,26 +170,8 @@ fun MangaChapterListItem(
} }
}, },
dismissContent = { dismissContent = {
val animateCornerRatio = if (dismissState.offset.value != 0f) {
min(
dismissState.progress.fraction / .075f,
1f,
)
} else {
0f
}
val animateCornerShape = (8f * animateCornerRatio).dp
val dismissContentAlpha =
if (lastDismissDirection != null) animateDismissContentAlpha else 1f
Card(
modifier = modifier,
colors = CardDefaults.elevatedCardColors(
containerColor = Color.Transparent,
),
shape = RoundedCornerShape(animateCornerShape),
) {
Row( Row(
modifier = Modifier modifier = modifier
.background( .background(
MaterialTheme.colorScheme.background.copy(dismissContentAlpha), MaterialTheme.colorScheme.background.copy(dismissContentAlpha),
) )
@ -285,7 +266,6 @@ fun MangaChapterListItem(
) )
} }
} }
}
}, },
) )
} }