fix: 贴子页面闪退
This commit is contained in:
parent
878e8ba8f1
commit
7460a0cd29
|
|
@ -25,7 +25,7 @@ import androidx.compose.foundation.layout.statusBarsPadding
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListScope
|
import androidx.compose.foundation.lazy.LazyListScope
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.text.appendInlineContent
|
import androidx.compose.foundation.text.appendInlineContent
|
||||||
|
|
@ -433,14 +433,6 @@ fun ThreadPage(
|
||||||
prop1 = ThreadUiState::data,
|
prop1 = ThreadUiState::data,
|
||||||
initial = persistentListOf()
|
initial = persistentListOf()
|
||||||
)
|
)
|
||||||
val contentRenders by viewModel.uiState.collectPartialAsState(
|
|
||||||
prop1 = ThreadUiState::contentRenders,
|
|
||||||
initial = persistentListOf()
|
|
||||||
)
|
|
||||||
val subPostContents by viewModel.uiState.collectPartialAsState(
|
|
||||||
prop1 = ThreadUiState::subPostContents,
|
|
||||||
initial = persistentListOf()
|
|
||||||
)
|
|
||||||
val author by viewModel.uiState.collectPartialAsState(
|
val author by viewModel.uiState.collectPartialAsState(
|
||||||
prop1 = ThreadUiState::author,
|
prop1 = ThreadUiState::author,
|
||||||
initial = null
|
initial = null
|
||||||
|
|
@ -521,14 +513,6 @@ fun ThreadPage(
|
||||||
prop1 = ThreadUiState::latestPosts,
|
prop1 = ThreadUiState::latestPosts,
|
||||||
initial = persistentListOf()
|
initial = persistentListOf()
|
||||||
)
|
)
|
||||||
val latestPostContentRenders by viewModel.uiState.collectPartialAsState(
|
|
||||||
prop1 = ThreadUiState::latestPostContentRenders,
|
|
||||||
initial = persistentListOf()
|
|
||||||
)
|
|
||||||
val latestPostSubPostContents by viewModel.uiState.collectPartialAsState(
|
|
||||||
prop1 = ThreadUiState::latestPostSubPostContents,
|
|
||||||
initial = persistentListOf()
|
|
||||||
)
|
|
||||||
|
|
||||||
val isEmpty by remember {
|
val isEmpty by remember {
|
||||||
derivedStateOf { data.isEmpty() && firstPost == null }
|
derivedStateOf { data.isEmpty() && firstPost == null }
|
||||||
|
|
@ -621,18 +605,19 @@ fun ThreadPage(
|
||||||
|
|
||||||
onGlobalEvent<GlobalEvent.ReplySuccess>(
|
onGlobalEvent<GlobalEvent.ReplySuccess>(
|
||||||
filter = { it.threadId == threadId }
|
filter = { it.threadId == threadId }
|
||||||
) {
|
) { event ->
|
||||||
viewModel.send(
|
viewModel.send(
|
||||||
ThreadUiIntent.LoadLatestReply(
|
ThreadUiIntent.LoadLatestReply(
|
||||||
threadId = threadId,
|
threadId = threadId,
|
||||||
postId = it.newPostId,
|
postId = event.newPostId,
|
||||||
forumId = curForumId,
|
forumId = curForumId,
|
||||||
isDesc = curSortType == ThreadSortType.SORT_TYPE_DESC,
|
isDesc = curSortType == ThreadSortType.SORT_TYPE_DESC,
|
||||||
curLatestPostFloor = if (curSortType == ThreadSortType.SORT_TYPE_DESC) {
|
curLatestPostFloor = if (curSortType == ThreadSortType.SORT_TYPE_DESC) {
|
||||||
data.firstOrNull()?.post?.get { floor } ?: 1
|
data.firstOrNull()?.post?.get { floor } ?: 1
|
||||||
} else {
|
} else {
|
||||||
data.lastOrNull()?.post?.get { floor } ?: 1
|
data.lastOrNull()?.post?.get { floor } ?: 1
|
||||||
}
|
},
|
||||||
|
curPostIds = data.map { it.post.get { id } },
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -935,14 +920,14 @@ fun ThreadPage(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemsIndexed(
|
items(
|
||||||
items = latestPosts,
|
items = latestPosts,
|
||||||
key = { _, (item) -> "LatestPost_${item.get { id }}" }
|
key = { (item) -> "LatestPost_${item.get { id }}" }
|
||||||
) { index, (item, blocked) ->
|
) { (item, blocked, renders, subPostContents) ->
|
||||||
PostCard(
|
PostCard(
|
||||||
item,
|
item,
|
||||||
latestPostContentRenders[index],
|
renders,
|
||||||
latestPostSubPostContents[index],
|
subPostContents,
|
||||||
blocked
|
blocked
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -1029,7 +1014,7 @@ fun ThreadPage(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val readItem = getLastVisibilityPost()
|
val readItem = lastVisibilityPost
|
||||||
if (readItem != null) {
|
if (readItem != null) {
|
||||||
viewModel.send(
|
viewModel.send(
|
||||||
ThreadUiIntent.AddFavorite(
|
ThreadUiIntent.AddFavorite(
|
||||||
|
|
@ -1308,14 +1293,14 @@ fun ThreadPage(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemsIndexed(
|
items(
|
||||||
items = data,
|
items = data,
|
||||||
key = { _, (item) -> "Post_${item.get { id }}" }
|
key = { (item) -> "Post_${item.get { id }}" }
|
||||||
) { index, (item, blocked) ->
|
) { (item, blocked, renders, subPostContents) ->
|
||||||
PostCard(
|
PostCard(
|
||||||
item,
|
item,
|
||||||
contentRenders[index],
|
renders,
|
||||||
subPostContents[index],
|
subPostContents,
|
||||||
blocked
|
blocked
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -623,11 +623,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
hasPrevious = hasPrevious,
|
hasPrevious = hasPrevious,
|
||||||
firstPostContentRenders = firstPostContentRenders?.toImmutableList()
|
firstPostContentRenders = firstPostContentRenders?.toImmutableList()
|
||||||
?: oldState.firstPostContentRenders,
|
?: oldState.firstPostContentRenders,
|
||||||
contentRenders = contentRenders.toImmutableList(),
|
|
||||||
subPostContents = subPostContents.toImmutableList(),
|
|
||||||
latestPosts = persistentListOf(),
|
latestPosts = persistentListOf(),
|
||||||
latestPostContentRenders = persistentListOf(),
|
|
||||||
latestPostSubPostContents = persistentListOf(),
|
|
||||||
postId = postId,
|
postId = postId,
|
||||||
seeLz = seeLz,
|
seeLz = seeLz,
|
||||||
sortType = sortType,
|
sortType = sortType,
|
||||||
|
|
@ -687,11 +683,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
nextPagePostId = nextPagePostId,
|
nextPagePostId = nextPagePostId,
|
||||||
hasPrevious = hasPrevious,
|
hasPrevious = hasPrevious,
|
||||||
firstPostContentRenders = firstPostContentRenders.toImmutableList(),
|
firstPostContentRenders = firstPostContentRenders.toImmutableList(),
|
||||||
contentRenders = contentRenders.toImmutableList(),
|
|
||||||
subPostContents = subPostContents.toImmutableList(),
|
|
||||||
latestPosts = persistentListOf(),
|
latestPosts = persistentListOf(),
|
||||||
latestPostContentRenders = persistentListOf(),
|
|
||||||
latestPostSubPostContents = persistentListOf(),
|
|
||||||
postId = postId,
|
postId = postId,
|
||||||
seeLz = seeLz,
|
seeLz = seeLz,
|
||||||
sortType = sortType,
|
sortType = sortType,
|
||||||
|
|
@ -741,11 +733,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
totalPage = totalPage,
|
totalPage = totalPage,
|
||||||
hasMore = hasMore,
|
hasMore = hasMore,
|
||||||
nextPagePostId = nextPagePostId,
|
nextPagePostId = nextPagePostId,
|
||||||
contentRenders = (oldState.contentRenders + contentRenders).toImmutableList(),
|
|
||||||
subPostContents = (oldState.subPostContents + subPostContents).toImmutableList(),
|
|
||||||
latestPosts = persistentListOf(),
|
latestPosts = persistentListOf(),
|
||||||
latestPostContentRenders = persistentListOf(),
|
|
||||||
latestPostSubPostContents = persistentListOf(),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
is Failure -> oldState.copy(isLoadingMore = false)
|
is Failure -> oldState.copy(isLoadingMore = false)
|
||||||
|
|
@ -782,8 +770,6 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
currentPageMin = currentPage,
|
currentPageMin = currentPage,
|
||||||
totalPage = totalPage,
|
totalPage = totalPage,
|
||||||
hasPrevious = hasPrevious,
|
hasPrevious = hasPrevious,
|
||||||
contentRenders = (contentRenders + oldState.contentRenders).toImmutableList(),
|
|
||||||
subPostContents = (subPostContents + oldState.subPostContents).toImmutableList()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
is Failure -> oldState.copy(isRefreshing = false)
|
is Failure -> oldState.copy(isRefreshing = false)
|
||||||
|
|
@ -823,14 +809,6 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
val replaceIndex = replacePostIndexes.firstOrNull { it.first == index }
|
val replaceIndex = replacePostIndexes.firstOrNull { it.first == index }
|
||||||
if (replaceIndex != null) posts[replaceIndex.second] else oldItem
|
if (replaceIndex != null) posts[replaceIndex.second] else oldItem
|
||||||
}
|
}
|
||||||
val newContentRenders = oldState.contentRenders.mapIndexed { index, oldItem ->
|
|
||||||
val replaceIndex = replacePostIndexes.firstOrNull { it.first == index }
|
|
||||||
if (replaceIndex != null) contentRenders[replaceIndex.second] else oldItem
|
|
||||||
}
|
|
||||||
val newSubPostContents = oldState.subPostContents.mapIndexed { index, oldItem ->
|
|
||||||
val replaceIndex = replacePostIndexes.firstOrNull { it.first == index }
|
|
||||||
if (replaceIndex != null) subPostContents[replaceIndex.second] else oldItem
|
|
||||||
}
|
|
||||||
when {
|
when {
|
||||||
hasNewPost && continuous && isDesc -> {
|
hasNewPost && continuous && isDesc -> {
|
||||||
oldState.copy(
|
oldState.copy(
|
||||||
|
|
@ -839,11 +817,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
error = null,
|
error = null,
|
||||||
anti = anti.wrapImmutable(),
|
anti = anti.wrapImmutable(),
|
||||||
data = (posts + newPost).toImmutableList(),
|
data = (posts + newPost).toImmutableList(),
|
||||||
contentRenders = (contentRenders + newContentRenders).toImmutableList(),
|
|
||||||
subPostContents = (subPostContents + newSubPostContents).toImmutableList(),
|
|
||||||
latestPosts = persistentListOf(),
|
latestPosts = persistentListOf(),
|
||||||
latestPostContentRenders = persistentListOf(),
|
|
||||||
latestPostSubPostContents = persistentListOf(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -854,11 +828,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
error = null,
|
error = null,
|
||||||
anti = anti.wrapImmutable(),
|
anti = anti.wrapImmutable(),
|
||||||
data = (newPost + posts).toImmutableList(),
|
data = (newPost + posts).toImmutableList(),
|
||||||
contentRenders = (newContentRenders + contentRenders).toImmutableList(),
|
|
||||||
subPostContents = (newSubPostContents + subPostContents).toImmutableList(),
|
|
||||||
latestPosts = persistentListOf(),
|
latestPosts = persistentListOf(),
|
||||||
latestPostContentRenders = persistentListOf(),
|
|
||||||
latestPostSubPostContents = persistentListOf(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -869,11 +839,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
error = null,
|
error = null,
|
||||||
anti = anti.wrapImmutable(),
|
anti = anti.wrapImmutable(),
|
||||||
data = newPost.toImmutableList(),
|
data = newPost.toImmutableList(),
|
||||||
contentRenders = newContentRenders.toImmutableList(),
|
|
||||||
subPostContents = newSubPostContents.toImmutableList(),
|
|
||||||
latestPosts = posts.toImmutableList(),
|
latestPosts = posts.toImmutableList(),
|
||||||
latestPostContentRenders = contentRenders.toImmutableList(),
|
|
||||||
latestPostSubPostContents = subPostContents.toImmutableList(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -884,11 +850,7 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
error = null,
|
error = null,
|
||||||
anti = anti.wrapImmutable(),
|
anti = anti.wrapImmutable(),
|
||||||
data = newPost.toImmutableList(),
|
data = newPost.toImmutableList(),
|
||||||
contentRenders = newContentRenders.toImmutableList(),
|
|
||||||
subPostContents = newSubPostContents.toImmutableList(),
|
|
||||||
latestPosts = persistentListOf(),
|
latestPosts = persistentListOf(),
|
||||||
latestPostContentRenders = persistentListOf(),
|
|
||||||
latestPostSubPostContents = persistentListOf(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1088,8 +1050,6 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
||||||
val deletedPostIndex = oldState.data.indexOfFirst { it.post.get { id } == postId }
|
val deletedPostIndex = oldState.data.indexOfFirst { it.post.get { id } == postId }
|
||||||
oldState.copy(
|
oldState.copy(
|
||||||
data = oldState.data.removeAt(deletedPostIndex),
|
data = oldState.data.removeAt(deletedPostIndex),
|
||||||
contentRenders = oldState.contentRenders.removeAt(deletedPostIndex),
|
|
||||||
subPostContents = oldState.subPostContents.removeAt(deletedPostIndex)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1146,11 +1106,7 @@ data class ThreadUiState(
|
||||||
|
|
||||||
val firstPostContentRenders: ImmutableList<PbContentRender> = persistentListOf(),
|
val firstPostContentRenders: ImmutableList<PbContentRender> = persistentListOf(),
|
||||||
val data: ImmutableList<PostItemData> = persistentListOf(),
|
val data: ImmutableList<PostItemData> = persistentListOf(),
|
||||||
val contentRenders: ImmutableList<ImmutableList<PbContentRender>> = persistentListOf(),
|
|
||||||
val subPostContents: ImmutableList<ImmutableList<AnnotatedString>> = persistentListOf(),
|
|
||||||
val latestPosts: ImmutableList<PostItemData> = persistentListOf(),
|
val latestPosts: ImmutableList<PostItemData> = persistentListOf(),
|
||||||
val latestPostContentRenders: ImmutableList<ImmutableList<PbContentRender>> = persistentListOf(),
|
|
||||||
val latestPostSubPostContents: ImmutableList<ImmutableList<AnnotatedString>> = persistentListOf(),
|
|
||||||
|
|
||||||
val isImmersiveMode: Boolean = false,
|
val isImmersiveMode: Boolean = false,
|
||||||
) : UiState
|
) : UiState
|
||||||
|
|
@ -1179,5 +1135,7 @@ object ThreadSortType {
|
||||||
@Immutable
|
@Immutable
|
||||||
data class PostItemData(
|
data class PostItemData(
|
||||||
val post: ImmutableHolder<Post>,
|
val post: ImmutableHolder<Post>,
|
||||||
val blocked: Boolean = post.get { shouldBlock() }
|
val blocked: Boolean = post.get { shouldBlock() },
|
||||||
|
val contentRenders: ImmutableList<PbContentRender> = post.get { this.contentRenders },
|
||||||
|
val subPostContents: ImmutableList<AnnotatedString> = post.get { this.subPostContents },
|
||||||
)
|
)
|
||||||
Loading…
Reference in New Issue