Answers for "i gave my image component a heigh and width in react native but it doesnt resize"

5

full width of image and maintain aspect ratio react native

render() {
    let image = this.props.requireSource;
    const { width, height } = Image.resolveAssetSource(image);
    const ratio = height / width;
    const SCREEN_WIDTH = Dimensions.get('window').width;

    return (
        <Image source={image} style={{width: SCREEN_WIDTH, height: SCREEN_WIDTH*ratio}} resizeMode="contain"/>
    );
}
Posted by: Guest on June-21-2021
0

relative width and height image react native

const dimensions = Dimensions.get('window');
const imageHeight = Math.round(dimensions.width * 9 / 16);
const imageWidth = dimensions.width;

return (
   <Image
     style={{ height: imageHeight, width: imageWidth }}
   />
);
Posted by: Guest on July-28-2020

Code answers related to "i gave my image component a heigh and width in react native but it doesnt resize"

Code answers related to "Javascript"

Browse Popular Code Answers by Language