diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-01-06 18:08:01 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2020-01-06 18:29:08 +0100 |
commit | 51d7e6499269af9106a8e36a25eb9ac1dfd8c57d (patch) | |
tree | 6fb2e636a83339398f808675887c130960a2ca68 /resources/qml/TimelineView.qml | |
parent | Use fetchMore for native lazy loading of item model data (diff) | |
download | nheko-51d7e6499269af9106a8e36a25eb9ac1dfd8c57d.tar.xz |
Simplify read message logic with inverted timeline
Diffstat (limited to 'resources/qml/TimelineView.qml')
-rw-r--r-- | resources/qml/TimelineView.qml | 58 |
1 files changed, 12 insertions, 46 deletions
diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 18ae3793..0be8609d 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -31,6 +31,7 @@ Item { running: timelineManager.isInitialSync height: 200 width: 200 + z: 3 } ListView { @@ -48,8 +49,6 @@ Item { boundsBehavior: Flickable.StopAtBounds - onVerticalOvershootChanged: contentY = contentY - verticalOvershoot - MouseArea { anchors.fill: parent acceptedButtons: Qt.NoButton @@ -60,18 +59,7 @@ Item { chat.contentY = chat.contentY - wheel.angleDelta.y wheel.accepted = true chat.forceLayout() - chat.updatePosition() - } - } - } - - onModelChanged: { - if (model) { - currentIndex = model.currentIndex - if (model.currentIndex == count - 1) { - positionViewAtEnd() - } else { - positionViewAtIndex(model.currentIndex, ListView.End) + chat.returnToBounds() } } } @@ -82,37 +70,13 @@ Item { anchors.top: chat.top anchors.left: chat.right anchors.bottom: chat.bottom - onPressedChanged: if (!pressed) chat.updatePosition() - } - - property bool atBottom: false - onCountChanged: { - if (atBottom) { - var newIndex = count - 1 // last index - positionViewAtEnd() - currentIndex = newIndex - model.currentIndex = newIndex - } } - onAtYBeginningChanged: if (atYBeginning) { chat.model.currentIndex = 0; chat.currentIndex = 0; } - - function updatePosition() { - for (var y = chat.contentY + chat.height; y > chat.height; y -= 9) { - var i = chat.itemAt(100, y); - if (!i) continue; - if (!i.isFullyVisible()) continue; - chat.model.currentIndex = i.getIndex(); - chat.currentIndex = i.getIndex() - atBottom = i.getIndex() == count - 1; - break; - } - } - onMovementEnded: updatePosition() - spacing: 4 verticalLayoutDirection: ListView.BottomToTop + onCountChanged: if (atYEnd) model.currentIndex = 0 // Mark last event as read, since we are at the bottom + delegate: Rectangle { // This would normally be previousSection, but our model's order is inverted. property bool sectionBoundary: (ListView.nextSection != "" && ListView.nextSection !== ListView.section) || model.index === chat.count - 1 @@ -126,12 +90,6 @@ Item { id: timelinerow y: section ? section.y + section.height : 0 } - function isFullyVisible() { - return height > 1 && (y - chat.contentY - 1) + height < chat.height - } - function getIndex() { - return index; - } onSectionBoundaryChanged: { if (sectionBoundary) { @@ -147,6 +105,14 @@ Item { } } + Binding { + target: chat.model + property: "currentIndex" + when: y + height > chat.contentY + chat.height && y < chat.contentY + chat.height + value: index + delayed: true + } + } section { |