on xenial help sign in
Rework how we set the ranges so we get some more asynchronousity from item views
commitf45a5746cc6691c890dfbe9456aa5037ae411283 authorAlbert Astals <albert.astals@canonical.com> dateWed 12 Nov 2014, 10:41 (12 years ago) parent882dbdf
3 files changed+41−17
qml/Dash/CardGrid.qml−1 qml/Dash/DashContent.qml+2 qml/Dash/GenericScopeView.qml+39−16
qml/Dash/CardGrid.qml−1
@@ -59,7 +59,6 @@ DashRenderer {
5959 id: loader
6060 sourceComponent: cardTool.cardComponent
6161 anchors.horizontalCenter: parent.horizontalCenter
62− asynchronous: true
6362 onLoaded: {
6463 item.objectName = "delegate" + index;
6564 item.width = Qt.binding(function() { return cardTool.cardWidth; });
qml/Dash/DashContent.qml+2
@@ -153,6 +153,7 @@ Item {
153153
154154 delegate:
155155 Loader {
156+ id: loader
156157 width: ListView.view.width
157158 height: ListView.view.height
158159 opacity: { // hide delegate if offscreen
@@ -181,6 +182,7 @@ Item {
181182 dashContent.scopeLoaded(item.scope.id)
182183 item.paginationCount = Qt.binding(function() { return dashContentList.count } )
183184 item.paginationIndex = Qt.binding(function() { return dashContentList.currentIndex } )
185+ item.visibleToParent = Qt.binding(function() { return loader.opacity != 0 });
184186 item.holdingList = dashContentList;
185187 item.forceNonInteractive = Qt.binding(function() { return dashContent.forceNonInteractive } )
186188 }
qml/Dash/GenericScopeView.qml+39−16
@@ -38,6 +38,7 @@ FocusScope {
3838 readonly property alias subPageShown: subPageLoader.subPageShown
3939 property int paginationCount: 0
4040 property int paginationIndex: 0
41+ property bool visibleToParent: false
4142 property alias pageHeaderTotallyVisible: categoryView.pageHeaderTotallyVisible
4243 property var holdingList: null
4344
@@ -357,6 +358,7 @@ FocusScope {
357358 Connections {
358359 target: scopeView
359360 onIsCurrentChanged: rendererLoader.updateRanges();
361+ onVisibleToParentChanged: rendererLoader.updateRanges();
360362 }
361363 Connections {
362364 target: holdingList
@@ -364,7 +366,9 @@ FocusScope {
364366 }
365367
366368 function updateRanges() {
367− if (holdingList && holdingList.moving) {
369+ // Don't want to create stress by requesting more items during scope
370+ // changes so unless you're not part of the visible scopes just return
371+ if (holdingList && holdingList.moving && !scopeView.visibleToParent) {
368372 return;
369373 }
370374
@@ -380,26 +384,45 @@ FocusScope {
380384 }
381385
382386 if (item && item.hasOwnProperty("displayMarginBeginning")) {
383− // A item view is considered visible from
387+ // A item view creates its delegates synchronously from
384388 // -displayMarginBeginning
385389 // to
386− // height + item.displayMarginEnd
390+ // height + displayMarginEnd
391+ // Around that area it adds the cacheBuffer area where delegates are created async
392+ //
387393 // We adjust displayMarginBeginning and displayMarginEnd so
388− // * In non visible scopes only the viewport is considered visible
389− // that way when you switch to it the visible items are there
390− // * For visible scopes we increase the visible range by categoryView.height * 1.5
391− // in both directions to make scrolling nicer by mantaining a higher number of
394+ // * In non visible scopes nothing is considered visible and we set cacheBuffer
395+ // so that creates the items that would be in the viewport asynchronously
396+ // * For the current scope set the visible range to the viewport and then
397+ // use cacheBuffer to create extra items for categoryView.height * 1.5
398+ // to make scrolling nicer by mantaining a higher number of
392399 // cached items
393− // TODO Improvements
394− // - For non visible scopes we should always have a visible range of 0 and
395− // make sure the items in the viewport are created with the cache buffer feature
396− // - For visible scopes we should always the have a visible range be exactly the
397− // viewport and make sure the rest of items are created with the cache buffer feature
398− var extraMargins = scopeView.isCurrent ? categoryView.height * 1.5 : 0;
399−
400− item.displayMarginBeginning = Math.round(-Math.max(-baseItem.y - extraMargins, 0));
401− item.displayMarginEnd = -Math.round(Math.max(baseItem.height - extraMargins - seeAll.height -
400+ // * For non current but visible scopes (i.e. when the user changes from one scope
401+ // to the next, we set the visible range to the viewport so
402+ // items are not culled (invisible) but still use no cacheBuffer
403+ // (it will be set once the scope is the current one)
404+ var displayMarginBeginning = Math.round(-Math.max(-baseItem.y, 0));
405+ var displayMarginEnd = -Math.round(Math.max(baseItem.height - seeAll.height -
402406 categoryView.height + baseItem.y, 0));
407+ if (scopeView.isCurrent || scopeView.visibleToParent) {
408+ item.displayMarginBeginning = displayMarginBeginning;
409+ item.displayMarginEnd = displayMarginEnd;
410+ item.cacheBuffer = scopeView.isCurrent ? categoryView.height * 1.5 : 0;
411+ } else {
412+ var visibleRange = baseItem.height + displayMarginEnd - displayMarginBeginning;
413+ if (visibleRange < 0) {
414+ item.displayMarginBeginning = displayMarginBeginning;
415+ item.displayMarginEnd = displayMarginEnd;
416+ item.cacheBuffer = 0;
417+ } else {
418+ // This should be visibleRange/2 in each of the properties
419+ // but some item views still (like GridView) like creating sync delegates even if
420+ // the visible range is 0 so let's make sure the visible range is negative
421+ item.displayMarginBeginning = displayMarginBeginning - visibleRange;
422+ item.displayMarginEnd = displayMarginEnd - visibleRange;
423+ item.cacheBuffer = visibleRange;
424+ }
425+ }
403426 }
404427 }
405428 }