[app] Avoid unpleasant flicking when pages are being dragged

This commit is contained in:
Slava Monich 2020-09-17 01:44:58 +03:00
parent 429c58efb0
commit 19c28e5c51

View file

@ -177,31 +177,20 @@ SilicaFlickable {
} }
onCurrentPageChanged: { onCurrentPageChanged: {
if (completed && !flicking && !scrollAnimation.running) { if (completed && !moving && !scrollAnimation.running) {
bookViewWatcher.positionViewAtIndex(currentPage) bookViewWatcher.positionViewAtIndex(currentPage)
} }
} }
onFlickingChanged: { onCurrentIndexChanged: {
if (!flicking) { if (completed && !moving && currentIndex >= 0) {
bookViewWatcher.updateModel() updateModel()
} }
} }
ListWatcher { onMovingChanged: {
id: bookViewWatcher if (!moving) {
listView: bookView updateModel()
onCurrentIndexChanged: {
if (listView.completed && !listView.flicking && currentIndex >= 0) {
updateModel()
}
}
function updateModel() {
hideViews()
stackModel.currentPage = currentIndex
if (!pager.pressed) {
pager.currentPage = currentIndex
}
} }
} }
@ -219,7 +208,7 @@ SilicaFlickable {
rightSpaceReserved: pageTools.visible ? pageTools.rightSpaceUsed: 0 rightSpaceReserved: pageTools.visible ? pageTools.rightSpaceUsed: 0
titleVisible: _currentState.title titleVisible: _currentState.title
pageNumberVisible: _currentState.page pageNumberVisible: _currentState.page
currentPage: bookViewWatcher.currentIndex === index currentPage: ListView.isCurrentItem
title: bookModel.title title: bookModel.title
onJumpToPage: bookView.jumpTo(page) onJumpToPage: bookView.jumpTo(page)
onPushPosition: stackModel.pushPosition(position) // bookView.jumpTo(page) onPushPosition: stackModel.pushPosition(position) // bookView.jumpTo(page)
@ -261,12 +250,12 @@ SilicaFlickable {
property int jumpingTo: -1 property int jumpingTo: -1
function jumpTo(page) { function jumpTo(page) {
if (book && page >=0 && page !== bookViewWatcher.currentIndex) { if (book && page >=0 && page !== currentIndex) {
jumpingTo = page jumpingTo = page
bookViewWatcher.positionViewAtIndex(page) bookViewWatcher.positionViewAtIndex(page)
pager.currentPage = page pager.currentPage = page
jumpingTo = -1 jumpingTo = -1
if (bookViewWatcher.currentIndex !== page) { if (currentIndex !== page) {
console.log("oops, still at", currentPage) console.log("oops, still at", currentPage)
resetPager.restart() resetPager.restart()
} }
@ -291,6 +280,19 @@ SilicaFlickable {
} }
} }
function updateModel() {
hideViews()
stackModel.currentPage = currentIndex
if (!pager.pressed) {
pager.currentPage = currentIndex
}
}
ListWatcher {
id: bookViewWatcher
listView: bookView
}
NumberAnimation { NumberAnimation {
id: scrollAnimation id: scrollAnimation
target: bookView target: bookView
@ -305,8 +307,8 @@ SilicaFlickable {
id: resetPager id: resetPager
interval: 0 interval: 0
onTriggered: { onTriggered: {
console.log("resetting pager to", bookViewWatcher.currentIndex) console.log("resetting pager to", bookView.currentIndex)
pager.currentPage = bookViewWatcher.currentIndex pager.currentPage = bookView.currentIndex
} }
} }