Commit 4ad9688b authored by Devin Lin's avatar Devin Lin 🎨
Browse files

homescreens/halcyon: Add ability to swipe to close folder

parent 58afb6be
Pipeline #218019 passed with stage
in 1 minute and 7 seconds
......@@ -34,7 +34,6 @@ Item {
readonly property real delegateHeight: PlasmaCore.Units.gridUnit * 3
property bool folderShown: false
onFolderShownChanged: folderShown ? openFolderAnim.restart() : closeFolderAnim.restart()
signal openConfigureRequested()
......@@ -43,14 +42,21 @@ Item {
}
function closeFolder() {
if (folderShown) {
folderShown = false;
}
folderShown = false;
closeFolderAnim.restart()
}
function openFolder() {
folderShown = true;
openFolderAnim.restart()
}
FavoritesGrid {
id: favoritesGrid
property real openFolderProgress: 0
anchors.fill: parent
interactive: root.interactive
searchWidget: root.searchWidget
......@@ -64,18 +70,22 @@ Item {
onOpenConfigureRequested: root.openConfigureRequested()
onRequestOpenFolder: (folder) => {
folderGrid.folder = folder;
root.folderShown = true;
root.openFolder();
}
property real translateX: 0
property real translateX: openFolderProgress * -PlasmaCore.Units.gridUnit
transform: Translate { x: favoritesGrid.translateX }
opacity: 1 - openFolderProgress
visible: opacity !== 0
}
FolderGrid {
id: folderGrid
property real openProgress: 0
anchors.fill: parent
folder: null
folder: null
interactive: root.interactive
......@@ -89,12 +99,42 @@ Item {
onOpenConfigureRequested: root.openConfigureRequested()
onCloseRequested: root.closeFolder()
property real translateX: 0
property real translateX: (1 - openProgress) * PlasmaCore.Units.gridUnit
transform: Translate { x: folderGrid.translateX }
opacity: 0
opacity: openProgress
visible: opacity !== 0
}
// handle horizontal dragging in a folder
DragHandler {
id: dragHandler
target: folderGrid
enabled: folderGrid.visible
yAxis.enabled: false
xAxis.enabled: true
xAxis.minimum: -PlasmaCore.Units.gridUnit * 5
xAxis.maximum: 0
property real oldTranslationX
property bool isClosing: false
// when dragged
onTranslationChanged: {
let moveAmount = Math.max(0, translation.x) / (PlasmaCore.Units.gridUnit * 5);
folderGrid.openProgress = 1 - Math.min(1, Math.max(0, moveAmount));
isClosing = translation.x > oldTranslationX;
oldTranslationX = translation.x;
}
// when drag is let go
onActiveChanged: {
if (!active) {
isClosing ? closeFolder() : openFolder();
}
}
}
NumberAnimation {
id: goToBeginningAnim
target: favoritesGrid
......@@ -110,18 +150,9 @@ Item {
ParallelAnimation {
NumberAnimation {
target: favoritesGrid
properties: 'translateX'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: 0
to: -PlasmaCore.Units.gridUnit
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: favoritesGrid
properties: 'opacity'
properties: 'openFolderProgress'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: 1
to: 0
to: 1
easing.type: Easing.InOutQuad
}
}
......@@ -129,17 +160,8 @@ Item {
ParallelAnimation {
NumberAnimation {
target: folderGrid
properties: 'translateX'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: PlasmaCore.Units.gridUnit
to: 0
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: folderGrid
properties: 'opacity'
properties: 'openProgress'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: 0
to: 1
easing.type: Easing.InOutQuad
}
......@@ -152,17 +174,8 @@ Item {
ParallelAnimation {
NumberAnimation {
target: folderGrid
properties: 'translateX'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: 0
to: PlasmaCore.Units.gridUnit
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: folderGrid
properties: 'opacity'
properties: 'openProgress'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: 1
to: 0
easing.type: Easing.InOutQuad
}
......@@ -171,20 +184,11 @@ Item {
ParallelAnimation {
NumberAnimation {
target: favoritesGrid
properties: 'translateX'
properties: 'openFolderProgress'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: -PlasmaCore.Units.gridUnit
to: 0
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: favoritesGrid
properties: 'opacity'
duration: MobileShell.MobileShellSettings.animationsEnabled ? 200 : 0
from: 0
to: 1
easing.type: Easing.InOutQuad
}
}
}
}
Supports Markdown
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