fix: 吧页面点击刷新后不自动回顶
This commit is contained in:
parent
c4e96c4031
commit
b6737f85d6
|
|
@ -43,7 +43,7 @@ sealed interface GlobalEvent : UiEvent {
|
|||
}
|
||||
|
||||
private val globalEventSharedFlow: MutableSharedFlow<UiEvent> by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
MutableSharedFlow(0, 1, BufferOverflow.DROP_OLDEST)
|
||||
MutableSharedFlow(0, 2, BufferOverflow.DROP_OLDEST)
|
||||
}
|
||||
|
||||
val GlobalEventFlow = globalEventSharedFlow.asSharedFlow()
|
||||
|
|
@ -54,7 +54,7 @@ fun CoroutineScope.emitGlobalEvent(event: UiEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun emitGlobalEvent(event: UiEvent) {
|
||||
suspend fun emitGlobalEventSuspend(event: UiEvent) {
|
||||
globalEventSharedFlow.emit(event)
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,6 @@ inline fun <reified Event : UiEvent> onGlobalEvent(
|
|||
GlobalEventFlow
|
||||
.filterIsInstance<Event>()
|
||||
.filter {
|
||||
Log.i("GlobalEvent", "onGlobalEvent: $it")
|
||||
filter(it)
|
||||
}
|
||||
.cancellable()
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ import com.huanchengfly.tieba.post.api.models.protos.frsPage.ForumInfo
|
|||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
||||
import com.huanchengfly.tieba.post.arch.emitGlobalEvent
|
||||
import com.huanchengfly.tieba.post.arch.emitGlobalEventSuspend
|
||||
import com.huanchengfly.tieba.post.arch.onEvent
|
||||
import com.huanchengfly.tieba.post.arch.pageViewModel
|
||||
import com.huanchengfly.tieba.post.dataStore
|
||||
|
|
@ -593,12 +594,12 @@ fun ForumPage(
|
|||
when (context.appPreferences.forumFabFunction) {
|
||||
"refresh" -> {
|
||||
coroutineScope.launch {
|
||||
emitGlobalEvent(
|
||||
emitGlobalEventSuspend(
|
||||
ForumThreadListUiEvent.BackToTop(
|
||||
pagerState.currentPage == 1
|
||||
)
|
||||
)
|
||||
emitGlobalEvent(
|
||||
emitGlobalEventSuspend(
|
||||
ForumThreadListUiEvent.Refresh(
|
||||
pagerState.currentPage == 1,
|
||||
getSortType(
|
||||
|
|
@ -838,7 +839,7 @@ fun ForumPage(
|
|||
forumId = forumInfo!!.get { id },
|
||||
forumName = forumInfo!!.get { name },
|
||||
isGood = it == 1,
|
||||
lazyListState = lazyListStates[it]
|
||||
lazyListState = remember { lazyListStates[it] }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,10 +271,14 @@ fun ForumThreadListPage(
|
|||
viewModel.send(getFirstLoadIntent(context, forumName, isGood))
|
||||
viewModel.initialized = true
|
||||
}
|
||||
onGlobalEvent<ForumThreadListUiEvent.Refresh> {
|
||||
onGlobalEvent<ForumThreadListUiEvent.Refresh>(
|
||||
filter = { it.isGood == isGood },
|
||||
) {
|
||||
viewModel.send(getRefreshIntent(context, forumName, isGood, it.sortType))
|
||||
}
|
||||
onGlobalEvent<ForumThreadListUiEvent.BackToTop> {
|
||||
onGlobalEvent<ForumThreadListUiEvent.BackToTop>(
|
||||
filter = { it.isGood == isGood },
|
||||
) {
|
||||
lazyListState.animateScrollToItem(0)
|
||||
}
|
||||
viewModel.onEvent<ForumThreadListUiEvent.AgreeFail> {
|
||||
|
|
|
|||
|
|
@ -718,17 +718,22 @@ sealed interface ThreadPartialChange : PartialChange<ThreadUiState> {
|
|||
sealed class LoadMore : ThreadPartialChange {
|
||||
override fun reduce(oldState: ThreadUiState): ThreadUiState = when (this) {
|
||||
is Start -> oldState.copy(isLoadingMore = true)
|
||||
is Success -> oldState.copy(
|
||||
isLoadingMore = false,
|
||||
author = wrapImmutable(author),
|
||||
data = (oldState.data + data).toImmutableList(),
|
||||
threadInfo = threadInfo.wrapImmutable(),
|
||||
currentPageMax = currentPage,
|
||||
totalPage = totalPage,
|
||||
hasMore = hasMore,
|
||||
nextPagePostId = nextPagePostId,
|
||||
latestPosts = persistentListOf(),
|
||||
)
|
||||
is Success -> {
|
||||
val uniqueData = data.filterNot { item ->
|
||||
oldState.data.any { it.post.get { id } == item.post.get { id } }
|
||||
}
|
||||
oldState.copy(
|
||||
isLoadingMore = false,
|
||||
author = wrapImmutable(author),
|
||||
data = (oldState.data + uniqueData).toImmutableList(),
|
||||
threadInfo = threadInfo.wrapImmutable(),
|
||||
currentPageMax = currentPage,
|
||||
totalPage = totalPage,
|
||||
hasMore = hasMore,
|
||||
nextPagePostId = nextPagePostId,
|
||||
latestPosts = persistentListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
is Failure -> oldState.copy(isLoadingMore = false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue