mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Merge the read receipts code with TimelineScrollHelper (#736)
This commit is contained in:
committed by
GitHub
parent
a2b3807e2e
commit
d3d314d9f9
+19
-6
@@ -77,6 +77,10 @@ fun TimelineView(
|
|||||||
state.eventSink(TimelineEvents.LoadMore)
|
state.eventSink(TimelineEvents.LoadMore)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onScrollFinishedAt(firstVisibleIndex: Int) {
|
||||||
|
state.eventSink(TimelineEvents.OnScrollFinished(firstVisibleIndex))
|
||||||
|
}
|
||||||
|
|
||||||
val lazyListState = rememberLazyListState()
|
val lazyListState = rememberLazyListState()
|
||||||
|
|
||||||
fun inReplyToClicked(eventId: EventId) {
|
fun inReplyToClicked(eventId: EventId) {
|
||||||
@@ -121,7 +125,8 @@ fun TimelineView(
|
|||||||
|
|
||||||
TimelineScrollHelper(
|
TimelineScrollHelper(
|
||||||
lazyListState = lazyListState,
|
lazyListState = lazyListState,
|
||||||
timelineItems = state.timelineItems
|
timelineItems = state.timelineItems,
|
||||||
|
onScrollFinishedAt = ::onScrollFinishedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,21 +224,29 @@ fun TimelineItemRow(
|
|||||||
internal fun BoxScope.TimelineScrollHelper(
|
internal fun BoxScope.TimelineScrollHelper(
|
||||||
lazyListState: LazyListState,
|
lazyListState: LazyListState,
|
||||||
timelineItems: ImmutableList<TimelineItem>,
|
timelineItems: ImmutableList<TimelineItem>,
|
||||||
|
onScrollFinishedAt: (Int) -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val firstVisibleItemIndex by remember { derivedStateOf { lazyListState.firstVisibleItemIndex } }
|
val firstVisibleItemIndex by remember { derivedStateOf { lazyListState.firstVisibleItemIndex } }
|
||||||
|
val isScrollFinished by remember { derivedStateOf { !lazyListState.isScrollInProgress } }
|
||||||
|
val shouldAutoScrollToBottom by remember { derivedStateOf { lazyListState.firstVisibleItemIndex < 2 } }
|
||||||
|
|
||||||
|
LaunchedEffect(timelineItems, firstVisibleItemIndex, isScrollFinished) {
|
||||||
|
if (!isScrollFinished) return@LaunchedEffect
|
||||||
|
|
||||||
|
// Notify the parent composable about the first visible item index when scrolling finishes
|
||||||
|
onScrollFinishedAt(firstVisibleItemIndex)
|
||||||
|
|
||||||
// Auto-scroll when new timeline items appear
|
// Auto-scroll when new timeline items appear
|
||||||
LaunchedEffect(timelineItems, firstVisibleItemIndex) {
|
if (shouldAutoScrollToBottom) {
|
||||||
if (!lazyListState.isScrollInProgress &&
|
coroutineScope.launch {
|
||||||
firstVisibleItemIndex < 2
|
|
||||||
) coroutineScope.launch {
|
|
||||||
lazyListState.animateScrollToItem(0)
|
lazyListState.animateScrollToItem(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Jump to bottom button
|
// Jump to bottom button
|
||||||
if (firstVisibleItemIndex > 2) {
|
if (!shouldAutoScrollToBottom) {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
|
|||||||
Reference in New Issue
Block a user