react-native-ui-lib
Version:
<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a
38 lines (32 loc) • 1.06 kB
JavaScript
import _pt from "prop-types";
import React from 'react';
import { isSvg, isSvgUri } from "../../utils/imageUtils";
import { SvgPackage } from "../../optionalDependencies";
const SvgXml = SvgPackage?.SvgXml;
const SvgCssUri = SvgPackage?.SvgCssUri; // const SvgProps = SvgPackage?.SvgProps; TODO: not sure how (or if) we can use their props
function SvgImage(props) {
const {
data,
...others
} = props;
if (!SvgXml) {
// eslint-disable-next-line max-len
console.error(`RNUILib Image "svg" prop requires installing "react-native-svg" and "react-native-svg-transformer" dependencies`);
return null;
}
if (isSvgUri(data)) {
return <SvgCssUri {...others} uri={data.uri} />;
} else if (typeof data === 'string') {
return <SvgXml xml={data} {...others} />;
} else if (data) {
const File = data; // Must be with capital letter
return <File {...others} />;
}
return null;
}
SvgImage.propTypes = {
data: _pt.any.isRequired
};
SvgImage.displayName = 'IGNORE';
SvgImage.isSvg = isSvg;
export default SvgImage;