GT2/GT2-Android/node_modules/lottie-react-native/lib/LottieView.js

1 line
6.5 KiB
JavaScript

var _jsxFileName='src/js/LottieView.js';var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor;};}();var _extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};var _react=require('react');var _react2=_interopRequireDefault(_react);var _reactNative=require('react-native');var _reactNativeSafeModule=require('react-native-safe-module');var _reactNativeSafeModule2=_interopRequireDefault(_reactNativeSafeModule);var _propTypes=require('prop-types');var _propTypes2=_interopRequireDefault(_propTypes);function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i];}return arr2;}else{return Array.from(arr);}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;}var NativeLottieView=_reactNativeSafeModule2.default.component({viewName:'LottieAnimationView',mockComponent:_reactNative.View});var LottieViewManager=_reactNativeSafeModule2.default.module({moduleName:'LottieAnimationView',mock:{play:function play(){},reset:function reset(){}}});var ViewStyleExceptBorderPropType=function ViewStyleExceptBorderPropType(props,propName,componentName){for(var _len=arguments.length,rest=Array(_len>3?_len-3:0),_key=3;_key<_len;_key++){rest[_key-3]=arguments[_key];}var flattened=_reactNative.StyleSheet.flatten(props[propName]);var usesBorder=Object.keys(flattened).some(function(key){return key.startsWith('border');});if(usesBorder){return Error(componentName+' does not allow any border related style properties to be specified. '+"Border styles for this component will behave differently across platforms. If you'd "+'like to render a border around this component, wrap it with a View.');}return _reactNative.ViewPropTypes.style.apply(_reactNative.ViewPropTypes,[props,propName,componentName].concat(rest));};var NotAllowedPropType=function NotAllowedPropType(props,propName,componentName){var value=props[propName];if(value!=null){return Error(componentName+' cannot specify \''+propName+'\'.');}return null;};var propTypes=_extends({},_reactNative.ViewPropTypes,{style:ViewStyleExceptBorderPropType,children:NotAllowedPropType,resizeMode:_propTypes2.default.oneOf(['cover','contain','center']),progress:_propTypes2.default.number,speed:_propTypes2.default.number,loop:_propTypes2.default.bool,enableMergePathsAndroidForKitKatAndAbove:_propTypes2.default.bool,source:_propTypes2.default.oneOfType([_propTypes2.default.object,_propTypes2.default.string]).isRequired});var defaultProps={progress:0,speed:1,loop:true,enableMergePathsAndroidForKitKatAndAbove:false,resizeMode:'contain',style:_reactNative.StyleSheet.absoluteFill};var viewConfig={uiViewClassName:'LottieAnimationView',validAttributes:{progress:true}};var LottieView=function(_React$Component){_inherits(LottieView,_React$Component);function LottieView(props){_classCallCheck(this,LottieView);var _this=_possibleConstructorReturn(this,(LottieView.__proto__||Object.getPrototypeOf(LottieView)).call(this,props));_this.viewConfig=viewConfig;_this.refRoot=_this.refRoot.bind(_this);return _this;}_createClass(LottieView,[{key:'setNativeProps',value:function setNativeProps(props){_reactNative.UIManager.updateView(this.getHandle(),this.viewConfig.uiViewClassName,{progress:props.progress});}},{key:'play',value:function play(startFrame,endFrame){this.runCommand('play',[startFrame,endFrame]);}},{key:'reset',value:function reset(){this.runCommand('reset');}},{key:'runCommand',value:function runCommand(name){var _this2=this;var args=arguments.length>1&&arguments[1]!==undefined?arguments[1]:[];return _reactNative.Platform.select({android:function android(){return _reactNative.UIManager.dispatchViewManagerCommand(_this2.getHandle(),_reactNative.UIManager.LottieAnimationView.Commands[name],args);},ios:function ios(){return LottieViewManager[name].apply(LottieViewManager,[_this2.getHandle()].concat(_toConsumableArray(args)));}})();}},{key:'getHandle',value:function getHandle(){return(0,_reactNative.findNodeHandle)(this.root);}},{key:'refRoot',value:function refRoot(root){this.root=root;}},{key:'render',value:function render(){var source=this.props.source;var sourceName=typeof source==='string'?source:undefined;var sourceJson=typeof source==='string'?undefined:JSON.stringify(source);return _react2.default.createElement(NativeLottieView,_extends({ref:this.refRoot},this.props,{source:undefined,sourceName:sourceName,sourceJson:sourceJson,__source:{fileName:_jsxFileName,lineNumber:123}}));}}]);return LottieView;}(_react2.default.Component);LottieView.propTypes=propTypes;LottieView.defaultProps=defaultProps;var AnimatedLottieView=_reactNative.Animated.createAnimatedComponent(LottieView);AnimatedLottieView.prototype.play=function play(){var startFrame=arguments.length>0&&arguments[0]!==undefined?arguments[0]:-1;var endFrame=arguments.length>1&&arguments[1]!==undefined?arguments[1]:-1;if(this.getNode()){return this.getNode().play(startFrame,endFrame);}console.warn('Trying to animate a view on an unmounted component');return null;};AnimatedLottieView.prototype.reset=function pause(){if(this.getNode()){return this.getNode().reset();}console.warn('Trying to animate a view on an unmounted component');return null;};module.exports=AnimatedLottieView;