Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does width null signify in react-native?

Tags:

react-native

I was going through few questions on SO and few apps where I came across the following style configuration:-

  container: {
    flex:1,
    width: null,
  },

I was wondering what is the use of width:null here. Can someone please help?

like image 960
Harkirat Saluja Avatar asked Jan 04 '17 13:01

Harkirat Saluja


People also ask

How know width of a view react-native?

You can directly use the Dimensions module and calc your views sizes. Actually, Dimensions give to you the main window sizes. import { Dimensions } from 'Dimensions'; Dimensions. get('window').

How do you use width in react?

To get the width of an Element in React: Set the ref prop on the element. In the useLayoutEffect hook, update the state variable for the width. Use the offsetWidth property to get the width of the element.


1 Answers

<Image source={require('./images/MacWallPaper.jpg')} style={styles.container}>

</Image>

When you don't specify width: null and height: null component fetches actual width and height of the source image.

container: {
   flex: 1,
   justifyContent: 'center',
   alignItems: 'center',
   backgroundColor: 'rgba(0, 0, 0, 0)',
}

when you explicitly specify width: null and height: null component won't make use of actual width and height of the image.

container: {
   flex: 1,
   justifyContent: 'center',
   alignItems: 'center',
   backgroundColor: 'rgba(0, 0, 0, 0)',
   // remove width and height to override fixed static size
   width: null,
   height: null,
}

Watch this video

like image 156
Ashok R Avatar answered Sep 29 '22 10:09

Ashok R