mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: .conditional extension method for Modifier
Also slightly adjust cover's shape
This commit is contained in:
parent
26021b2ad0
commit
8391a25ef4
2 changed files with 20 additions and 14 deletions
|
@ -19,6 +19,7 @@ import androidx.compose.ui.unit.dp
|
||||||
import coil3.compose.AsyncImage
|
import coil3.compose.AsyncImage
|
||||||
import coil3.compose.AsyncImagePainter
|
import coil3.compose.AsyncImagePainter
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import yokai.util.conditional
|
||||||
import yokai.util.rememberResourceBitmapPainter
|
import yokai.util.rememberResourceBitmapPainter
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -30,7 +31,7 @@ fun MangaCover(
|
||||||
minimumHeight: (() -> Int)? = null,
|
minimumHeight: (() -> Int)? = null,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentDescription: String = "",
|
contentDescription: String = "",
|
||||||
shape: Shape = MaterialTheme.shapes.extraSmall,
|
shape: Shape = MaterialTheme.shapes.small,
|
||||||
contentScale: () -> ContentScale = { ContentScale.Crop },
|
contentScale: () -> ContentScale = { ContentScale.Crop },
|
||||||
onClick: (() -> Unit)? = null,
|
onClick: (() -> Unit)? = null,
|
||||||
onLoading: ((AsyncImagePainter.State.Loading) -> Unit)? = null,
|
onLoading: ((AsyncImagePainter.State.Loading) -> Unit)? = null,
|
||||||
|
@ -45,30 +46,24 @@ fun MangaCover(
|
||||||
maximumHeightDp = maximumHeight?.let { it().toDp() } ?: Dp.Unspecified
|
maximumHeightDp = maximumHeight?.let { it().toDp() } ?: Dp.Unspecified
|
||||||
}
|
}
|
||||||
|
|
||||||
val ratioModifier = if (adjustViewBounds()) Modifier.aspectRatio(ratio()) else Modifier
|
|
||||||
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = data,
|
model = data,
|
||||||
placeholder = ColorPainter(CoverPlaceholderColor),
|
placeholder = ColorPainter(CoverPlaceholderColor),
|
||||||
error = rememberResourceBitmapPainter(id = R.drawable.ic_broken_image_24dp),
|
error = rememberResourceBitmapPainter(id = R.drawable.ic_broken_image_24dp),
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.then(ratioModifier)
|
.conditional(adjustViewBounds()) { aspectRatio(ratio()) }
|
||||||
.clip(shape)
|
.clip(shape)
|
||||||
.heightIn(
|
.heightIn(
|
||||||
min = minimumHeightDp,
|
min = minimumHeightDp,
|
||||||
max = maximumHeightDp,
|
max = maximumHeightDp,
|
||||||
)
|
)
|
||||||
.then(
|
.conditional(onClick != null) {
|
||||||
if (onClick != null) {
|
clickable(
|
||||||
Modifier.clickable(
|
|
||||||
role = Role.Button,
|
role = Role.Button,
|
||||||
onClick = onClick,
|
onClick = onClick!!,
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
},
|
},
|
||||||
),
|
|
||||||
contentScale = contentScale(),
|
contentScale = contentScale(),
|
||||||
onLoading = onLoading,
|
onLoading = onLoading,
|
||||||
onError = onError,
|
onError = onError,
|
||||||
|
|
11
app/src/main/java/yokai/util/Modifier.kt
Normal file
11
app/src/main/java/yokai/util/Modifier.kt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package yokai.util
|
||||||
|
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
fun Modifier.conditional(condition: Boolean, modifier: Modifier.() -> Modifier): Modifier {
|
||||||
|
return if (condition) {
|
||||||
|
modifier(this)
|
||||||
|
} else {
|
||||||
|
this
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue