Larney Larney - 1 year ago 121
Android Question

React-Native Android - How to use getRealDimensions (Dimensions is not working)

After much research I have discovered that the Dimensions library for Android does not work like it is supposed to. For example, Each time I use "Dimensions.get('window').height", I get a different results.

This is documented on git:

Dimensions.get('window').height is sometimes wrong on Android

The solution is to use "getRealDimensions" library as is mentioned on the git link above.

This is the link to the 'getRealDimensions' but it is written in java and I have no idea how to implement it into my react-native android project.


How can I implement the 'getRealDimensions' library into my react-native android project?


Answer Source

For anyone having the same problem, here is the solution.


The real solution is the react-native-extra-dimensions-android library.

The problem was that react-native-extra-dimensions-android library does not work with React-Native versions above 0.29.

Some dude called BelinChung forked the 'react-native-extra-dimensions-android' git repository and fixed the issue.

This is the link to the working repository ==> ( )

What you have to do is, inside the 'package.json' file, replace the version number of 'react-native-extra-dimensions-android' with the above link to the working git repository like this:
enter image description here

Then uninstall 'react-native-extra-dimensions-android':

npm uninstall react-native-extra-dimensions-android

Then re-install packages:

npm install

The library is now working!
Please upvote if this helped because I need 50 rep to be able to leave comments :)