mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-2966 Chats | Fix | Enhance auto-scroll-to-bottom behavior (#2413)
This commit is contained in:
parent
b2248869df
commit
6a46ddb8d8
1 changed files with 33 additions and 15 deletions
|
@ -433,6 +433,21 @@ fun ChatScreen(
|
|||
}
|
||||
}
|
||||
|
||||
// Jump to bottom button shows up when user scrolls past a threshold.
|
||||
// Convert to pixels:
|
||||
val jumpThreshold = with(LocalDensity.current) {
|
||||
JumpToBottomThreshold.toPx()
|
||||
}
|
||||
|
||||
// Show the button if the first visible item is not the first one or if the offset is
|
||||
// greater than the threshold.
|
||||
val jumpToBottomButtonEnabled by remember {
|
||||
derivedStateOf {
|
||||
lazyListState.firstVisibleItemIndex != 0 ||
|
||||
lazyListState.firstVisibleItemScrollOffset > jumpThreshold
|
||||
}
|
||||
}
|
||||
|
||||
val isAtBottom by remember {
|
||||
derivedStateOf {
|
||||
lazyListState.firstVisibleItemIndex == 0 &&
|
||||
|
@ -440,10 +455,27 @@ fun ChatScreen(
|
|||
}
|
||||
}
|
||||
|
||||
var wasAtBottom by remember { mutableStateOf(isAtBottom) }
|
||||
|
||||
LaunchedEffect(lazyListState) {
|
||||
snapshotFlow {
|
||||
val layoutInfo = lazyListState.layoutInfo
|
||||
layoutInfo.visibleItemsInfo.firstOrNull()?.index == 0 &&
|
||||
layoutInfo.visibleItemsInfo.firstOrNull()?.offset == 0
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.collect { atBottom ->
|
||||
wasAtBottom = atBottom
|
||||
Timber.d("DROID-2966 Updated wasAtBottom: $wasAtBottom")
|
||||
}
|
||||
}
|
||||
|
||||
// Scrolling to bottom when list size changes and we are at the bottom of the list
|
||||
LaunchedEffect(messages.size) {
|
||||
if (isAtBottom && !isPerformingScrollIntent.value) {
|
||||
if (wasAtBottom && !isPerformingScrollIntent.value) {
|
||||
lazyListState.animateScrollToItem(0)
|
||||
} else {
|
||||
Timber.d("DROID-2966 Skipping auto-scroll")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -497,20 +529,6 @@ fun ChatScreen(
|
|||
onMentionClicked = onMentionClicked,
|
||||
onScrollToReplyClicked = onScrollToReplyClicked
|
||||
)
|
||||
// Jump to bottom button shows up when user scrolls past a threshold.
|
||||
// Convert to pixels:
|
||||
val jumpThreshold = with(LocalDensity.current) {
|
||||
JumpToBottomThreshold.toPx()
|
||||
}
|
||||
|
||||
// Show the button if the first visible item is not the first one or if the offset is
|
||||
// greater than the threshold.
|
||||
val jumpToBottomButtonEnabled by remember {
|
||||
derivedStateOf {
|
||||
lazyListState.firstVisibleItemIndex != 0 ||
|
||||
lazyListState.firstVisibleItemScrollOffset > jumpThreshold
|
||||
}
|
||||
}
|
||||
|
||||
GoToBottomButton(
|
||||
modifier = Modifier
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue