Skip to content

Commit

Permalink
Merge pull request #107 from maralorn/fix-scrolling
Browse files Browse the repository at this point in the history
Fix scrollToBottom
  • Loading branch information
KitsuneRal committed Oct 26, 2016
2 parents 2a58ec2 + 37a0b15 commit 4665483
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions client/qml/chat.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,23 @@ Rectangle {

signal getPreviousContent()

Timer{
id: scrollTimer
interval: 0
onTriggered: reallyScrollToBottom()
}

function reallyScrollToBottom() {
if (chatView.stickToBottom && !chatView.nowAtYEnd)
{
chatView.positionViewAtEnd()
scrollToBottom()
}
}

function scrollToBottom() {
chatView.positionViewAtEnd();
chatView.stickToBottom = true
scrollTimer.running = true
}

ListView {
Expand All @@ -28,25 +43,15 @@ Rectangle {
pixelAligned: true
// FIXME: atYEnd is glitchy on Qt 5.2.1
property bool nowAtYEnd: contentY - originY + height >= contentHeight
property bool wasAtEndY: true

function aboutToBeInserted() {
wasAtEndY = nowAtYEnd;
console.log("aboutToBeInserted! nowAtYEnd=" + nowAtYEnd);
}
property bool stickToBottom: true

function rowsInserted() {
if( wasAtEndY )
{
if( stickToBottom )
root.scrollToBottom();
} else {
console.log("was not at end, not scrolling");
}
}

Component.onCompleted: {
console.log("onCompleted");
model.rowsAboutToBeInserted.connect(aboutToBeInserted);
model.rowsInserted.connect(rowsInserted);
}

Expand All @@ -62,6 +67,16 @@ Rectangle {
}
}

onHeightChanged: {
if( stickToBottom )
root.scrollToBottom();
}

onContentHeightChanged: {
if( stickToBottom )
root.scrollToBottom();
}

onContentYChanged: {
if( (this.contentY - this.originY) < 5 )
{
Expand All @@ -70,6 +85,15 @@ Rectangle {
}

}

onMovementStarted: {
stickToBottom = false;
}

onMovementEnded: {
stickToBottom = nowAtYEnd;
}

}

Slider {
Expand Down

0 comments on commit 4665483

Please sign in to comment.