fix: 重组时列表异常回顶

This commit is contained in:
HuanCheng65 2023-10-08 11:24:30 +08:00
parent fda886629d
commit a3bb46ba46
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
1 changed files with 74 additions and 71 deletions

View File

@ -35,6 +35,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastForEach
import com.huanchengfly.tieba.post.R import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.api.models.protos.OriginThreadInfo import com.huanchengfly.tieba.post.api.models.protos.OriginThreadInfo
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
@ -59,6 +60,7 @@ import com.huanchengfly.tieba.post.ui.page.forum.getSortType
import com.huanchengfly.tieba.post.ui.widgets.Chip import com.huanchengfly.tieba.post.ui.widgets.Chip
import com.huanchengfly.tieba.post.ui.widgets.compose.BlockTip import com.huanchengfly.tieba.post.ui.widgets.compose.BlockTip
import com.huanchengfly.tieba.post.ui.widgets.compose.BlockableContent import com.huanchengfly.tieba.post.ui.widgets.compose.BlockableContent
import com.huanchengfly.tieba.post.ui.widgets.compose.Container
import com.huanchengfly.tieba.post.ui.widgets.compose.FeedCard import com.huanchengfly.tieba.post.ui.widgets.compose.FeedCard
import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad import com.huanchengfly.tieba.post.ui.widgets.compose.LazyLoad
import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout import com.huanchengfly.tieba.post.ui.widgets.compose.LoadMoreLayout
@ -112,18 +114,17 @@ private enum class ItemType {
@Composable @Composable
private fun GoodClassifyTabs( private fun GoodClassifyTabs(
goodClassifyHoldersProvider: () -> List<ImmutableHolder<Classify>>, goodClassifyHolders: ImmutableList<ImmutableHolder<Classify>>,
selectedItem: Int?, selectedItem: Int?,
onSelected: (Int) -> Unit, onSelected: (Int) -> Unit,
) { ) {
val goodClassifyHolders = goodClassifyHoldersProvider()
Row( Row(
modifier = Modifier modifier = Modifier
.horizontalScroll(rememberScrollState()) .horizontalScroll(rememberScrollState())
.padding(vertical = 8.dp, horizontal = 16.dp), .padding(vertical = 8.dp, horizontal = 16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp) horizontalArrangement = Arrangement.spacedBy(8.dp)
) { ) {
goodClassifyHolders.forEach { holder -> goodClassifyHolders.fastForEach { holder ->
val (classify) = holder val (classify) = holder
Chip( Chip(
text = classify.class_name, text = classify.class_name,
@ -173,7 +174,7 @@ private fun ThreadList(
items: ImmutableList<ThreadItemData>, items: ImmutableList<ThreadItemData>,
isGood: Boolean, isGood: Boolean,
goodClassifyId: Int?, goodClassifyId: Int?,
goodClassifyHoldersProvider: () -> List<ImmutableHolder<Classify>>, goodClassifyHolders: ImmutableList<ImmutableHolder<Classify>>,
onItemClicked: (ThreadInfo) -> Unit, onItemClicked: (ThreadInfo) -> Unit,
onItemReplyClicked: (ThreadInfo) -> Unit, onItemReplyClicked: (ThreadInfo) -> Unit,
onAgree: (ThreadInfo) -> Unit, onAgree: (ThreadInfo) -> Unit,
@ -188,21 +189,22 @@ private fun ThreadList(
WindowWidthSizeClass.Expanded -> 0.5f WindowWidthSizeClass.Expanded -> 0.5f
else -> 1f else -> 1f
} }
MyLazyColumn( Column {
state = state,
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(),
contentPadding = WindowInsets.navigationBars.asPaddingValues()
) {
if (isGood) { if (isGood) {
item(key = "GoodClassifyHeader") { Container {
GoodClassifyTabs( GoodClassifyTabs(
goodClassifyHoldersProvider = goodClassifyHoldersProvider, goodClassifyHolders = goodClassifyHolders,
selectedItem = goodClassifyId, selectedItem = goodClassifyId,
onSelected = onClassifySelected onSelected = onClassifySelected
) )
} }
} }
MyLazyColumn(
state = state,
// horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth(),
contentPadding = WindowInsets.navigationBars.asPaddingValues()
) {
if (!forumRuleTitle.isNullOrEmpty()) { if (!forumRuleTitle.isNullOrEmpty()) {
item(key = "ForumRule") { item(key = "ForumRule") {
TopThreadItem( TopThreadItem(
@ -271,6 +273,7 @@ private fun ThreadList(
} }
} }
} }
}
} }
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@ -385,7 +388,7 @@ fun ForumThreadListPage(
items = threadList, items = threadList,
isGood = isGood, isGood = isGood,
goodClassifyId = goodClassifyId, goodClassifyId = goodClassifyId,
goodClassifyHoldersProvider = { goodClassifies }, goodClassifyHolders = goodClassifies,
onItemClicked = { onItemClicked = {
navigator.navigate( navigator.navigate(
ThreadPageDestination( ThreadPageDestination(