L
L
Lost1772020-05-09 22:54:55
React Native
Lost177, 2020-05-09 22:54:55

How to set automatic image height in react-native?

The goal is to display the image on the full width of the screen, and the height is automatically obtained.
But if height is not specified, the image will not be displayed.

Please tell me how can I do this?
Thank you for your attention.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
khorark, 2020-05-14
@khorark

There are several ways, depending on what result you expect.
You can:
1) specify the height as a % of the parent element;
2) use screen height , for static size

import { Dimensions } from 'react-native';

const screenHeight = Dimensions.get('screen').height;

3) Use the static getSize method to get the height and width of the image, then set it manually.
Image.getSize(uri, success, [failure]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question