Skip to content

Commit 302e48b

Browse files
author
Corwin Kerr
committed
widget_utils: Move events to anim function
1 parent ba5d98a commit 302e48b

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

modules/widget_utils.js

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,34 @@ exports.swipeOn = function(autohide) {
132132
if (exports.animInterval) clearInterval(exports.animInterval);
133133
exports.animInterval = setInterval(function() {
134134
exports.offset += dir;
135-
let stop = false;
136-
if (dir>0 && exports.offset>=0) { // fully down
137-
stop = true;
138-
exports.offset = 0;
139-
Bangle.emit("widgets-shown");
140-
} else if (dir<0 && exports.offset<-23) { // fully up
141-
stop = true;
142-
exports.offset = -24;
143-
Bangle.emit("widgets-hidden");
144-
}
135+
let stop = false;
136+
// exports.offset >=0 <0 <-23
137+
// dir >0 shown, so stop. in process of showing start show
138+
// <0 start hide in process of hiding hidden, so stop
139+
if (dir > 0) {
140+
if (exports.offset >= 0) {
141+
stop = true;
142+
exports.offset = 0;
143+
Bangle.emit("widgets-shown");
144+
} else if (exports.offset <= -23) {
145+
Bangle.emit("widgets-start-show");
146+
} else {
147+
Bangle.emit("widget-anim-step");
148+
}
149+
} else if (dir < 0) {
150+
if (exports.offset>=0) {
151+
Bangle.emit("widget-start-hide");
152+
} else if (exports.offset <= -23) {
153+
stop = true;
154+
exports.offset = -24;
155+
Bangle.emit("widgets-hidden");
156+
} else {
157+
Bangle.emit("widget-anim-step");
158+
}
159+
}
160+
else {
161+
// dir == 0??
162+
}
145163
if (stop) {
146164
clearInterval(exports.animInterval);
147165
delete exports.animInterval;
@@ -159,18 +177,11 @@ exports.swipeOn = function(autohide) {
159177
let cb;
160178
if (exports.autohide > 0) cb = function() {
161179
exports.hideTimeout = setTimeout(function() {
162-
Bangle.emit("widgets-start-hide");
163180
anim(-4);
164181
}, exports.autohide);
165182
};
166-
if (ud>0 && exports.offset<0) {
167-
Bangle.emit("widgets-start-show");
168-
anim(4, cb);
169-
}
170-
if (ud<0 && exports.offset>-24) {
171-
Bangle.emit("widgets-start-hide");
172-
anim(-4);
173-
}
183+
if (ud>0 && exports.offset<0) anim(4, cb);
184+
if (ud<0 && exports.offset>-24) anim(-4);
174185
};
175186
Bangle.on("swipe", exports.swipeHandler);
176187
Bangle.drawWidgets();

0 commit comments

Comments
 (0)