fix: can not load more
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user