From 109082c8d87dcbeae208da53cb5345b44b7acb91 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 19 Aug 2019 15:37:48 -0400 Subject: [PATCH] Use a Loader instead of StackView for pageStack --- TODO.md | 1 - src/qml/Chat/Banners/LeftBanner.qml | 2 +- src/qml/Chat/SendBox.qml | 2 +- src/qml/Pages/EditAccount/EditAccount.qml | 2 +- src/qml/Pages/EditAccount/Encryption.qml | 2 +- src/qml/Pages/EditAccount/Profile.qml | 2 +- src/qml/Pages/SignIn.qml | 2 +- src/qml/SidePane/DelegateAccount.qml | 2 +- src/qml/SidePane/DelegateRoom.qml | 2 +- src/qml/SidePane/PaneToolBar.qml | 2 +- src/qml/UI.qml | 32 ++++++++++++++--------- 11 files changed, 28 insertions(+), 23 deletions(-) diff --git a/TODO.md b/TODO.md index 03465204..3cbea451 100644 --- a/TODO.md +++ b/TODO.md @@ -139,7 +139,6 @@ - Direct chats category - Markdown: don't turn #things (no space) and `thing\n---` into title, disable `__` syntax for bold/italic - - Push instead of replacing in stack view (remove getMemberFilter when done) - `
` scrollbar on overflow
   - When inviting someone to direct chat, room is "Empty room" until accepted,
     it should be the peer's display name instead.
diff --git a/src/qml/Chat/Banners/LeftBanner.qml b/src/qml/Chat/Banners/LeftBanner.qml
index 7c9ea806..6559952f 100644
--- a/src/qml/Chat/Banners/LeftBanner.qml
+++ b/src/qml/Chat/Banners/LeftBanner.qml
@@ -24,7 +24,7 @@ Banner {
             py.callClientCoro(
                 chatPage.userId, "room_forget", [chatPage.roomId], () => {
                     button.loading = false
-                    Qt.callLater(pageStack.showPage, "Default")
+                    Qt.callLater(pageLoader.showPage, "Default")
             })
         }
     })
diff --git a/src/qml/Chat/SendBox.qml b/src/qml/Chat/SendBox.qml
index 3874a297..f65957cc 100644
--- a/src/qml/Chat/SendBox.qml
+++ b/src/qml/Chat/SendBox.qml
@@ -49,7 +49,7 @@ HRectangle {
     Layout.fillWidth: true
     Layout.minimumHeight: theme.baseElementsHeight
     Layout.preferredHeight: areaScrollView.implicitHeight
-    Layout.maximumHeight: pageStack.height / 2
+    Layout.maximumHeight: pageLoader.height / 2
     color: theme.chat.sendBox.background
 
     HRowLayout {
diff --git a/src/qml/Pages/EditAccount/EditAccount.qml b/src/qml/Pages/EditAccount/EditAccount.qml
index fceac856..e4de7d54 100644
--- a/src/qml/Pages/EditAccount/EditAccount.qml
+++ b/src/qml/Pages/EditAccount/EditAccount.qml
@@ -42,7 +42,7 @@ HPage {
 
             Layout.maximumWidth: Math.min(parent.width, 640)
             Layout.preferredWidth:
-                pageStack.isWide ? parent.width : avatarPreferredSize
+                pageLoader.isWide ? parent.width : avatarPreferredSize
 
             Layout.preferredHeight: childrenRect.height
 
diff --git a/src/qml/Pages/EditAccount/Encryption.qml b/src/qml/Pages/EditAccount/Encryption.qml
index f3c61806..1dab2249 100644
--- a/src/qml/Pages/EditAccount/Encryption.qml
+++ b/src/qml/Pages/EditAccount/Encryption.qml
@@ -24,7 +24,7 @@ HColumnLayout {
             "rooms can be exported to a passphrase-protected file.%1" +
             "You will then be able to import this file in another " +
             "Matrix client."
-        ).arg(pageStack.isWide ? "\n" :"\n\n")
+        ).arg(pageLoader.isWide ? "\n" :"\n\n")
 
         Layout.fillWidth: true
         Layout.margins: currentSpacing
diff --git a/src/qml/Pages/EditAccount/Profile.qml b/src/qml/Pages/EditAccount/Profile.qml
index f0619941..a175650a 100644
--- a/src/qml/Pages/EditAccount/Profile.qml
+++ b/src/qml/Pages/EditAccount/Profile.qml
@@ -46,7 +46,7 @@ HGridLayout {
     }
 
     columns: 2
-    flow: pageStack.isWide ? GridLayout.LeftToRight : GridLayout.TopToBottom
+    flow: pageLoader.isWide ? GridLayout.LeftToRight : GridLayout.TopToBottom
     rowSpacing: currentSpacing
 
     Component.onCompleted: nameField.field.forceActiveFocus()
diff --git a/src/qml/Pages/SignIn.qml b/src/qml/Pages/SignIn.qml
index 14a4488a..aaca006d 100644
--- a/src/qml/Pages/SignIn.qml
+++ b/src/qml/Pages/SignIn.qml
@@ -41,7 +41,7 @@ HPage {
                         (rememberAccount.checked ? "add": "delete"),
                         [data]
                     )
-                    pageStack.showPage(
+                    pageLoader.showPage(
                         "EditAccount/EditAccount", {userId: data}
                     )
 
diff --git a/src/qml/SidePane/DelegateAccount.qml b/src/qml/SidePane/DelegateAccount.qml
index eaced1a7..03fada96 100644
--- a/src/qml/SidePane/DelegateAccount.qml
+++ b/src/qml/SidePane/DelegateAccount.qml
@@ -37,7 +37,7 @@ HInteractiveRectangle {
     }
 
     function activate() {
-        pageStack.showPage(
+        pageLoader.showPage(
             "EditAccount/EditAccount", { "userId": model.data.user_id }
         )
     }
diff --git a/src/qml/SidePane/DelegateRoom.qml b/src/qml/SidePane/DelegateRoom.qml
index aa7a1b7c..947ee742 100644
--- a/src/qml/SidePane/DelegateRoom.qml
+++ b/src/qml/SidePane/DelegateRoom.qml
@@ -33,7 +33,7 @@ HInteractiveRectangle {
     }
 
     function activate() {
-        pageStack.showRoom(model.user_id, model.data.room_id)
+        pageLoader.showRoom(model.user_id, model.data.room_id)
     }
 
 
diff --git a/src/qml/SidePane/PaneToolBar.qml b/src/qml/SidePane/PaneToolBar.qml
index 1b55544d..02c05787 100644
--- a/src/qml/SidePane/PaneToolBar.qml
+++ b/src/qml/SidePane/PaneToolBar.qml
@@ -16,7 +16,7 @@ HRowLayout {
         backgroundColor: theme.sidePane.settingsButton.background
         Layout.preferredHeight: parent.height
 
-        onClicked: pageStack.showPage("SignIn")
+        onClicked: pageLoader.showPage("SignIn")
     }
 
     HTextField {
diff --git a/src/qml/UI.qml b/src/qml/UI.qml
index 679ae6c9..a0243808 100644
--- a/src/qml/UI.qml
+++ b/src/qml/UI.qml
@@ -11,7 +11,7 @@ HRectangle {
     Component.onCompleted: window.mainUI = mainUI
 
     property alias sidePane: sidePane
-    property alias pageStack: pageStack
+    property alias pageLoader: pageLoader
     property alias pressAnimation: _pressAnimation
 
     SequentialAnimation {
@@ -63,13 +63,13 @@ HRectangle {
             Behavior on Layout.minimumWidth { HNumberAnimation {} }
         }
 
-        StackView {
-            id: pageStack
+        HLoader {
+            id: pageLoader
             property bool isWide: width > theme.contentIsWideAbove
 
             Component.onCompleted: {
                 if (! py.startupAnyAccountsSaved) {
-                    pageStack.showPage("SignIn")
+                    pageLoader.showPage("SignIn")
                     return
                 }
 
@@ -77,14 +77,14 @@ HRectangle {
                 let props = window.uiState.pageProperties
 
                 if (page == "Chat/Chat.qml") {
-                    pageStack.showRoom(props.userId, props.roomId)
+                    pageLoader.showRoom(props.userId, props.roomId)
                 } else {
-                    pageStack._show(page, props)
+                    pageLoader._show(page, props)
                 }
             }
 
             function _show(componentUrl, properties={}) {
-                pageStack.replace(componentUrl, properties)
+                pageLoader.setSource(componentUrl, properties)
             }
 
             function showPage(name, properties={}) {
@@ -104,14 +104,20 @@ HRectangle {
                 window.uiStateChanged()
             }
 
-            onCurrentItemChanged: if (currentItem) {
-                currentItem.forceActiveFocus()
+            onStatusChanged: if (status == Loader.Ready) {
+                item.forceActiveFocus()
+                appearAnimation.start()
             }
 
-            // Buggy
-            replaceExit: null
-            popExit: null
-            pushExit: null
+            clip: appearAnimation.running
+            XAnimator {
+                id: appearAnimation
+                target: pageLoader.item
+                from: -300
+                to: 0
+                easing.type: Easing.OutBack
+                duration: theme.animationDuration * 2
+            }
         }
     }
 }