Skip to content

Commit 16d61c7

Browse files
Fix: Animation could wire up multiple times
1 parent 7960f39 commit 16d61c7

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

fab-common.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,50 @@ var color = require("color");
33
var frameModule = require("ui/frame");
44
var dObservable = require("ui/core/dependency-observable");
55
var proxy = require("ui/core/proxy");
6-
6+
var swipeLoaded = false;
7+
78
var FloatingActionButton = (function (_super) {
89
global.__extends(FloatingActionButton, _super);
910

1011
function FloatingActionButton() {
1112
_super.call(this);
1213
}
1314

15+
1416
FloatingActionButton.prototype.onLoaded = function () {
1517
_super.prototype.onLoaded.call(this);
16-
var fab = this;
17-
var viewToAttachTo = this.hideOnSwipeOfView;
18-
var swipeItem = this.page.getViewById(viewToAttachTo);
19-
20-
if(swipeItem !== undefined){
21-
var duration = (this.hideAnimationDuration == undefined) ? 300 : this.hideAnimationDuration;
22-
23-
//Wire up action
24-
swipeItem.on("swipe", function (args) {
25-
26-
//if scrolling down (swipe up) -- hide FAB
27-
if (args.direction === 4) {
28-
fab.animate({
29-
translate: { x: 0, y: 200 },
30-
opacity: 0,
31-
duration: duration
32-
});
33-
} //if scrolling up (swipe down) -- show FAB
34-
else if (args.direction === 8) {
35-
fab.animate({
36-
translate: { x: 0, y: 0 },
37-
opacity: 1,
38-
duration: duration
18+
19+
if(swipeLoaded === false){
20+
var fab = this;
21+
var viewToAttachTo = this.hideOnSwipeOfView;
22+
if(viewToAttachTo !== undefined){
23+
var swipeItem = this.page.getViewById(viewToAttachTo);
24+
25+
if(swipeItem !== undefined){
26+
console.log("Wiring up swipe");
27+
var duration = (this.hideAnimationDuration == undefined) ? 300 : this.hideAnimationDuration;
28+
swipeItem.on("swipe", function (args) {
29+
//Swipe up
30+
if (args.direction === 4) {
31+
fab.animate({
32+
translate: { x: 0, y: 200 },
33+
opacity: 0,
34+
duration: duration
35+
});
36+
}
37+
//Swipe Down
38+
else if (args.direction === 8) {
39+
fab.animate({
40+
translate: { x: 0, y: 0 },
41+
opacity: 1,
42+
duration: duration
43+
});
44+
};
3945
});
40-
};
41-
});
46+
47+
swipeLoaded = true;
48+
}
49+
}
4250
}
4351
};
4452

@@ -77,5 +85,4 @@ var FloatingActionButton = (function (_super) {
7785
return FloatingActionButton;
7886
})(view.View);
7987

80-
8188
exports.Fab = FloatingActionButton;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-floatingactionbutton",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "A NativeScript plugin to provide an XML widget to implement the Material Design Floating Action Button in NativeScript apps.",
55
"main": "fab.js",
66
"nativescript": {

0 commit comments

Comments
 (0)