Files
react-native-svg/Example/components/SnackImageCompat.web.js
T
2022-02-21 16:17:37 +01:00

39 lines
997 B
JavaScript

import React, { Component } from 'react';
import { Image as NativeImage, View } from 'react-native';
import { Image as SvgImage } from '../Svg';
class WebImage extends NativeImage {
constructor(props, context) {
super(props, context);
this._setImageRef = ref => {
this._imageRef = ref;
const attrs = ref && ref.attributes;
const src = attrs && attrs.src;
const uri = src && src.value;
this.setState({ href: uri });
};
this.oldRender = this.render;
this.render = () => {
const uri = this.state && this.state.href;
return (
<>
<View
style={{
visibility: 'hidden',
position: 'absolute',
width: 0,
height: 0,
}}>
{this.oldRender()}
</View>
<SvgImage {...this.props} href={uri} />
</>
);
};
}
}
export default props => (
<WebImage {...props} source={props.source || props.href} />
);