Skip to content

Commit fad9bd7

Browse files
committed
qml: signal based navigation in onboarding
Pages exist within a view, in this page <-> view dependency, somewhere inside of there, at least for views that are 'flows' or 'wizards,' there needs to be logic on: a) when to move to a new page b) what page to move to. We are currently handling this navigation logic primarily inside the definition of a page itself. Inside of the page, we assume a hard-coded ID for a parent view and call navigation function directly to the view from within the page itself telling it to: a) to pop or push b) the id of the page we want to push. This is bad because: 1. It creates a dependency between page declarations that does not need to exist. As in, PageB.qml doesn't really exist unless PageA.qml includes code to go to it. 2. This prevents us from being able to 'statically' define and clearly contain pages. Clearly containing pages makes it so that when we want to reason about PageA.qml, we only have to look inside of PageA.qml and the components that are used within that file; we don't have to go on a chase for interlinked dependencies on id's or properties that are hidden or at least not easy to find in other pages. 3. We should never assume outside id's from within a page, as these can change, and when they change, the page that assumes said outside id is now broken, and debugging can be annoying. All of this is unnecessary. In this commit, we address the issue of the logic for navigation being contained within the page definitions. This proposes a new navigation model based on signals and first applies it to the onboarding flow. Pages within our onboarding flow now: 1. Emit a signal when it's time to go to a new page 2. The parent View itself handles the signals and contains the logic for navigation. This removes the dependence on having a hardcoded outside ID within a a page, and is one step to moving us to pages with no dependency on other pages.
1 parent 88ce525 commit fad9bd7

File tree

8 files changed

+45
-12
lines changed

8 files changed

+45
-12
lines changed

src/qml/controls/InformationPage.qml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import org.bitcoincore.qt 1.0
99

1010
Page {
1111
id: root
12+
signal back
13+
signal next
1214
implicitHeight: information.height + continueButton.height + buttonMargin
1315
property alias bannerItem: banner_loader.sourceComponent
1416
property alias detailItem: detail_loader.sourceComponent
@@ -106,7 +108,7 @@ Page {
106108
anchors.rightMargin: 20
107109
anchors.horizontalCenter: parent.horizontalCenter
108110
text: root.buttonText
109-
onClicked: root.lastPage ? swipeView.finished = true : swipeView.incrementCurrentIndex()
111+
onClicked: root.next()
110112
}
111113
}
112114

src/qml/pages/main.qml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,29 @@ ApplicationWindow {
7070
property bool finished: false
7171
interactive: false
7272

73-
OnboardingCover {}
74-
OnboardingStrengthen {}
75-
OnboardingBlockclock {}
76-
OnboardingStorageLocation {}
77-
OnboardingStorageAmount {}
78-
OnboardingConnection {}
73+
OnboardingCover {
74+
onNext: swipeView.incrementCurrentIndex()
75+
}
76+
OnboardingStrengthen {
77+
onBack: swipeView.decrementCurrentIndex()
78+
onNext: swipeView.incrementCurrentIndex()
79+
}
80+
OnboardingBlockclock {
81+
onBack: swipeView.decrementCurrentIndex()
82+
onNext: swipeView.incrementCurrentIndex()
83+
}
84+
OnboardingStorageLocation {
85+
onBack: swipeView.decrementCurrentIndex()
86+
onNext: swipeView.incrementCurrentIndex()
87+
}
88+
OnboardingStorageAmount {
89+
onBack: swipeView.decrementCurrentIndex()
90+
onNext: swipeView.incrementCurrentIndex()
91+
}
92+
OnboardingConnection {
93+
onBack: swipeView.decrementCurrentIndex()
94+
onNext: swipeView.finished = true
95+
}
7996

8097
onFinishedChanged: {
8198
optionsModel.onboard()

src/qml/pages/onboarding/OnboardingBlockclock.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import QtQuick.Layouts 1.15
88
import "../../controls"
99

1010
InformationPage {
11+
id: root
1112
navLeftDetail: NavButton {
1213
iconSource: "image://images/caret-left"
1314
text: qsTr("Back")
14-
onClicked: swipeView.decrementCurrentIndex()
15+
onClicked: root.back()
1516
}
1617
bannerItem: Image {
1718
source: Theme.image.blocktime

src/qml/pages/onboarding/OnboardingConnection.qml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import "../../components"
1010
import "../settings"
1111

1212
Page {
13+
id: root
14+
signal back
15+
signal next
1316
background: null
1417
clip: true
1518
SwipeView {
@@ -21,7 +24,7 @@ Page {
2124
navLeftDetail: NavButton {
2225
iconSource: "image://images/caret-left"
2326
text: qsTr("Back")
24-
onClicked: swipeView.decrementCurrentIndex()
27+
onClicked: root.back()
2528
}
2629
bannerItem: Image {
2730
Layout.topMargin: 20
@@ -47,6 +50,7 @@ Page {
4750
lastPage: true
4851
buttonText: qsTr("Next")
4952
buttonMargin: 20
53+
onNext: root.next()
5054
}
5155
SettingsConnection {
5256
navRightDetail: NavButton {

src/qml/pages/onboarding/OnboardingCover.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import "../../components"
1010
import "../settings"
1111

1212
Page {
13+
id: root
14+
signal next
1315
background: null
1416
clip: true
1517
SwipeView {
@@ -48,6 +50,7 @@ Page {
4850
descriptionSize: 24
4951
subtext: qsTr("100% open-source & open-design")
5052
buttonText: qsTr("Start")
53+
onNext: root.next()
5154
}
5255
SettingsAbout {
5356
navLeftDetail: NavButton {

src/qml/pages/onboarding/OnboardingStorageAmount.qml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import "../../components"
1010
import "../settings"
1111

1212
Page {
13+
id: root
14+
signal back
15+
signal next
1316
background: null
1417
clip: true
1518
SwipeView {
@@ -21,7 +24,7 @@ Page {
2124
navLeftDetail: NavButton {
2225
iconSource: "image://images/caret-left"
2326
text: qsTr("Back")
24-
onClicked: swipeView.decrementCurrentIndex()
27+
onClicked: root.back()
2528
}
2629
bannerActive: false
2730
bold: true
@@ -47,6 +50,7 @@ Page {
4750
}
4851
buttonText: qsTr("Next")
4952
buttonMargin: 20
53+
onNext: root.next()
5054
}
5155
SettingsStorage {
5256
id: advancedStorage

src/qml/pages/onboarding/OnboardingStorageLocation.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import "../../controls"
1010
import "../../components"
1111

1212
InformationPage {
13+
id: root
1314
navLeftDetail: NavButton {
1415
iconSource: "image://images/caret-left"
1516
text: qsTr("Back")
16-
onClicked: swipeView.decrementCurrentIndex()
17+
onClicked: root.back()
1718
}
1819
bannerActive: false
1920
bold: true

src/qml/pages/onboarding/OnboardingStrengthen.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import QtQuick.Layouts 1.15
88
import "../../controls"
99

1010
InformationPage {
11+
id: root
1112
navLeftDetail: NavButton {
1213
iconSource: "image://images/caret-left"
1314
text: qsTr("Back")
14-
onClicked: swipeView.decrementCurrentIndex()
15+
onClicked: root.back()
1516
}
1617
bannerItem: Image {
1718
source: Theme.image.network

0 commit comments

Comments
 (0)