-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (23 loc) · 934 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
import React, { useState } from 'react';
import { Image } from 'react-native';
const ImageAutoHeight = (props) => {
var propsImageWidth, propsImageHeight, imageUri;
if(props.style.length) {
propsImageWidth = props.style[props.style.length-1].width;
propsImageHeight = props.style[props.style.length-1].height;
} else {
propsImageWidth = props.style.width;
propsImageHeight = props.style.height;
}
const [ ImageHeight, setImageHeight ] = useState(propsImageHeight);
if(propsImageHeight == 'auto') {
imageUri = props.source.uri ? props.source.uri : Image.resolveAssetSource(props.source).uri;
Image.getSize(imageUri, (imgWidth, imgHeight) => {
setImageHeight((imgHeight * (propsImageWidth)) / imgWidth)
});
}
return (<Image {...props} style={[props.style, {
height: ImageHeight,
}]}/>)
}
export default ImageAutoHeight;