@@ -91,6 +91,7 @@
9191
9292#include "listviewwithpageheader.h"
9393
94+#include <QCoreApplication>
9495#include <QDebug>
9596#include <qqmlinfo.h>
9697#include <qqmlengine.h>
@@ -477,6 +478,11 @@ void ListViewWithPageHeader::componentComplete()
477478 polish();
478479}
479480
481+static inline bool uFuzzyCompare(qreal r1, qreal r2)
482+{
483+ return qFuzzyCompare(r1, r2) || (qFuzzyIsNull(r1) && qFuzzyIsNull(r2));
484+}
485+
480486void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
481487{
482488 // Check we are not being taken down and don't paint anything
@@ -491,11 +497,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
491497 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
492498 if (m_headerItem) {
493499 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
494− if (contentY() < -m_minYExtent) {
495− // Stick the header item to the top when dragging down
496− m_headerItem->setY(contentY());
497− m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
498− } else {
500+ if (uFuzzyCompare(contentY(), -m_minYExtent) || contentY() > -m_minYExtent) {
499501 m_headerItem->setHeight(m_headerItem->implicitHeight());
500502 // We are going down (but it's not because of the rebound at the end)
501503 // (but the header was not shown by it's own position)
@@ -509,21 +511,32 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
509511 m_headerItemShownHeight = 0;
510512 m_headerItem->setY(-m_minYExtent);
511513 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
512− if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
514+ if (maximizeVisibleAreaRunning && diff > 0) {
515+ // If we are maximizing and the header was shown, make sure we hide it
513516 m_headerItemShownHeight -= diff;
514− else
517+ } else {
515518 m_headerItemShownHeight += diff;
516− if (contentY() == -m_minYExtent) {
519+ }
520+ if (uFuzzyCompare(contentY(), -m_minYExtent)) {
517521 m_headerItemShownHeight = 0;
518522 } else {
519523 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
520524 }
521525 if (m_headerItemShownHeight > 0) {
522− m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
526+ if (uFuzzyCompare(m_headerItem->height(), m_headerItemShownHeight)) {
527+ m_headerItem->setY(contentY());
528+ m_headerItemShownHeight = m_headerItem->height();
529+ } else {
530+ m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
531+ }
523532 } else {
524533 m_headerItem->setY(-m_minYExtent);
525534 }
526535 }
536+ } else {
537+ // Stick the header item to the top when dragging down
538+ m_headerItem->setY(contentY());
539+ m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
527540 }
528541 // We will be changing the clip item, need to accomadate for it
529542 // otherwise we move the firstItem down/up twice (unless the
@@ -1128,7 +1141,12 @@ void ListViewWithPageHeader::adjustMinYExtent()
11281141 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
11291142// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
11301143 }
1131− m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + (m_headerItem ? m_headerItem->implicitHeight() : 0);
1144+ const qreal headerHeight = (m_headerItem ? m_headerItem->implicitHeight() : 0);
1145+ m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + headerHeight;
1146+ if (m_minYExtent != 0 && qFuzzyIsNull(m_minYExtent)) {
1147+ m_minYExtent = 0;
1148+ m_visibleItems.first()->setY(nonCreatedHeight - m_clipItem->y() + headerHeight);
1149+ }
11321150 }
11331151}
11341152
@@ -1264,6 +1282,11 @@ void ListViewWithPageHeader::updatePolish()
12641282 refill();
12651283
12661284 if (m_contentHeightDirty) {
1285+ // We need to make sure all bindings have updated otherwise
1286+ // we may end up with bindings updating when we call setContentHeight
1287+ // and then everything gets out of sync, i.e. testHeaderPositionBug1240118
1288+ QCoreApplication::instance()->processEvents();
1289+
12671290 qreal contentHeight;
12681291 if (m_visibleItems.isEmpty()) {
12691292 contentHeight = m_headerItem ? m_headerItem->height() : 0;