Skip to content

Commit ac075f0

Browse files
committed
Gallery: rework load more management
1 parent 67e70cc commit ac075f0

File tree

1 file changed

+17
-22
lines changed
  • libraries/mediaviewer/impl/src/main/kotlin/io/element/android/libraries/mediaviewer/impl/gallery

1 file changed

+17
-22
lines changed

libraries/mediaviewer/impl/src/main/kotlin/io/element/android/libraries/mediaviewer/impl/gallery/MediaGalleryView.kt

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,11 @@ private fun MediaGalleryFilesList(
299299
is MediaItem.Video -> {
300300
// Should not happen
301301
}
302-
is MediaItem.LoadingIndicator -> {
303-
LoadingMoreIndicator(
304-
modifier = Modifier.animateItem(),
305-
direction = item.direction,
306-
)
307-
val latestEventSink by rememberUpdatedState(eventSink)
308-
LaunchedEffect(item.timestamp) {
309-
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
310-
}
311-
}
302+
is MediaItem.LoadingIndicator -> LoadingMoreIndicator(
303+
modifier = Modifier.animateItem(),
304+
item = item,
305+
eventSink = eventSink,
306+
)
312307
}
313308
}
314309
}
@@ -370,31 +365,27 @@ private fun MediaGalleryImageGrid(
370365
eventSink(MediaGalleryEvents.OpenInfo(item))
371366
},
372367
)
373-
is MediaItem.LoadingIndicator -> {
374-
LoadingMoreIndicator(
375-
modifier = Modifier.animateItem(),
376-
direction = item.direction,
377-
)
378-
val latestEventSink by rememberUpdatedState(eventSink)
379-
LaunchedEffect(item.timestamp) {
380-
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
381-
}
382-
}
368+
is MediaItem.LoadingIndicator -> LoadingMoreIndicator(
369+
modifier = Modifier.animateItem(),
370+
item = item,
371+
eventSink = eventSink,
372+
)
383373
}
384374
}
385375
}
386376
}
387377

388378
@Composable
389379
private fun LoadingMoreIndicator(
390-
direction: Timeline.PaginationDirection,
380+
item: MediaItem.LoadingIndicator,
381+
eventSink: (MediaGalleryEvents) -> Unit,
391382
modifier: Modifier = Modifier
392383
) {
393384
Box(
394385
modifier = modifier.fillMaxWidth(),
395386
contentAlignment = Alignment.Center,
396387
) {
397-
when (direction) {
388+
when (item.direction) {
398389
Timeline.PaginationDirection.FORWARDS -> {
399390
LinearProgressIndicator(
400391
modifier = Modifier
@@ -410,6 +401,10 @@ private fun LoadingMoreIndicator(
410401
)
411402
}
412403
}
404+
val latestEventSink by rememberUpdatedState(eventSink)
405+
LaunchedEffect(item.timestamp) {
406+
latestEventSink(MediaGalleryEvents.LoadMore(item.direction))
407+
}
413408
}
414409
}
415410

0 commit comments

Comments
 (0)