Как узнать элементы, которые полностью видны в окне просмотра ленивой строки в компоновке реактивного ранца?Android

Форум для тех, кто программирует под Android
Anonymous
Как узнать элементы, которые полностью видны в окне просмотра ленивой строки в компоновке реактивного ранца?

Сообщение Anonymous »


I have a lazy row that contains items. Now I want to make an API call for the items which are fully visible in the viewport whenever the user scrolls the lazy row.

I have tried the following code:

listState = rememberLazyListState() LaunchedEffect(listState){ snapshotFlow { listState.firstVisibleItemIndex } .collectLatest{ Log.d("printed Item", listState.firstVisibleItemIndex.toString()) }} The problems with this code are:
  • Even though the 2nd item occupies the viewport, it will not be printed unless the 1st item is fully invisible.
  • For the tablets, due to their large screen sizes, only the API call is made for the first visible item even though there are 2 visible items on the screen. Please refer to the screenshots.

When the first item is partially visible and 2nd item is fully visible [1]: Изображение

When the 2nd tile is fully visible and the first tile is completely invisible [2]: Изображение

For the tablets where 2 items are completely visible [3]: Изображение

Can anyone please tell me how to resolve my issue?


Источник: https://stackoverflow.com/questions/724 ... ow-in-jetp

Вернуться в «Android»