Files
react-native-svg/Example/components/SnackImageCompat.web.tsx
Wojciech Lewicki 2484baa8db feat: move Example to TS (#1712)
This PR changes all examples in Example app to ts in order to more easily check if types are correct and in future remove index.d.ts file.
2022-03-01 14:35:53 +01:00

42 lines
1.1 KiB
TypeScript

import React, { Component } from 'react';
import { Image as NativeImage, View } from 'react-native';
import { Image as SvgImage } from '../Svg';
class WebImage extends NativeImage {
oldRender: () => React.ReactNode;
private _setImageRef: (ref: any) => void;
private _imageRef: any;
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} />
);