@@ -207,28 +207,17 @@ private fun FeedScreen(
207207
208208 val isAtBottom by remember(pagerState.currentPage) {
209209 derivedStateOf {
210- val feedListState = when (pagerState.currentPage) {
211- 0 -> recommendFeedList
212- else -> followingFeedList
213- }
214-
215- when (feedListState) {
216- is UiState .Success -> {
217- val feedList = feedListState.data
218- val layoutInfo = currentListState.layoutInfo
219- val visibleItemsInfo = layoutInfo.visibleItemsInfo
220-
221- if (feedList.isEmpty() || layoutInfo.totalItemsCount == 0 ) return @derivedStateOf false
210+ val layoutInfo = currentListState.layoutInfo
211+ val visibleItemsInfo = layoutInfo.visibleItemsInfo
222212
223- val lastVisibleItem = visibleItemsInfo.last()
224- val viewportHeight =
225- layoutInfo.viewportEndOffset + layoutInfo.viewportStartOffset
226- (lastVisibleItem.index == layoutInfo.totalItemsCount - 1 ) &&
227- (lastVisibleItem.offset + lastVisibleItem.size <= viewportHeight)
228- }
229-
230- else -> false
213+ if (layoutInfo.totalItemsCount == 0 || visibleItemsInfo.isEmpty()) {
214+ return @derivedStateOf false
231215 }
216+
217+ val lastVisibleItem = visibleItemsInfo.last()
218+ val viewportHeight = layoutInfo.viewportEndOffset + layoutInfo.viewportStartOffset
219+ (lastVisibleItem.index == layoutInfo.totalItemsCount - 1 ) &&
220+ (lastVisibleItem.offset + lastVisibleItem.size <= viewportHeight)
232221 }
233222 }
234223
@@ -239,13 +228,15 @@ private fun FeedScreen(
239228 FeedScrollState (
240229 itemIndex = currentListState.firstVisibleItemIndex,
241230 scrollOffset = currentListState.firstVisibleItemScrollOffset,
231+ isAtBottom = isAtBottom,
232+ isScrollInProgress = currentListState.isScrollInProgress,
242233 )
243234 }
244235 .pairwise()
245236 .collect { (previous, current) ->
246- if (currentListState .isScrollInProgress &&
237+ if (current .isScrollInProgress &&
247238 current.isScrollingDownFrom(previous) &&
248- isAtBottom
239+ current. isAtBottom
249240 ) {
250241 latestReadAllFeed()
251242 }
@@ -355,6 +346,8 @@ private fun FeedScreenPreview() {
355346private data class FeedScrollState (
356347 val itemIndex : Int ,
357348 val scrollOffset : Int ,
349+ val isAtBottom : Boolean = false ,
350+ val isScrollInProgress : Boolean = false ,
358351) {
359352 fun isScrollingDownFrom (previous : FeedScrollState ? ): Boolean {
360353 if (previous == null ) return false
0 commit comments