@@ -91,6 +91,7 @@
9191
9292#include "listviewwithpageheader.h"
9393
94+#include <QCoreApplication>
9495#include <QDebug>
9596#include <qqmlinfo.h>
9697#include <qqmlengine.h>
@@ -484,6 +485,11 @@ void ListViewWithPageHeader::componentComplete()
484485 polish();
485486}
486487
488+static inline bool uFuzzyCompare(qreal r1, qreal r2)
489+{
490+ return qFuzzyCompare(r1, r2) || (qFuzzyIsNull(r1) && qFuzzyIsNull(r2));
491+}
492+
487493void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
488494{
489495 // Check we are not being taken down and don't paint anything
@@ -498,11 +504,7 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
498504 const bool showHeaderAnimationRunning = m_contentYAnimation->isRunning() && contentYAnimationType == ContentYAnimationShowHeader;
499505 if (m_headerItem) {
500506 const auto oldHeaderItemShownHeight = m_headerItemShownHeight;
501− if (contentY() < -m_minYExtent) {
502− // Stick the header item to the top when dragging down
503− m_headerItem->setY(contentY());
504− m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
505− } else {
507+ if (uFuzzyCompare(contentY(), -m_minYExtent) || contentY() > -m_minYExtent) {
506508 m_headerItem->setHeight(m_headerItem->implicitHeight());
507509 // We are going down (but it's not because of the rebound at the end)
508510 // (but the header was not shown by it's own position)
@@ -516,21 +518,32 @@ void ListViewWithPageHeader::viewportMoved(Qt::Orientations orient)
516518 m_headerItemShownHeight = 0;
517519 m_headerItem->setY(-m_minYExtent);
518520 } else if ((scrolledUp && notRebounding && notShownByItsOwn && !maximizeVisibleAreaRunning) || (m_headerItemShownHeight > 0) || m_inContentHeightKeepHeaderShown) {
519− if (maximizeVisibleAreaRunning && diff > 0) // If we are maximizing and the header was shown, make sure we hide it
521+ if (maximizeVisibleAreaRunning && diff > 0) {
522+ // If we are maximizing and the header was shown, make sure we hide it
520523 m_headerItemShownHeight -= diff;
521− else
524+ } else {
522525 m_headerItemShownHeight += diff;
523− if (contentY() == -m_minYExtent) {
526+ }
527+ if (uFuzzyCompare(contentY(), -m_minYExtent)) {
524528 m_headerItemShownHeight = 0;
525529 } else {
526530 m_headerItemShownHeight = qBound(static_cast<qreal>(0.), m_headerItemShownHeight, m_headerItem->height());
527531 }
528532 if (m_headerItemShownHeight > 0) {
529− m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
533+ if (uFuzzyCompare(m_headerItem->height(), m_headerItemShownHeight)) {
534+ m_headerItem->setY(contentY());
535+ m_headerItemShownHeight = m_headerItem->height();
536+ } else {
537+ m_headerItem->setY(contentY() - m_headerItem->height() + m_headerItemShownHeight);
538+ }
530539 } else {
531540 m_headerItem->setY(-m_minYExtent);
532541 }
533542 }
543+ } else {
544+ // Stick the header item to the top when dragging down
545+ m_headerItem->setY(contentY());
546+ m_headerItem->setHeight(m_headerItem->implicitHeight() + (-m_minYExtent - contentY()));
534547 }
535548 // We will be changing the clip item, need to accomadate for it
536549 // otherwise we move the firstItem down/up twice (unless the
@@ -1135,7 +1148,12 @@ void ListViewWithPageHeader::adjustMinYExtent()
11351148 nonCreatedHeight = m_firstVisibleIndex * visibleItemsHeight / visibleItems;
11361149// qDebug() << m_firstVisibleIndex << visibleItemsHeight << visibleItems << nonCreatedHeight;
11371150 }
1138− m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + (m_headerItem ? m_headerItem->implicitHeight() : 0);
1151+ const qreal headerHeight = (m_headerItem ? m_headerItem->implicitHeight() : 0);
1152+ m_minYExtent = nonCreatedHeight - m_visibleItems.first()->y() - m_clipItem->y() + headerHeight;
1153+ if (m_minYExtent != 0 && qFuzzyIsNull(m_minYExtent)) {
1154+ m_minYExtent = 0;
1155+ m_visibleItems.first()->setY(nonCreatedHeight - m_clipItem->y() + headerHeight);
1156+ }
11391157 }
11401158}
11411159
@@ -1271,6 +1289,11 @@ void ListViewWithPageHeader::updatePolish()
12711289 refill();
12721290
12731291 if (m_contentHeightDirty) {
1292+ // We need to make sure all bindings have updated otherwise
1293+ // we may end up with bindings updating when we call setContentHeight
1294+ // and then everything gets out of sync, i.e. testHeaderPositionBug1240118
1295+ QCoreApplication::instance()->processEvents();
1296+
12741297 qreal contentHeight;
12751298 if (m_visibleItems.isEmpty()) {
12761299 contentHeight = m_headerItem ? m_headerItem->height() : 0;