forked from seekshiva/react-native-remote-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (30 loc) · 826 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react';
import { Image } from 'react-native';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
import SvgImage from './SvgImage';
const MyImage = React.forwardRef((props, ref) => {
const { onError } = props;
const source = resolveAssetSource(props.source);
if (!source || !source.uri || !source.uri.match('.svg')) {
return <Image ref={ref} {...props} />;
}
const style = props.style || {};
if (source.__packager_asset && typeof style !== 'number') {
if (!style.width) {
style.width = source.width;
}
if (!style.height) {
style.height = source.height;
}
}
return (
<SvgImage
ref={ref}
source={source}
style={style}
onError={onError}
{...props}
/>
);
});
export default MyImage;