Commit d37559bb authored by Ronan Abhamon's avatar Ronan Abhamon

fix(ui/modules/Common/Collapse): fix the change order of the `minimumHeight`,...

fix(ui/modules/Common/Collapse): fix the change order of the `minimumHeight`, `maximumHeight` and `height`
parent bdd17a36
......@@ -2,6 +2,7 @@ import QtQuick 2.7
import Common 1.0
import Common.Styles 1.0
import Utils 1.0
// =============================================================================
// A simple component to build collapsed item.
......@@ -12,10 +13,11 @@ Item {
// ---------------------------------------------------------------------------
property alias target: targetChanges.target
property var target
property int targetHeight
property bool _collapsed: false
property var _savedHeight
// ---------------------------------------------------------------------------
......@@ -24,7 +26,29 @@ Item {
// ---------------------------------------------------------------------------
function setCollapsed (status) {
if (_collapsed === status) {
return
}
_collapsed = status
// Warning: Unable to use `PropertyChanges` because the change order is unknown.
// It exists a bug on Ubuntu if the `height` property is changed before `minimumHeight`.
if (_collapsed) {
_savedHeight = Utils.extractProperties(target, [
'height',
'maximumHeight',
'minimumHeight'
])
target.minimumHeight = collapse.targetHeight
target.maximumHeight = Constants.sizeMax
target.height = collapse.targetHeight
} else {
target.minimumHeight = _savedHeight.minimumHeight
target.maximumHeight = _savedHeight.maximumHeight
target.height = _savedHeight.height
}
}
// ---------------------------------------------------------------------------
......@@ -32,6 +56,8 @@ Item {
implicitHeight: button.iconSize
implicitWidth: button.iconSize
property int savedHeight
ActionButton {
id: button
......@@ -40,7 +66,7 @@ Item {
iconSize: CollapseStyle.iconSize
useStates: false
onClicked: _collapsed = !_collapsed
onClicked: setCollapsed(!_collapsed)
}
// ---------------------------------------------------------------------------
......@@ -52,15 +78,6 @@ Item {
rotation: 180
target: button
}
PropertyChanges {
id: targetChanges
height: collapse.targetHeight
maximumHeight: Constants.sizeMax
maximumWidth: Constants.sizeMax
minimumHeight: collapse.targetHeight
}
}
transitions: Transition {
......
......@@ -33,7 +33,7 @@ Item {
// ---------------------------------------------------------------------------
// DO NOT TOUCH THIS PROPERTIES.
// DO NOT TOUCH THESE PROPERTIES.
// No visible.
visible: false
......
......@@ -259,6 +259,21 @@ function assert (condition, message) {
// -----------------------------------------------------------------------------
function extractProperties (obj, pattern) {
if (!pattern) {
return {}
}
var obj2 = {}
pattern.forEach(function (property) {
obj2[property] = obj[property]
})
return obj2
}
// -----------------------------------------------------------------------------
// Returns an array from a `object` or `array` argument.
function ensureArray (obj) {
if (isArray(obj)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment