Minor composable updates

Extracted from #7244

Co-authored-by: ivaniskandar <ivaniskandar@users.noreply.github.com>
This commit is contained in:
arkon 2022-06-19 17:17:48 -04:00
parent e644772731
commit 68c47a3238
5 changed files with 43 additions and 10 deletions

View file

@ -1,10 +1,8 @@
package eu.kanade.presentation.components package eu.kanade.presentation.components
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
@ -15,12 +13,10 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@Composable @Composable
@ -72,7 +68,6 @@ fun AppBarActions(
} }
DropdownMenu( DropdownMenu(
modifier = Modifier.widthIn(min = 200.dp),
expanded = showMenu, expanded = showMenu,
onDismissRequest = { showMenu = false }, onDismissRequest = { showMenu = false },
) { ) {

View file

@ -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,
)
}

View file

@ -1,5 +1,6 @@
package eu.kanade.presentation.components package eu.kanade.presentation.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable 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.Shape
import androidx.compose.ui.graphics.painter.ColorPainter import androidx.compose.ui.graphics.painter.ColorPainter
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage import coil.compose.AsyncImage
import eu.kanade.presentation.util.rememberResourceBitmapPainter import eu.kanade.presentation.util.rememberResourceBitmapPainter
@ -24,6 +26,7 @@ enum class MangaCover(val ratio: Float) {
data: Any?, data: Any?,
contentDescription: String? = null, contentDescription: String? = null,
shape: Shape? = null, shape: Shape? = null,
onClick: (() -> Unit)? = null,
) { ) {
AsyncImage( AsyncImage(
model = data, model = data,
@ -32,7 +35,15 @@ enum class MangaCover(val ratio: Float) {
contentDescription = contentDescription, contentDescription = contentDescription,
modifier = modifier modifier = modifier
.aspectRatio(ratio) .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, contentScale = ContentScale.Crop,
) )
} }

View file

@ -52,10 +52,9 @@ fun HistoryItem(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
MangaCover.Book( MangaCover.Book(
modifier = Modifier modifier = Modifier.fillMaxHeight(),
.fillMaxHeight()
.clickable(onClick = onClickCover),
data = history.coverData, data = history.coverData,
onClick = onClickCover,
) )
Column( Column(
modifier = Modifier modifier = Modifier

View file

@ -45,9 +45,9 @@ private val defaultCover: @Composable RowScope.(Manga, () -> Unit) -> Unit = { m
MangaCover.Square( MangaCover.Square(
modifier = Modifier modifier = Modifier
.padding(vertical = 8.dp) .padding(vertical = 8.dp)
.clickable(onClick = onClick)
.fillMaxHeight(), .fillMaxHeight(),
data = manga, data = manga,
onClick = onClick,
) )
} }