-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPageManager.qml
164 lines (152 loc) · 5.26 KB
/
PageManager.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import QtQuick 2.4
import QtGraphicalEffects 1.0
Item {
anchors.fill: parent
id: pageLoader
property var toolBar
property var navigationBar
property var components: []
property var initialComponents: []
property int speed: 3
property string currentPage
property var currentView
property var previousView
property int previousIndex: -1
property bool inFromRight: true
Component.onCompleted: {
for(var i=pageLoader.initialComponents.length-1; i>=0; i--) {
loadPage(pageLoader.initialComponents[i]);
}
if(pageLoader.initialComponents.length)
showPage(pageLoader.initialComponents[0], 0)
}
function showPage(pageName, pageIndex) {
console.log("Load page:", pageName, pageIndex)
if(currentPage === pageName)
return;
if(!components[pageName]) {
loadPage(pageName)
}
showView(pageName, pageIndex)
}
function loadPage(pageName) {
console.log("Loading component " + pageName)
var component = Qt.createComponent(pageName + ".qml")
if (component.status === Component.Ready) {
components[pageName] = component.createObject(pageLoader, {
width: parent.width,
height: parent.height,
visible: false
// opacity: 0,
// "anchors.fill": pageLoader
})
console.log(components[pageName])
try {
components[pageName].navigationBar = pageLoader.navigationBar
components[pageName].toolBar = pageLoader.toolBar
components[pageName].viewDidLoad()
} catch(e) { }
} else console.log("Component not ready: " + component.errorString())
}
function showView(pageName, pageIndex) {
currentPage = pageName
previousView = currentView
currentView = components[pageName]
if(previousView) {
currentView.width = pageLoader.width
currentView.height = pageLoader.height
previousView.z = 1
currentView.z = 2
currentView.x = pageLoader.width
inFromRight = previousIndex < pageIndex
if(!inFromRight) {
currentView.x = -currentView.width
}
try {
previousView.viewWillDisappear()
} catch(e) { }
fadeOut1.target = previousView
fadeOut2.target = previousView
fadeOut3.target = previousView
fadeOut.running = true
try {
currentView.viewWillAppear()
} catch(e) { }
currentView.visible = true
fadeIn1.target = currentView
fadeIn2.target = currentView
fadeIn3.target = currentView
fadeIn.running = true
} else {
currentView.x = 0
currentView.visible = true
}
previousIndex = pageIndex
_appMgr.lightContent = currentView.lightContent
}
SequentialAnimation {
id: fadeOut
PropertyAnimation {
id: fadeOut1
from: 1
to: .8
duration: 100 * pageLoader.speed
property: "scale"
// target: pageLoader.previousView
easing.type: Easing.InQuad
}
PropertyAnimation {
id: fadeOut2
from: 0
to: inFromRight ? -pageLoader.width : pageLoader.width
duration: 200 * pageLoader.speed
property: "x"
// target: pageLoader.previousView
}
PropertyAnimation {
id: fadeOut3
from: .8
to: 1
duration: 100 * pageLoader.speed
property: "scale"
// target: pageLoader.previousView
easing.type: Easing.OutQuad
onStopped: {
try { pageLoader.previousView.viewDidDisappear() } catch(e) { }
pageLoader.previousView.visible = false
}
}
}
SequentialAnimation {
id: fadeIn
PropertyAnimation {
id: fadeIn1
from: 1
to: .8
duration: 100 * pageLoader.speed
property: "scale"
easing.type: Easing.InQuad
}
PropertyAnimation {
id: fadeIn2
from: inFromRight ? pageLoader.width : -pageLoader.width
to: 0
duration: 200 * pageLoader.speed
property: "x"
}
PropertyAnimation {
id: fadeIn3
from: .8
to: 1
duration: 100 * pageLoader.speed
property: "scale"
easing.type: Easing.OutQuad
onStopped: {
try { pageLoader.currentView.viewDidAppear() } catch(e) { }
pageLoader.previousView.visible = false
}
}
}
onWidthChanged: if(currentView) currentView.width = width
onHeightChanged: if(currentView) currentView.height = height
}