diff --git a/dist/animations/SlideAnimation.js b/dist/animations/SlideAnimation.js index 1ee5727..bcb5067 100644 --- a/dist/animations/SlideAnimation.js +++ b/dist/animations/SlideAnimation.js @@ -1 +1 @@ -Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:{},_ref$initialValue=_ref.initialValue,initialValue=_ref$initialValue===undefined?0:_ref$initialValue,_ref$useNativeDriver=_ref.useNativeDriver,useNativeDriver=_ref$useNativeDriver===undefined?true:_ref$useNativeDriver,_ref$slideFrom=_ref.slideFrom,slideFrom=_ref$slideFrom===undefined?'bottom':_ref$slideFrom;_classCallCheck(this,SlideAnimation);var _this=_possibleConstructorReturn(this,(SlideAnimation.__proto__||Object.getPrototypeOf(SlideAnimation)).call(this,{initialValue:initialValue,useNativeDriver:useNativeDriver}));_this.slideFrom=slideFrom;return _this;}_createClass(SlideAnimation,[{key:'in',value:function _in(){var onFinished=arguments.length>0&&arguments[0]!==undefined?arguments[0]:function(){};_reactNative.Animated.spring(this.animate,{toValue:1,velocity:0,tension:65,friction:10,useNativeDriver:this.useNativeDriver}).start(onFinished);}},{key:'out',value:function out(){var onFinished=arguments.length>0&&arguments[0]!==undefined?arguments[0]:function(){};_reactNative.Animated.spring(this.animate,{toValue:0,velocity:0,tension:65,friction:10,useNativeDriver:this.useNativeDriver}).start(onFinished);}},{key:'getAnimations',value:function getAnimations(){var transform=[];if(this.slideFrom==='top'){transform.push({translateY:this.animate.interpolate({inputRange:[0,1],outputRange:[-SCREEN_HEIGHT,0]})});}if(this.slideFrom==='bottom'){transform.push({translateY:this.animate.interpolate({inputRange:[0,1],outputRange:[SCREEN_HEIGHT,0]})});}if(this.slideFrom==='left'){transform.push({translateX:this.animate.interpolate({inputRange:[0,1],outputRange:[-SCREEN_WIDTH,0]})});}if(this.slideFrom==='right'){transform.push({translateX:this.animate.interpolate({inputRange:[0,1],outputRange:[SCREEN_WIDTH,0]})});}return{transform:transform};}}]);return SlideAnimation;}(_Animation3.default);exports.default=SlideAnimation; \ No newline at end of file +Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i0&&arguments[0]!==undefined?arguments[0]:{},_ref$initialValue=_ref.initialValue,initialValue=_ref$initialValue===undefined?0:_ref$initialValue,_ref$useNativeDriver=_ref.useNativeDriver,useNativeDriver=_ref$useNativeDriver===undefined?true:_ref$useNativeDriver,_ref$slideFrom=_ref.slideFrom,slideFrom=_ref$slideFrom===undefined?SlideAnimation.SLIDE_FROM_BOTTOM:_ref$slideFrom;_classCallCheck(this,SlideAnimation);var _this=_possibleConstructorReturn(this,(SlideAnimation.__proto__||Object.getPrototypeOf(SlideAnimation)).call(this,{initialValue:initialValue,useNativeDriver:useNativeDriver}));_this.slideFrom=slideFrom;return _this;}_createClass(SlideAnimation,[{key:'in',value:function _in(){var onFinished=arguments.length>0&&arguments[0]!==undefined?arguments[0]:function(){};_reactNative.Animated.spring(this.animate,{toValue:1,velocity:0,tension:65,friction:10,useNativeDriver:this.useNativeDriver}).start(onFinished);}},{key:'out',value:function out(){var onFinished=arguments.length>0&&arguments[0]!==undefined?arguments[0]:function(){};_reactNative.Animated.spring(this.animate,{toValue:0,velocity:0,tension:65,friction:10,useNativeDriver:this.useNativeDriver}).start(onFinished);}},{key:'getAnimations',value:function getAnimations(){var transform=[];if(this.slideFrom===SlideAnimation.SLIDE_FROM_TOP){transform.push({translateY:this.animate.interpolate({inputRange:[0,1],outputRange:[-SCREEN_HEIGHT,0]})});}else if(this.slideFrom===SlideAnimation.SLIDE_FROM_BOTTOM){transform.push({translateY:this.animate.interpolate({inputRange:[0,1],outputRange:[SCREEN_HEIGHT,0]})});}else if(this.slideFrom===SlideAnimation.SLIDE_FROM_LEFT){transform.push({translateX:this.animate.interpolate({inputRange:[0,1],outputRange:[-SCREEN_WIDTH,0]})});}else if(this.slideFrom===SlideAnimation.SLIDE_FROM_RIGHT){transform.push({translateX:this.animate.interpolate({inputRange:[0,1],outputRange:[SCREEN_WIDTH,0]})});}else{throw new Error('\n slideFrom: '+this.slideFrom+' not supported. \'slideFrom\' must be \'top\' | \'bottom\' | \'left\' | \'right\'\n ');}return{transform:transform};}}]);return SlideAnimation;}(_Animation3.default);SlideAnimation.SLIDE_FROM_TOP='top';SlideAnimation.SLIDE_FROM_BOTTOM='bottom';SlideAnimation.SLIDE_FROM_LEFT='left';SlideAnimation.SLIDE_FROM_RIGHT='right';exports.default=SlideAnimation; \ No newline at end of file diff --git a/src/animations/SlideAnimation.js b/src/animations/SlideAnimation.js index f055ec2..ee4e7c5 100644 --- a/src/animations/SlideAnimation.js +++ b/src/animations/SlideAnimation.js @@ -3,20 +3,28 @@ import { Animated, Dimensions } from 'react-native'; import Animation, { type AnimationConfig } from './Animation'; +const { + width: SCREEN_WIDTH, + height: SCREEN_HEIGHT, +} = Dimensions.get('window'); + type SlideFrom = 'top' | 'bottom' | 'left' | 'right'; type SlideAnimationConfig = AnimationConfig & { slideFrom?: SlideFrom, } -const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window'); - export default class SlideAnimation extends Animation { - slideFrom: SlideFrom + slideFrom: SlideFrom; + + static SLIDE_FROM_TOP = 'top'; + static SLIDE_FROM_BOTTOM = 'bottom'; + static SLIDE_FROM_LEFT = 'left'; + static SLIDE_FROM_RIGHT = 'right'; constructor({ initialValue = 0, useNativeDriver = true, - slideFrom = 'bottom', + slideFrom = SlideAnimation.SLIDE_FROM_BOTTOM, }: SlideAnimationConfig = {}) { super({ initialValue, useNativeDriver }); this.slideFrom = slideFrom; @@ -44,37 +52,38 @@ export default class SlideAnimation extends Animation { getAnimations(): Object { const transform = []; - if (this.slideFrom === 'top') { + if (this.slideFrom === SlideAnimation.SLIDE_FROM_TOP) { transform.push({ translateY: this.animate.interpolate({ inputRange: [0, 1], outputRange: [-SCREEN_HEIGHT, 0], }), }); - } - if (this.slideFrom === 'bottom') { + } else if (this.slideFrom === SlideAnimation.SLIDE_FROM_BOTTOM) { transform.push({ translateY: this.animate.interpolate({ inputRange: [0, 1], outputRange: [SCREEN_HEIGHT, 0], }), }); - } - if (this.slideFrom === 'left') { + } else if (this.slideFrom === SlideAnimation.SLIDE_FROM_LEFT) { transform.push({ translateX: this.animate.interpolate({ inputRange: [0, 1], outputRange: [-SCREEN_WIDTH, 0], }), }); - } - if (this.slideFrom === 'right') { + } else if (this.slideFrom === SlideAnimation.SLIDE_FROM_RIGHT) { transform.push({ translateX: this.animate.interpolate({ inputRange: [0, 1], outputRange: [SCREEN_WIDTH, 0], }), }); + } else { + throw new Error(` + slideFrom: ${this.slideFrom} not supported. 'slideFrom' must be 'top' | 'bottom' | 'left' | 'right' + `); } return { transform,