@@ -15,6 +15,7 @@
1515*/
1616
1717import QtQuick 2.0
18+import "Animations"
1819
1920Item {
2021 id: container
@@ -38,11 +39,21 @@ Item {
3839 Connections {
3940 target: surface
4041 onRemoved: {
42+ container.removing = true;
43+
44+ var childSurfaces = surface.childSurfaces;
45+ for (var i=0; i<childSurfaces.length; i++) {
46+ childSurfaces[i].removed();
47+ }
48+
49+ //if we don't have children, nothing will tell us to animate out, so do it.
50+ if (childSurfaces.length === 0) {
51+ animateOut();
52+ }
53+ // tell our parent to animate out.
4154 if (surface.parentSurface) {
4255 surface.parentSurface.parent.animateOut();
4356 }
44− container.removing = true;
45− animateOut();
4657 }
4758 }
4859
@@ -57,30 +68,27 @@ Item {
5768 source: Qt.resolvedUrl("SurfaceContainer.qml")
5869 onLoaded: {
5970 item.surface = modelData;
60− item.animateIn("swipeFromBottom");
61− container.animateIn("swipeUp");
71+ item.animateIn(swipeFromBottom);
72+ container.animateIn(swipeUp);
6273 }
6374 }
6475 }
6576
66− function animateIn(type) {
77+ function animateIn(component) {
78+ var animation = component.createObject(container, { "surface": container.surface, "surfaceArea": container.surfaceArea });
79+ animation.start();
80+
6781 var tmp = d.animations;
68− tmp.push(type);
82+ tmp.push(animation);
6983 d.animations = tmp;
70−
71− container.state = d.currentAnimation + "-prep";
72− container.state = d.currentAnimation + "-in";
7384 }
7485
7586 function animateOut() {
7687 if (d.animations.length > 0) {
7788 var tmp = d.animations;
7889 var popped = tmp.pop();
90+ popped.end();
7991 d.animations = tmp;
80− container.state = popped + "-out";
81− if (d.currentAnimation !== "") {
82− container.state = d.currentAnimation + "-in";
83− }
8492 } else {
8593 container.state = "initial";
8694 }
@@ -88,90 +96,24 @@ Item {
8896
8997 QtObject {
9098 id: d
91− property variant animations: []
92− property string currentAnimation: animations.length > 0 ? animations[animations.length-1] : ""
99+ property var animations: []
100+ property var currentAnimation: animations.length > 0 ? animations[animations.length-1] : undefined
101+ }
102+
103+ Component {
104+ id: swipeFromBottom
105+ SwipeFromBottomAnimation {}
106+ }
107+ Component {
108+ id: swipeUp
109+ SwipeUpAnimation {}
93110 }
94111
95112 states: [
96113 State {
97114 name: "initial"
98115 PropertyChanges { target: surface; anchors.fill: surfaceArea }
99− },
100−
101− State {
102− name: "baseAnimation"
103− PropertyChanges { target: surface; anchors.fill: undefined }
104− },
105−
106− State {
107− name: "swipeFromBottom-prep"
108− extend: "baseAnimation"
109− AnchorChanges { target: surface; anchors.top: surfaceArea.bottom }
110− },
111− State {
112− name: "swipeFromBottom-out"
113− extend: "swipeFromBottom-prep"
114− },
115− State {
116− name: "swipeFromBottom-in"
117− extend: "baseAnimation"
118− AnchorChanges { target: surface; anchors.top: surfaceArea.top }
119− },
120−
121− State {
122− name: "swipeUp-prep"
123− extend: "baseAnimation"
124− },
125− State {
126− name: "swipeUp-out"
127− extend: "swipeUp-prep"
128− },
129− State {
130− name: "swipeUp-in"
131− extend: "baseAnimation"
132− AnchorChanges { target: surface; anchors.bottom: surfaceArea.top }
133116 }
134117 // TODO: more animations!
135118 ]
136−
137− transitions: [
138− Transition {
139− to: "swipeFromBottom-in"
140− SequentialAnimation {
141− PropertyAction { target: surface.parent; property: "clip"; value: true }
142− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
143− PropertyAction { target: surface.parent; property: "clip"; value: false }
144− }
145− },
146− Transition {
147− to: "swipeFromBottom-out"
148− SequentialAnimation {
149− PropertyAction { target: surface.parent; property: "clip"; value: true }
150− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
151− PropertyAction { target: surface; property: "visible"; value: !removing }
152− PropertyAction { target: surface.parent; property: "clip"; value: false }
153− ScriptAction { script: { if (container.removing) surface.release() } }
154− }
155− },
156−
157− Transition {
158− to: "swipeUp-in"
159− SequentialAnimation {
160− PropertyAction { target: surface.parent; property: "clip"; value: true }
161− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
162− PropertyAction { target: surface; property: "visible"; value: false}
163− PropertyAction { target: surface.parent; property: "clip"; value: false }
164− }
165− },
166− Transition {
167− to: "swipeUp-out"
168− SequentialAnimation {
169− PropertyAction { target: surface.parent; property: "clip"; value: true }
170− PropertyAction { target: surface; property: "visible"; value: true }
171− AnchorAnimation { easing.type: Easing.InOutQuad; duration: 400 }
172− PropertyAction { target: surface.parent; property: "clip"; value: false }
173− ScriptAction { script: { if (container.removing) surface.release() } }
174− }
175− }
176− ]
177119}