1import { Dimensions } from "react-native";
2const win = Dimensions.get('window');
3
4<Image
5 style={{
6 width: win.width/2,
7 height: win.width/2,
8 resizeMode: "contain",
9 alignSelf: "center",
10 borderWidth: 1,
11 borderRadius: 20,
12 }}
13 source={{uri:'https://facebook.github.io/react/img/logo_og.png'}}
14 resizeMode="stretch"
15/>
1Adding Image
2Let us create a new folder img inside the src folder. We will add our image (myImage.png) inside this folder.
3
4We will show images on the home screen.
5
6App.js
7import React from 'react';
8import ImagesExample from './ImagesExample.js'
9
10const App = () => {
11 return (
12 <ImagesExample />
13 )
14}
15export default App
16Local image can be accessed using the following syntax.
17
18image_example.js
19import React, { Component } from 'react'
20import { Image } from 'react-native'
21
22const ImagesExample = () => (
23 <Image source = {require('C:/Users/Tutorialspoint/Desktop/NativeReactSample/logo.png')} />
24)
25export default ImagesExample
1First import Dimensions from react-native
2
3import { Dimensions } from 'react-native';
4then you have to get the dimensions of the window
5
6const win = Dimensions.get('window');
7Now calculate ratio as
8
9const ratio = win.width/541; //541 is actual image width
10now the add style to your image as
11
12imageStyle: {
13 width: win.width,
14 height: 362 * ratio, //362 is actual height of image
15}