From 68c47a323879a794c9fc87903233fd418fe2edab Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Jun 2022 17:17:48 -0400 Subject: [PATCH] Minor composable updates Extracted from #7244 Co-authored-by: ivaniskandar --- .../kanade/presentation/components/AppBar.kt | 5 ---- .../presentation/components/DropdownMenu.kt | 28 +++++++++++++++++++ .../presentation/components/MangaCover.kt | 13 ++++++++- .../history/components/HistoryItem.kt | 5 ++-- .../manga/components/BaseMangaListItem.kt | 2 +- 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt diff --git a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt index 92b415d71..418a8856c 100644 --- a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt +++ b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt @@ -1,10 +1,8 @@ package eu.kanade.presentation.components import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.widthIn import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.MoreVert -import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -15,12 +13,10 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp import eu.kanade.tachiyomi.R @Composable @@ -72,7 +68,6 @@ fun AppBarActions( } DropdownMenu( - modifier = Modifier.widthIn(min = 200.dp), expanded = showMenu, onDismissRequest = { showMenu = false }, ) { diff --git a/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt b/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt new file mode 100644 index 000000000..b036fcfcf --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt @@ -0,0 +1,28 @@ +package eu.kanade.presentation.components + +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.sizeIn +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.PopupProperties +import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu + +@Composable +fun DropdownMenu( + expanded: Boolean, + onDismissRequest: () -> Unit, + modifier: Modifier = Modifier, + properties: PopupProperties = PopupProperties(focusable = true), + content: @Composable ColumnScope.() -> Unit, +) { + ComposeDropdownMenu( + expanded = expanded, + onDismissRequest = onDismissRequest, + modifier = modifier.sizeIn(minWidth = 196.dp, maxWidth = 196.dp), + offset = DpOffset(8.dp, (-8).dp), + properties = properties, + content = content, + ) +} diff --git a/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt b/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt index 0940d0a5a..4118607af 100644 --- a/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt +++ b/app/src/main/java/eu/kanade/presentation/components/MangaCover.kt @@ -1,5 +1,6 @@ package eu.kanade.presentation.components +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable @@ -9,6 +10,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.painter.ColorPainter import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import eu.kanade.presentation.util.rememberResourceBitmapPainter @@ -24,6 +26,7 @@ enum class MangaCover(val ratio: Float) { data: Any?, contentDescription: String? = null, shape: Shape? = null, + onClick: (() -> Unit)? = null, ) { AsyncImage( model = data, @@ -32,7 +35,15 @@ enum class MangaCover(val ratio: Float) { contentDescription = contentDescription, modifier = modifier .aspectRatio(ratio) - .clip(shape ?: RoundedCornerShape(4.dp)), + .clip(shape ?: RoundedCornerShape(4.dp)) + .then( + if (onClick != null) { + Modifier.clickable( + role = Role.Button, + onClick = onClick, + ) + } else Modifier, + ), contentScale = ContentScale.Crop, ) } diff --git a/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt b/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt index 23bcb71dd..1be3d22d7 100644 --- a/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt +++ b/app/src/main/java/eu/kanade/presentation/history/components/HistoryItem.kt @@ -52,10 +52,9 @@ fun HistoryItem( verticalAlignment = Alignment.CenterVertically, ) { MangaCover.Book( - modifier = Modifier - .fillMaxHeight() - .clickable(onClick = onClickCover), + modifier = Modifier.fillMaxHeight(), data = history.coverData, + onClick = onClickCover, ) Column( modifier = Modifier diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/BaseMangaListItem.kt b/app/src/main/java/eu/kanade/presentation/manga/components/BaseMangaListItem.kt index 509d3cb8a..e5c5828f8 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/BaseMangaListItem.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/BaseMangaListItem.kt @@ -45,9 +45,9 @@ private val defaultCover: @Composable RowScope.(Manga, () -> Unit) -> Unit = { m MangaCover.Square( modifier = Modifier .padding(vertical = 8.dp) - .clickable(onClick = onClick) .fillMaxHeight(), data = manga, + onClick = onClick, ) }