Gallery: rework load more management
This commit is contained in:
parent
a9b5c61ebf
commit
9c89c7892d
1 changed files with 17 additions and 22 deletions
|
|
@ -299,16 +299,11 @@ private fun MediaGalleryFilesList(
|
||||||
is MediaItem.Video -> {
|
is MediaItem.Video -> {
|
||||||
// Should not happen
|
// Should not happen
|
||||||
}
|
}
|
||||||
is MediaItem.LoadingIndicator -> {
|
is MediaItem.LoadingIndicator -> LoadingMoreIndicator(
|
||||||
LoadingMoreIndicator(
|
modifier = Modifier.animateItem(),
|
||||||
modifier = Modifier.animateItem(),
|
item = item,
|
||||||
direction = item.direction,
|
eventSink = eventSink,
|
||||||
)
|
)
|
||||||
val latestEventSink by rememberUpdatedState(eventSink)
|
|
||||||
LaunchedEffect(item.timestamp) {
|
|
||||||
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -370,16 +365,11 @@ private fun MediaGalleryImageGrid(
|
||||||
eventSink(MediaGalleryEvents.OpenInfo(item))
|
eventSink(MediaGalleryEvents.OpenInfo(item))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
is MediaItem.LoadingIndicator -> {
|
is MediaItem.LoadingIndicator -> LoadingMoreIndicator(
|
||||||
LoadingMoreIndicator(
|
modifier = Modifier.animateItem(),
|
||||||
modifier = Modifier.animateItem(),
|
item = item,
|
||||||
direction = item.direction,
|
eventSink = eventSink,
|
||||||
)
|
)
|
||||||
val latestEventSink by rememberUpdatedState(eventSink)
|
|
||||||
LaunchedEffect(item.timestamp) {
|
|
||||||
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -387,14 +377,15 @@ private fun MediaGalleryImageGrid(
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun LoadingMoreIndicator(
|
private fun LoadingMoreIndicator(
|
||||||
direction: Timeline.PaginationDirection,
|
item: MediaItem.LoadingIndicator,
|
||||||
|
eventSink: (MediaGalleryEvents) -> Unit,
|
||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
when (direction) {
|
when (item.direction) {
|
||||||
Timeline.PaginationDirection.FORWARDS -> {
|
Timeline.PaginationDirection.FORWARDS -> {
|
||||||
LinearProgressIndicator(
|
LinearProgressIndicator(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
@ -410,6 +401,10 @@ private fun LoadingMoreIndicator(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val latestEventSink by rememberUpdatedState(eventSink)
|
||||||
|
LaunchedEffect(item.timestamp) {
|
||||||
|
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue