[fix] Cover height meansure

This commit is contained in:
acite
2025-10-02 01:20:13 +08:00
parent 2c4d5d2366
commit db8d5ef4d5
3 changed files with 107 additions and 105 deletions

View File

@@ -95,9 +95,10 @@ fun ComicGridView(
} }
} }
LaunchedEffect(Unit) { LaunchedEffect(comicGridViewModel) {
comicGridViewModel.coverHeight = screenHeight * 0.4f comicGridViewModel.coverHeight = screenHeight * 0.4f
comicGridViewModel.maxHeight = screenHeight * 0.8f if(comicGridViewModel.maxHeight == 0.dp)
comicGridViewModel.maxHeight = screenHeight * 0.8f
} }
val dens = LocalDensity.current val dens = LocalDensity.current

View File

@@ -5,10 +5,12 @@ import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@@ -36,7 +38,9 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView import androidx.compose.ui.platform.LocalView
@@ -92,13 +96,17 @@ fun ComicPageView(
.fillMaxSize() .fillMaxSize()
.align(Alignment.Center) .align(Alignment.Center)
.background(Color.Black) .background(Color.Black)
.clickable { .pointerInput(Unit) {
showPlane = !showPlane detectTapGestures(
if (showPlane) { onTap = {
comicPageViewModel.viewModelScope.launch { showPlane = !showPlane
comicPageViewModel.listState?.scrollToItem(index = pagerState.currentPage) if (showPlane) {
comicPageViewModel.viewModelScope.launch {
comicPageViewModel.listState?.scrollToItem(index = pagerState.currentPage)
}
}
} }
} )
} }
) { page -> ) { page ->
AsyncImage( AsyncImage(
@@ -123,110 +131,103 @@ fun ComicPageView(
modifier = Modifier modifier = Modifier
.align(Alignment.TopCenter) .align(Alignment.TopCenter)
) { ) {
Box() Column(Modifier
{ .align(Alignment.TopCenter)
Column(Modifier .fillMaxWidth()
.align(Alignment.TopCenter) .background(
.fillMaxWidth()) brush = Brush.verticalGradient(
{ colors = listOf(
Card( Color.Black.copy(alpha = 0.9f),
colors = CardDefaults.cardColors(containerColor = colorScheme.primary), Color.Transparent,
shape = RoundedCornerShape(12.dp), )
modifier = Modifier )
.fillMaxWidth() ))
.padding(top = 18.dp) {
.padding(horizontal = 12.dp) Row(modifier = Modifier
.height(42.dp) .fillMaxWidth()
.padding(horizontal = 16.dp).padding(top = 16.dp))
{
Text(
text = title,
fontSize = 16.sp,
lineHeight = 19.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
color = Color.White,
modifier = Modifier
.padding(8.dp)
.padding(horizontal = 10.dp)
.weight(1f)
.align(Alignment.CenterVertically)
) )
{
Row(modifier = Modifier.fillMaxSize())
{
Text(
text = title,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
modifier = Modifier
.padding(8.dp)
.padding(horizontal = 10.dp)
.weight(1f)
.align(Alignment.CenterVertically)
)
Text( Text(
text = "${pagerState.currentPage + 1}/${pagerState.pageCount}", text = "${pagerState.currentPage + 1}/${pagerState.pageCount}",
fontSize = 18.sp, fontSize = 16.sp,
fontWeight = FontWeight.Bold, lineHeight = 19.sp,
maxLines = 1, fontWeight = FontWeight.Bold,
modifier = Modifier maxLines = 1,
.padding(8.dp) color = Color.White,
.widthIn(min = 60.dp) modifier = Modifier
.align(Alignment.CenterVertically) .padding(8.dp)
) .widthIn(min = 60.dp)
} .align(Alignment.CenterVertically)
)
}
Box(Modifier.fillMaxWidth()
.padding(horizontal = 16.dp))
{
Row {
val k = it.getPageChapterIndex(pagerState.currentPage)
Text(
text = k.first.name,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
color = Color.White,
modifier = Modifier
.padding(8.dp)
.padding(horizontal = 10.dp)
.align(Alignment.CenterVertically)
)
Text(
text = "${k.second}/${it.getChapterLength(k.first.page)}",
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
color = Color.White,
modifier = Modifier
.padding(8.dp)
.widthIn(min = 60.dp)
.align(Alignment.CenterVertically)
)
} }
Box(Modifier.fillMaxWidth()) {
Card(
modifier = Modifier
.align(Alignment.CenterStart)
.padding(top = 6.dp)
.padding(horizontal = 12.dp)
.height(42.dp),
colors = CardDefaults.cardColors(containerColor = colorScheme.primary),
shape = RoundedCornerShape(12.dp)
)
{
Row {
val k = it.getPageChapterIndex(pagerState.currentPage)
Text(
text = k.first.name,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
modifier = Modifier
.padding(8.dp)
.padding(horizontal = 10.dp)
.align(Alignment.CenterVertically)
)
Text( Card(
text = "${k.second}/${it.getChapterLength(k.first.page)}", modifier = Modifier
fontSize = 18.sp, .align(Alignment.CenterEnd)
fontWeight = FontWeight.Bold, .padding(top = 6.dp)
maxLines = 1, .padding(horizontal = 12.dp)
modifier = Modifier .height(42.dp),
.padding(8.dp) colors = CardDefaults.cardColors(containerColor = colorScheme.surface),
.widthIn(min = 60.dp) shape = RoundedCornerShape(12.dp)
.align(Alignment.CenterVertically) )
) {
} Box(Modifier.clickable {
} showBookMarkPop = true
}) {
Icon(
Card( Icons.Filled.Bookmarks,
modifier = Modifier modifier = Modifier
.align(Alignment.CenterEnd) .padding(8.dp),
.padding(top = 6.dp) contentDescription = "Bookmark"
.padding(horizontal = 12.dp) )
.height(42.dp),
colors = CardDefaults.cardColors(containerColor = colorScheme.primary),
shape = RoundedCornerShape(12.dp)
)
{
Box(Modifier.clickable {
showBookMarkPop = true
}) {
Icon(
Icons.Filled.Bookmarks,
modifier = Modifier
.padding(8.dp),
contentDescription = "Bookmark"
)
}
} }
} }
} }
Spacer(Modifier.height(64.dp))
} }
} }

View File

@@ -32,7 +32,7 @@ class ComicGridViewModel @Inject constructor(
) : ViewModel() ) : ViewModel()
{ {
var coverHeight by mutableStateOf(220.dp) var coverHeight by mutableStateOf(220.dp)
var maxHeight = 220.dp var maxHeight = 0.dp
var imageLoader: ImageLoader? = null var imageLoader: ImageLoader? = null
var comic = mutableStateOf<Comic?>(null) var comic = mutableStateOf<Comic?>(null)