Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react native image auto height

import {
  Image,
  Dimensions,
} from "react-native";


const screen = Dimensions.get("window");
Image.getSize(this.state.image_url, (width, height) => {
  //full image to screen width (Change screen.width to pixel you want)
  let imageWidthRatio = width / screen.width; 
  let imageHeight = height / imageWidthRatio;
  this.setState({ width: screen.width, height: imageHeight });
});

<Image
	style={{
       width: this.state.width,
       height: this.state.height,
       alignSelf: "center",
    }}
    source={{ uri: this.state.image_url }}
/>
 
PREVIOUS NEXT
Tagged: #react #native #image #auto #height
ADD COMMENT
Topic
Name
9+2 =