Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react native asign width to image

import { Dimensions } from "react-native";
const win = Dimensions.get('window');

<Image
  style={{
    width: win.width/2,
    height: win.width/2,
    resizeMode: "contain",
    alignSelf: "center",
    borderWidth: 1,
    borderRadius: 20,
  }}
  source={{uri:'https://facebook.github.io/react/img/logo_og.png'}}
  resizeMode="stretch"
/>
Comment

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 }}
/>
Comment

react native asign width to image

First import Dimensions from react-native

import { Dimensions } from 'react-native';
then you have to get the dimensions of the window

const win = Dimensions.get('window');
Now calculate ratio as

const ratio = win.width/541; //541 is actual image width
now the add style to your image as

imageStyle: {
    width: win.width,
    height: 362 * ratio, //362 is actual height of image
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: react router dom props.history is undefined 
Javascript :: scroll for sticky 
Javascript :: animate javascript 
Javascript :: arrow functions 
Javascript :: curl send json as variable 
Javascript :: js string replace array 
Javascript :: react render twice v18 
Javascript :: remove array item with index 
Javascript :: how to validate from and to date using date.parse in javascript 
Javascript :: javascript caeser cipher 
Javascript :: express return svg 
Javascript :: react owl-carousel 
Javascript :: setimeout 
Javascript :: remove duplicates in array 
Javascript :: expo modal 
Javascript :: office check in 
Javascript :: is string undefined null or empty c# javascript 
Javascript :: npm ERR! Error: connect ECONNREFUSED 
Javascript :: catch errors async await javascript 
Javascript :: js event div class adding 
Javascript :: How to fetch data from an api async and await 
Javascript :: datatable bootstrap cllick on specific button 
Javascript :: como eliminar un elemento del dom con javascript 
Javascript :: check object has key javascript 
Javascript :: insert array as string google app scripts 
Javascript :: javascript print to pdf 
Javascript :: js max array 
Javascript :: get max value of slider js 
Javascript :: array any 
Javascript :: node js documentation 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =