react-native-svg
Version:
SVG library for react-native
2 lines • 6.44 kB
JavaScript
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.RNSVGSvg=exports.default=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf3=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _extractResponder=_interopRequireDefault(require("../lib/extract/extractResponder"));var _extractViewBox=_interopRequireDefault(require("../lib/extract/extractViewBox"));var _extractColor=_interopRequireDefault(require("../lib/extract/extractColor"));var _Shape2=_interopRequireDefault(require("./Shape"));var _G=_interopRequireDefault(require("./G"));var _jsxFileName="/Users/jannegylling/IdeaProjects/react-native-svg/src/elements/Svg.tsx";function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(source,true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(source).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var RNSVGSvgViewManager=_reactNative.NativeModules.RNSVGSvgViewManager;var styles=_reactNative.StyleSheet.create({svg:{backgroundColor:'transparent',borderWidth:0}});var Svg=function(_Shape){(0,_inherits2.default)(Svg,_Shape);function Svg(){var _getPrototypeOf2;var _this;(0,_classCallCheck2.default)(this,Svg);for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key];}_this=(0,_possibleConstructorReturn2.default)(this,(_getPrototypeOf2=(0,_getPrototypeOf3.default)(Svg)).call.apply(_getPrototypeOf2,[this].concat(args)));_this.measureInWindow=function(callback){_this.root&&_this.root.measureInWindow(callback);};_this.measure=function(callback){_this.root&&_this.root.measure(callback);};_this.measureLayout=function(relativeToNativeNode,onSuccess,onFail){_this.root&&_this.root.measureLayout(relativeToNativeNode,onSuccess,onFail);};_this.setNativeProps=function(props){var width=props.width,height=props.height;if(width){props.bbWidth=width;}if(height){props.bbHeight=height;}_this.root&&_this.root.setNativeProps(props);};_this.toDataURL=function(callback,options){if(!callback){return;}var handle=(0,_reactNative.findNodeHandle)(_this.root);RNSVGSvgViewManager.toDataURL(handle,options,callback);};return _this;}(0,_createClass2.default)(Svg,[{key:"render",value:function render(){var _this$props=this.props,_this$props$opacity=_this$props.opacity,opacity=_this$props$opacity===void 0?1:_this$props$opacity,viewBox=_this$props.viewBox,preserveAspectRatio=_this$props.preserveAspectRatio,style=_this$props.style,children=_this$props.children,onLayout=_this$props.onLayout,props=(0,_objectWithoutProperties2.default)(_this$props,["opacity","viewBox","preserveAspectRatio","style","children","onLayout"]);var stylesAndProps=_objectSpread({},Array.isArray(style)?Object.assign.apply(Object,[{}].concat((0,_toConsumableArray2.default)(style))):style,{},props);var color=stylesAndProps.color,width=stylesAndProps.width,height=stylesAndProps.height,focusable=stylesAndProps.focusable,font=stylesAndProps.font,transform=stylesAndProps.transform,fill=stylesAndProps.fill,fillOpacity=stylesAndProps.fillOpacity,fillRule=stylesAndProps.fillRule,stroke=stylesAndProps.stroke,strokeWidth=stylesAndProps.strokeWidth,strokeOpacity=stylesAndProps.strokeOpacity,strokeDasharray=stylesAndProps.strokeDasharray,strokeDashoffset=stylesAndProps.strokeDashoffset,strokeLinecap=stylesAndProps.strokeLinecap,strokeLinejoin=stylesAndProps.strokeLinejoin,strokeMiterlimit=stylesAndProps.strokeMiterlimit;var w=parseInt(width,10);var h=parseInt(height,10);var doNotParseWidth=isNaN(w)||width[width.length-1]==='%';var doNotParseHeight=isNaN(h)||height[height.length-1]==='%';var dimensions=width&&height?{width:doNotParseWidth?width:w,height:doNotParseHeight?height:h,flex:0}:null;var o=+opacity;var opacityStyle=!isNaN(o)?{opacity:o}:null;var tint=(0,_extractColor.default)(color);return _react.default.createElement(RNSVGSvg,(0,_extends2.default)({},props,{bbWidth:width,bbHeight:height,color:tint,tintColor:tint,onLayout:onLayout,ref:this.refMethod,style:[styles.svg,style,opacityStyle,dimensions],focusable:Boolean(focusable)&&focusable!=='false'},(0,_extractResponder.default)(props,this),(0,_extractViewBox.default)({viewBox:viewBox,preserveAspectRatio:preserveAspectRatio}),{__source:{fileName:_jsxFileName,lineNumber:157}}),_react.default.createElement(_G.default,(0,_extends2.default)({children:children,style:style,font:font,transform:transform,fill:fill,fillOpacity:fillOpacity,fillRule:fillRule,stroke:stroke,strokeWidth:strokeWidth,strokeOpacity:strokeOpacity,strokeDasharray:strokeDasharray,strokeDashoffset:strokeDashoffset,strokeLinecap:strokeLinecap,strokeLinejoin:strokeLinejoin,strokeMiterlimit:strokeMiterlimit},{__source:{fileName:_jsxFileName,lineNumber:170}})));}}]);return Svg;}(_Shape2.default);exports.default=Svg;Svg.displayName='Svg';Svg.defaultProps={preserveAspectRatio:'xMidYMid meet'};var RNSVGSvg=(0,_reactNative.requireNativeComponent)('RNSVGSvgView');exports.RNSVGSvg=RNSVGSvg;
//# sourceMappingURL=Svg.js.map