fix: 重组时列表异常回顶
This commit is contained in:
parent
fda886629d
commit
a3bb46ba46
|
|
@ -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,84 +189,86 @@ 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
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!forumRuleTitle.isNullOrEmpty()) {
|
MyLazyColumn(
|
||||||
item(key = "ForumRule") {
|
state = state,
|
||||||
TopThreadItem(
|
// horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
title = forumRuleTitle,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
onClick = {
|
contentPadding = WindowInsets.navigationBars.asPaddingValues()
|
||||||
onOpenForumRule?.invoke()
|
) {
|
||||||
},
|
if (!forumRuleTitle.isNullOrEmpty()) {
|
||||||
modifier = Modifier.fillMaxWidth(),
|
item(key = "ForumRule") {
|
||||||
type = stringResource(id = R.string.desc_forum_rule)
|
TopThreadItem(
|
||||||
)
|
title = forumRuleTitle,
|
||||||
}
|
onClick = {
|
||||||
}
|
onOpenForumRule?.invoke()
|
||||||
itemsIndexed(
|
},
|
||||||
items = items,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
key = { index, (holder) ->
|
type = stringResource(id = R.string.desc_forum_rule)
|
||||||
val (item) = holder
|
)
|
||||||
"${index}_${item.id}"
|
|
||||||
},
|
|
||||||
contentType = { _, (holder) ->
|
|
||||||
val (item) = holder
|
|
||||||
if (item.isTop == 1) ItemType.Top
|
|
||||||
else {
|
|
||||||
if (item.media.isNotEmpty())
|
|
||||||
if (item.media.size == 1) ItemType.SingleMedia else ItemType.MultiMedia
|
|
||||||
else if (item.videoInfo != null)
|
|
||||||
ItemType.Video
|
|
||||||
else ItemType.PlainText
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { index, (holder, blocked) ->
|
itemsIndexed(
|
||||||
BlockableContent(
|
items = items,
|
||||||
blocked = blocked,
|
key = { index, (holder) ->
|
||||||
blockedTip = { BlockTip(text = { Text(text = stringResource(id = R.string.tip_blocked_thread)) }) },
|
val (item) = holder
|
||||||
modifier = Modifier
|
"${index}_${item.id}"
|
||||||
.fillMaxWidth()
|
},
|
||||||
.padding(vertical = 8.dp, horizontal = 16.dp),
|
contentType = { _, (holder) ->
|
||||||
) {
|
val (item) = holder
|
||||||
val (item) = holder
|
if (item.isTop == 1) ItemType.Top
|
||||||
Column(
|
else {
|
||||||
modifier = Modifier.fillMaxWidth(itemFraction)
|
if (item.media.isNotEmpty())
|
||||||
|
if (item.media.size == 1) ItemType.SingleMedia else ItemType.MultiMedia
|
||||||
|
else if (item.videoInfo != null)
|
||||||
|
ItemType.Video
|
||||||
|
else ItemType.PlainText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) { index, (holder, blocked) ->
|
||||||
|
BlockableContent(
|
||||||
|
blocked = blocked,
|
||||||
|
blockedTip = { BlockTip(text = { Text(text = stringResource(id = R.string.tip_blocked_thread)) }) },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(vertical = 8.dp, horizontal = 16.dp),
|
||||||
) {
|
) {
|
||||||
if (item.isTop == 1) {
|
val (item) = holder
|
||||||
val title = item.title.takeUnless { it.isBlank() } ?: item.abstractText
|
Column(
|
||||||
TopThreadItem(
|
modifier = Modifier.fillMaxWidth(itemFraction)
|
||||||
title = title,
|
) {
|
||||||
onClick = { onItemClicked(item) },
|
if (item.isTop == 1) {
|
||||||
modifier = Modifier.fillMaxWidth(),
|
val title = item.title.takeUnless { it.isBlank() } ?: item.abstractText
|
||||||
)
|
TopThreadItem(
|
||||||
} else {
|
title = title,
|
||||||
if (index > 0) {
|
onClick = { onItemClicked(item) },
|
||||||
if (items[index - 1].thread.get { isTop } == 1) {
|
modifier = Modifier.fillMaxWidth(),
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
)
|
||||||
|
} else {
|
||||||
|
if (index > 0) {
|
||||||
|
if (items[index - 1].thread.get { isTop } == 1) {
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
VerticalDivider(modifier = Modifier.padding(horizontal = 16.dp))
|
||||||
}
|
}
|
||||||
VerticalDivider(modifier = Modifier.padding(horizontal = 16.dp))
|
FeedCard(
|
||||||
|
item = holder,
|
||||||
|
onClick = onItemClicked,
|
||||||
|
onClickReply = onItemReplyClicked,
|
||||||
|
onAgree = onAgree,
|
||||||
|
onClickOriginThread = onOriginThreadClicked,
|
||||||
|
onClickUser = onUserClicked
|
||||||
|
)
|
||||||
}
|
}
|
||||||
FeedCard(
|
|
||||||
item = holder,
|
|
||||||
onClick = onItemClicked,
|
|
||||||
onClickReply = onItemReplyClicked,
|
|
||||||
onAgree = onAgree,
|
|
||||||
onClickOriginThread = onOriginThreadClicked,
|
|
||||||
onClickUser = onUserClicked
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue