on xenial help sign in
Showable: do nothing if requested action's animation is running
1a9b7e1Ratchanan Srirattanamet
qml/Components/Showable.qml+8−6
@@ -74,6 +74,9 @@ Item {
74 }
74 }
75
75
76 function __reallyShow() {
76 function __reallyShow() {
77+ if (showAnimation != undefined && showAnimation.running)
78+ return;
79+
77 if (!available) {
80 if (!available) {
78 __skipShowAnimation = false;
81 __skipShowAnimation = false;
79 return false;
82 return false;
@@ -86,9 +89,7 @@ Item {
86 }
89 }
87
90
88 if (showAnimation != undefined) {
91 if (showAnimation != undefined) {
89− if (!showAnimation.running) {
90− showAnimation.restart()
92+ showAnimation.restart()
91− }
92 if (__skipShowAnimation || shown) {
93 if (__skipShowAnimation || shown) {
93 showAnimation.complete();
94 showAnimation.complete();
94 }
95 }
@@ -107,6 +108,9 @@ Item {
107 property var prepareToHide: function(){}
108 property var prepareToHide: function(){}
108
109
109 function hide() {
110 function hide() {
111+ if (hideAnimation != undefined && hideAnimation.running)
112+ return;
113+
110 if (showAnimation != undefined && showAnimation.running) {
114 if (showAnimation != undefined && showAnimation.running) {
111 showAnimation.stop()
115 showAnimation.stop()
112 }
116 }
@@ -119,9 +123,7 @@ Item {
119 }
123 }
120
124
121 if (hideAnimation != undefined) {
125 if (hideAnimation != undefined) {
122− if (!hideAnimation.running) {
123− hideAnimation.restart()
126+ hideAnimation.restart()
124− }
125 if (__skipHideAnimation || !shown) {
127 if (__skipHideAnimation || !shown) {
126 hideAnimation.complete();
128 hideAnimation.complete();
127 }
129 }
tests/qmltests/Components/tst_Showable.qml+13
@@ -182,5 +182,18 @@ Item {
182 compare(show1.showAnimation.running, false, "Showable should be done running after delayed showNow");
182 compare(show1.showAnimation.running, false, "Showable should be done running after delayed showNow");
183 compare(show1.opacity, 1.0, "Showable should be at end of animation after delayed showNow");
183 compare(show1.opacity, 1.0, "Showable should be at end of animation after delayed showNow");
184 }
184 }
185+
186+ // Test consecutive show()/hide() to not just complete the animation.
187+ function test_show_when_showing_hide_when_hiding() {
188+ init_test();
189+
190+ show1.show();
191+ show1.show();
192+ compare(show1.showAnimation.running, true);
193+
194+ show1.hide();
195+ show1.hide();
196+ compare(show1.hideAnimation.running, true);
197+ }
185 }
198 }
186}
199}