react-native-svg
Version:
SVG library for react-native
52 lines • 1.65 kB
JavaScript
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import * as React from 'react';
import { Image } from 'react-native';
import { alignEnum, meetOrSliceTypes } from '../lib/extract/extractViewBox';
import { withoutXY } from '../lib/extract/extractProps';
import Shape from './Shape';
import RNSVGImage from '../fabric/ImageNativeComponent';
const spacesRegExp = /\s+/;
export default class SvgImage extends Shape {
static displayName = 'Image';
static defaultProps = {
x: 0,
y: 0,
width: 0,
height: 0,
preserveAspectRatio: 'xMidYMid meet'
};
render() {
const {
props
} = this;
const {
preserveAspectRatio,
x,
y,
width,
height,
xlinkHref,
href = xlinkHref,
onLoad
} = props;
const modes = preserveAspectRatio ? preserveAspectRatio.trim().split(spacesRegExp) : [];
const align = modes[0];
const meetOrSlice = modes[1];
const imageProps = {
x,
y,
width,
height,
onLoad,
meetOrSlice: meetOrSliceTypes[meetOrSlice] || 0,
align: alignEnum[align] || 'xMidYMid',
src: !href ? null : Image.resolveAssetSource(typeof href === 'string' ? {
uri: href
} : href)
};
return /*#__PURE__*/React.createElement(RNSVGImage, _extends({
ref: ref => this.refMethod(ref)
}, withoutXY(this, props), imageProps));
}
}
//# sourceMappingURL=Image.js.map