Add hack around atYEnd

This fixes the annoying "I just scrolled down to the bottom, how come
NeoChat doesn't think I did?"

From what I can tell this is also ListView bug (or something caused by
our style/Kirigami) that creates cases like contentY being -643.2 (for a
ListView of height 643) thus that's not "at Y's end". For our case
though, we don't care and can safely round it.
This commit is contained in:
Joshua Goins
2026-01-16 17:07:03 -05:00
parent 136063bd37
commit 3c77711417

View File

@@ -83,6 +83,9 @@ QQC2.ScrollView {
ListView { ListView {
id: messageListView id: messageListView
// HACK: Use this instead of atYEnd to handle cases like -643.2 at height of 643 not being counted as "at the beginning"
readonly property bool closeToYEnd: -Math.round(contentY) >= height
/** /**
* @brief Whether all unread messages in the timeline are visible. * @brief Whether all unread messages in the timeline are visible.
*/ */
@@ -130,7 +133,7 @@ QQC2.ScrollView {
Shortcut { Shortcut {
sequences: [ StandardKey.Cancel ] sequences: [ StandardKey.Cancel ]
onActivated: { onActivated: {
if (!messageListView.atYEnd || !_private.room.partiallyReadStats.empty()) { if (!messageListView.closeToYEnd || !_private.room.partiallyReadStats.empty()) {
messageListView.positionViewAtBeginning(); messageListView.positionViewAtBeginning();
} else { } else {
(root.Kirigami.PageStack.pageStack as Kirigami.PageRow).get(0).forceActiveFocus(); (root.Kirigami.PageStack.pageStack as Kirigami.PageRow).get(0).forceActiveFocus();
@@ -179,12 +182,12 @@ QQC2.ScrollView {
} }
} }
onAtYEndChanged: if (atYEnd && _private.hasScrolledUpBefore) { onCloseToYEndChanged: if (closeToYEnd && _private.hasScrolledUpBefore) {
if (QQC2.ApplicationWindow.window && (QQC2.ApplicationWindow.window.visibility !== QQC2.ApplicationWindow.Hidden)) { if (QQC2.ApplicationWindow.window && (QQC2.ApplicationWindow.window.visibility !== QQC2.ApplicationWindow.Hidden)) {
_private.room.markAllMessagesAsRead(); _private.room.markAllMessagesAsRead();
} }
_private.hasScrolledUpBefore = false; _private.hasScrolledUpBefore = false;
} else if (!atYEnd) { } else if (!closeToYEnd) {
_private.hasScrolledUpBefore = true; _private.hasScrolledUpBefore = true;
} }
@@ -269,7 +272,7 @@ QQC2.ScrollView {
padding: Kirigami.Units.largeSpacing padding: Kirigami.Units.largeSpacing
z: 2 z: 2
visible: !messageListView.atYEnd visible: !messageListView.closeToYEnd
text: i18nc("@action:button", "Jump to latest message") text: i18nc("@action:button", "Jump to latest message")