fix: can not load more

This commit is contained in:
AnranYus
2024-06-16 12:35:35 +08:00
parent 1cf4d6cb3d
commit 7d489e5d51
@@ -5,6 +5,7 @@ import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
@@ -221,8 +222,7 @@ fun PostListScreen(
LaunchedEffect(listState) {
snapshotFlow { listState.layoutInfo }.also{
it.collect{
snapshotFlow { listState.layoutInfo }.map { layoutInfo ->
if (lastScrollOffset < listState.firstVisibleItemScrollOffset && lastScrollPosition < listState.firstVisibleItemIndex) {
scrollDirectionState = -1
}
@@ -231,10 +231,10 @@ fun PostListScreen(
}
lastScrollOffset = listState.firstVisibleItemScrollOffset
lastScrollPosition = listState.firstVisibleItemIndex
}
}.map { layoutInfo ->
layoutInfo.visibleItemsInfo.lastOrNull()?.index == postList.lastIndex
}.distinctUntilChanged().collect { reachedEnd ->
Log.d(TAG, reachedEnd.toString())
//避免初次加载数据时,list未绘制导致被判断为到达底部
if (reachedEnd && listState.firstVisibleItemIndex != 0) {
withContext(Dispatchers.IO) {