mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-06 07:06:11 +00:00
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.
42 lines
1.1 KiB
TypeScript
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} />
|
|
);
|