qml: improve initialization sequence in ExpandGridView

only set initialization flag after component is completed, try to avoid forceRelayout
This commit is contained in:
Prince Gupta 2024-03-19 22:52:29 +05:30 committed by Steve Lhomme
parent d0fdb21e36
commit c1e3248411
1 changed files with 15 additions and 6 deletions

View File

@ -177,7 +177,10 @@ FocusScope {
// Events
Component.onCompleted: flickable.layout(true)
Component.onCompleted: {
if (_initialize())
flickable.layout(true)
}
onHeightChanged: flickable.layout(false)
@ -493,15 +496,21 @@ FocusScope {
// Private
// returns true if this requires forceLayout
function _initialize() {
if (_isInitialised)
return;
if (flickable.width === 0 || flickable.height === 0)
return;
if (currentIndex !== 0)
positionViewAtIndex(currentIndex, ItemView.Contain)
_isInitialised = true;
if (flickable.width === 0 || flickable.height === 0)
return false;
if (currentIndex !== 0) {
positionViewAtIndex(currentIndex, ItemView.Contain)
return false; // positionViewAtIndex will cause layout
}
return true
}
function _calculateCurrentRange() {
@ -900,7 +909,7 @@ FocusScope {
if (flickable.width === 0 || flickable.height === 0)
return
else if (!root._isInitialised)
root._initialize()
return
root.rowX = getItemPos(0)[0]