on xenial help sign in
Rework how we set the ranges so we get some more asynchronousity from item views
f45a574Albert Astals
qml/Dash/CardGrid.qml−1
@@ -59,7 +59,6 @@ DashRenderer {
59 id: loader
59 id: loader
60 sourceComponent: cardTool.cardComponent
60 sourceComponent: cardTool.cardComponent
61 anchors.horizontalCenter: parent.horizontalCenter
61 anchors.horizontalCenter: parent.horizontalCenter
62− asynchronous: true
63 onLoaded: {
62 onLoaded: {
64 item.objectName = "delegate" + index;
63 item.objectName = "delegate" + index;
65 item.width = Qt.binding(function() { return cardTool.cardWidth; });
64 item.width = Qt.binding(function() { return cardTool.cardWidth; });
qml/Dash/DashContent.qml+2
@@ -153,6 +153,7 @@ Item {
153
153
154 delegate:
154 delegate:
155 Loader {
155 Loader {
156+ id: loader
156 width: ListView.view.width
157 width: ListView.view.width
157 height: ListView.view.height
158 height: ListView.view.height
158 opacity: { // hide delegate if offscreen
159 opacity: { // hide delegate if offscreen
@@ -181,6 +182,7 @@ Item {
181 dashContent.scopeLoaded(item.scope.id)
182 dashContent.scopeLoaded(item.scope.id)
182 item.paginationCount = Qt.binding(function() { return dashContentList.count } )
183 item.paginationCount = Qt.binding(function() { return dashContentList.count } )
183 item.paginationIndex = Qt.binding(function() { return dashContentList.currentIndex } )
184 item.paginationIndex = Qt.binding(function() { return dashContentList.currentIndex } )
185+ item.visibleToParent = Qt.binding(function() { return loader.opacity != 0 });
184 item.holdingList = dashContentList;
186 item.holdingList = dashContentList;
185 item.forceNonInteractive = Qt.binding(function() { return dashContent.forceNonInteractive } )
187 item.forceNonInteractive = Qt.binding(function() { return dashContent.forceNonInteractive } )
186 }
188 }
qml/Dash/GenericScopeView.qml+39−16
@@ -38,6 +38,7 @@ FocusScope {
38 readonly property alias subPageShown: subPageLoader.subPageShown
38 readonly property alias subPageShown: subPageLoader.subPageShown
39 property int paginationCount: 0
39 property int paginationCount: 0
40 property int paginationIndex: 0
40 property int paginationIndex: 0
41+ property bool visibleToParent: false
41 property alias pageHeaderTotallyVisible: categoryView.pageHeaderTotallyVisible
42 property alias pageHeaderTotallyVisible: categoryView.pageHeaderTotallyVisible
42 property var holdingList: null
43 property var holdingList: null
43
44
@@ -357,6 +358,7 @@ FocusScope {
357 Connections {
358 Connections {
358 target: scopeView
359 target: scopeView
359 onIsCurrentChanged: rendererLoader.updateRanges();
360 onIsCurrentChanged: rendererLoader.updateRanges();
361+ onVisibleToParentChanged: rendererLoader.updateRanges();
360 }
362 }
361 Connections {
363 Connections {
362 target: holdingList
364 target: holdingList
@@ -364,7 +366,9 @@ FocusScope {
364 }
366 }
365
367
366 function updateRanges() {
368 function updateRanges() {
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
367− if (holdingList && holdingList.moving) {
371+ if (holdingList && holdingList.moving && !scopeView.visibleToParent) {
368 return;
372 return;
369 }
373 }
370
374
@@ -380,26 +384,45 @@ FocusScope {
380 }
384 }
381
385
382 if (item && item.hasOwnProperty("displayMarginBeginning")) {
386 if (item && item.hasOwnProperty("displayMarginBeginning")) {
383− // A item view is considered visible from
387+ // A item view creates its delegates synchronously from
384 // -displayMarginBeginning
388 // -displayMarginBeginning
385 // to
389 // to
386− // height + item.displayMarginEnd
390+ // height + displayMarginEnd
391+ // Around that area it adds the cacheBuffer area where delegates are created async
392+ //
387 // We adjust displayMarginBeginning and displayMarginEnd so
393 // We adjust displayMarginBeginning and displayMarginEnd so
388− // * In non visible scopes only the viewport is considered visible
394+ // * In non visible scopes nothing is considered visible and we set cacheBuffer
389− // that way when you switch to it the visible items are there
395+ // so that creates the items that would be in the viewport asynchronously
390− // * For visible scopes we increase the visible range by categoryView.height * 1.5
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
391− // in both directions to make scrolling nicer by mantaining a higher number of
398+ // to make scrolling nicer by mantaining a higher number of
392 // cached items
399 // cached items
393− // TODO Improvements
400+ // * For non current but visible scopes (i.e. when the user changes from one scope
394− // - For non visible scopes we should always have a visible range of 0 and
401+ // to the next, we set the visible range to the viewport so
395− // make sure the items in the viewport are created with the cache buffer feature
402+ // items are not culled (invisible) but still use no cacheBuffer
396− // - For visible scopes we should always the have a visible range be exactly the
403+ // (it will be set once the scope is the current one)
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));
404+ var displayMarginBeginning = Math.round(-Math.max(-baseItem.y, 0));
401− item.displayMarginEnd = -Math.round(Math.max(baseItem.height - extraMargins - seeAll.height -
405+ var displayMarginEnd = -Math.round(Math.max(baseItem.height - seeAll.height -
402 categoryView.height + baseItem.y, 0));
406 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+ }
403 }
426 }
404 }
427 }
405 }
428 }