Skip to content

Instantly share code, notes, and snippets.

@brunoziie
Created October 1, 2018 14:02
Show Gist options
  • Save brunoziie/8e36313724b459437662c804bd59a91c to your computer and use it in GitHub Desktop.
Save brunoziie/8e36313724b459437662c804bd59a91c to your computer and use it in GitHub Desktop.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var color_1 = require("tns-core-modules/color");
var view_1 = require("tns-core-modules/ui/core/view");
var gestures_1 = require("tns-core-modules/ui/gestures");
var common = require("./ripple-common");
var Ripple = (function (_super) {
__extends(Ripple, _super);
function Ripple() {
return _super.call(this) || this;
}
Ripple.prototype.calcRadius = function (x, y, w, h) {
var ww = Math.max(x, Math.abs(w - x)) * 2.1;
var hh = Math.max(y, Math.abs(h - y)) * 2.1;
return Math.max(ww, hh);
}
Ripple.prototype.performRipple = function (x, y) {
var _this = this;
if (!(this.content instanceof view_1.View)) {
return;
}
if (this.performingAnimation) {
return;
}
var nativeView = this.content.ios;
var size = this.content.getActualSize();
var radius = this.calcRadius(x, y, size.width, size.height);
var scale = (radius) * 0.1;
var initial = 10;
var ripple = UIView.alloc().initWithFrame(CGRectMake(0, 0, initial, initial));
this.performingAnimation = ripple;
ripple.layer.cornerRadius = initial * 0.5;
ripple.backgroundColor = new color_1.Color(_this.rippleColor.hex || '#cecece').ios;
ripple.alpha = 0.0;
nativeView.insertSubviewAtIndex(ripple, 0);
ripple.center = CGPointMake(x || 0, y || 0);
UIView.animateWithDurationDelayOptionsAnimationsCompletion(0.6, 0, 131072, function () {
ripple.transform = CGAffineTransformMakeScale(scale, scale);
ripple.alpha = 0.1;
}, function (finished) {
ripple.removeFromSuperview();
_this.performingAnimation = null;
});
};
Ripple.prototype.onLoaded = function () {
var _this = this;
_super.prototype.onLoaded.call(this);
if (this.content instanceof view_1.View) {
this.tapFn = function (args) {
_this.performRipple(args.getX(), args.getY());
};
this.content.on(gestures_1.GestureTypes.touch, this.tapFn);
}
else {
throw new Error('Content must inherit from View!');
}
};
Ripple.prototype.onUnloaded = function () {
_super.prototype.onUnloaded.call(this);
if (this.content instanceof view_1.View) {
this.content.off(gestures_1.GestureTypes.tap, this.tapFn);
}
};
return Ripple;
}(common.Ripple));
exports.Ripple = Ripple;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment