feat: only show the scrollDown when scrolled up 400 pixels

This commit is contained in:
Jonathan Rainville 2020-09-29 12:52:23 -04:00 committed by Iuri Matias
parent 3881d1e012
commit 9acb6609ab
1 changed files with 6 additions and 12 deletions

View File

@ -40,9 +40,10 @@ ScrollView {
Button { Button {
readonly property int buttonPadding: 5 readonly property int buttonPadding: 5
id: newMessagesBox id: scrollDownButton
visible: false
height: 32 height: 32
width: nbMessages.width + arrowImage.width + 2 * Style.current.halfPadding + (nbMessages.visible ? newMessagesBox.buttonPadding : 0) width: nbMessages.width + arrowImage.width + 2 * Style.current.halfPadding + (nbMessages.visible ? scrollDownButton.buttonPadding : 0)
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: Style.current.padding anchors.rightMargin: Style.current.padding
@ -53,7 +54,7 @@ ScrollView {
} }
onClicked: { onClicked: {
root.newMessages = 0 root.newMessages = 0
newMessagesBox.visible = false scrollDownButton.visible = false
chatLogView.scrollToBottom(true) chatLogView.scrollToBottom(true)
} }
@ -76,7 +77,7 @@ ScrollView {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.left: nbMessages.right anchors.left: nbMessages.right
source: "../../../img/leave_chat.svg" source: "../../../img/leave_chat.svg"
anchors.leftMargin: nbMessages.visible ? newMessagesBox.buttonPadding : 0 anchors.leftMargin: nbMessages.visible ? scrollDownButton.buttonPadding : 0
rotation: -90 rotation: -90
ColorOverlay { ColorOverlay {
@ -93,14 +94,6 @@ ScrollView {
} }
} }
onAtYEndChanged: {
if (chatLogView.atYEnd) {
newMessagesBox.visible = false
} else {
newMessagesBox.visible = true
}
}
function scrollToBottom(force, caller) { function scrollToBottom(force, caller) {
if (!force && !chatLogView.atYEnd) { if (!force && !chatLogView.atYEnd) {
// User has scrolled up, we don't want to scroll back // User has scrolled up, we don't want to scroll back
@ -163,6 +156,7 @@ ScrollView {
}); });
onContentYChanged: { onContentYChanged: {
scrollDownButton.visible = (contentHeight - (scrollY + height) > 400)
if(scrollY < 500){ if(scrollY < 500){
loadMsgs(); loadMsgs();
} }