If you know the aspect ratio for example, if your image is square you can set either the height or the width to fill the container and get the other to be set by the aspectRatio property

Here is the style if you want the height be set automatically:

{
    width: '100%',
    height: undefined,
    aspectRatio: 1,
}

Note: height must be undefined

Edit (Based on @rob-art's comment):
If your image is a different aspect ratio than the one you want to set in the style you can use resizeMode to control how the image should be displayed. Use resizeMode:'contain' to ensure your image is not cropped.
See documentation for more details

Answer from sazzy4o on Stack Overflow
🌐
React Native
reactnative.dev › docs › image
Image · React Native
2 weeks ago - When the resizeMethod is set to resize, the destination dimensions are multiplied by this value. The scale method is used to perform the remainder of the resize. A default of 1.0 means the bitmap size is designed to fit the destination dimensions.
🌐
npm
npmjs.com › package › react-native-scalable-image
react-native-scalable-image - npm
February 12, 2021 - React Native <Image/> component does not keep the image aspect ratio, which results in the image being stretched or cropped. react-native-scalable-image solves this problem by calculating the image size and resizing the image when rendering.
      » npm install react-native-scalable-image
    
Published   Feb 12, 2021
Version   1.1.0
Author   Ihor Burlachenko
🌐
LogRocket
blog.logrocket.com › home › using resizemode in react native to scale images
Using resizeMode in React Native to scale images - LogRocket Blog
June 4, 2024 - In React Native, the resizeMode property has five values — cover, contain, stretch, repeat, and center. These values help us to resize our images when the frame doesn’t match or fit the raw image dimensions.
🌐
GitHub
github.com › bamlab › react-native-image-resizer
GitHub - bamlab/react-native-image-resizer: 🗻 Resize local images with React Native
Similar to react-native Image's resizeMode: either contain (the default), cover, or stretch. contain will fit the image within width and height, preserving its ratio. cover preserves the aspect ratio, and makes sure the image is at least width ...
Starred by 1.7K users
Forked by 363 users
Languages   Java 40.9% | Objective-C++ 20.5% | Objective-C 15.9% | TypeScript 15.8% | Ruby 4.5% | JavaScript 2.2%
🌐
GitHub
github.com › ihor › react-native-scalable-image
GitHub - ihor/react-native-scalable-image: React Native Image component which scales width or height automatically to keep the original aspect ratio
React Native <Image/> component does not keep the image aspect ratio, which results in the image being stretched or cropped. react-native-scalable-image solves this problem by calculating the image size and resizing the image when rendering.
Starred by 315 users
Forked by 67 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
SKPTRICKS
skptricks.com › 2018 › 11 › react-native-responsive-image-scale-to-fit-example.html
React Native Responsive Image Scale To Fit Example - Android | SKPTRICKS
So here we are going to discuss about new library that helps to create responsive image in android or ios device easily. react-native-scalable-image solves this problem by calculating the image size and resizing the image when rendering.
Find elsewhere
🌐
AbstractAPI
abstractapi.com › api guides, tips & tricks › how to resize images in react native
Image Resizing in React Native: How to Resize Images in React Native
June 7, 2024 - The resizeImage attribute tells React Native how an image should be stretched, shrunk, or otherwise modified to fit into the constraints of the Image component. There are five options available: ‘cover’, ‘contain’, ‘stretch’, ...
🌐
Bacancy Technology
bacancytechnology.com › qanda › react-native › image-resizing-in-react-native
How to Resize Images in React Native?
July 27, 2023 - If we want to achieve the image to fit on the screen without any area being cropped, then we can use the resize mode “contain”. ... Instead of giving some random value for the height and width, You can use the “Dimensions” method from ...
🌐
npm
npmjs.com › package › react-native-fit-image
react-native-fit-image - npm
November 14, 2019 - Responsive image component to fit perfectly itself.. Latest version: 1.5.5, last published: 6 years ago. Start using react-native-fit-image in your project by running `npm i react-native-fit-image`. There are 56 other projects in the npm registry using react-native-fit-image.
      » npm install react-native-fit-image
    
Published   Nov 14, 2019
Version   1.5.5
Top answer
1 of 16
89

Try this:

 import React, { Component, PropTypes } from "react";
 import { Image } from "react-native";

export default class ScaledImage extends Component {
constructor(props) {
    super(props);
    this.state = { source: { uri: this.props.uri } };
}

componentWillMount() {
    Image.getSize(this.props.uri, (width, height) => {
        if (this.props.width && !this.props.height) {
            this.setState({
                width: this.props.width,
                height: height * (this.props.width / width)
            });
        } else if (!this.props.width && this.props.height) {
            this.setState({
                width: width * (this.props.height / height),
                height: this.props.height
            });
        } else {
            this.setState({ width: width, height: height });
        }
    });
}

render() {
    return (
        <Image
            source={this.state.source}
            style={{ height: this.state.height, width: this.state.width }}
        />
    );
}
}

ScaledImage.propTypes = {
uri: PropTypes.string.isRequired,
width: PropTypes.number,
height: PropTypes.number
};

I'm passing the URL as a prop called uri. You can specify your width prop as Dimensions.get('window').width and that should cover it.

Note that this will also work if you know what you want to set the height to and you need to resize the width to maintain the ratio. In that case, you would specify the height prop instead of the width one.

2 of 16
57

There is a property resizeMode set it to 'contain', this solution works only for local images:

Example:

<Image
    source={require('./local_path_to/your_image.png')}
    style={{ width: 30 }}
    resizeMode="contain"
 />

Source: https://facebook.github.io/react-native/docs/image#resizemode

Edit: The above solution is working fine for me, the resizeMode property is not deprecated and I couldn't find any indications that they are planning to do so. If for some reason the the above solution doesn't work for you, you can calculate the height yourself. Here is an axample:

const Demo = () => {
    const scaleHeight = ({ source, desiredWidth }) => {
        const { width, height } = Image.resolveAssetSource(source)

        return desiredWidth / width * height
    }

    const imageSource = './local_image.png'
    const imageWidth = 150
    const imageHeigh = scaleHeight({
        source: require(imageSource),
        desiredWidth: imageWidth
    })
    
    return (
        <View style={{
            display: 'flex',
            flex: 1,
            alignItems: 'center',
            justifyContent: 'center'
        }}>
            <Image
                source={require(imageSource)}
                style={{
                    borderWidth: 1,
                    width: imageWidth,
                    height: imageHeigh
                }}
            />
        </View>
    )
}

The above solution works only for local images. Here is how to do the same for remote images:

const RemoteImage = ({uri, desiredWidth}) => {
    const [desiredHeight, setDesiredHeight] = React.useState(0)

    Image.getSize(uri, (width, height) => {
        setDesiredHeight(desiredWidth / width * height)
    })

    return (
        <Image
            source={{uri}}
            style={{
                borderWidth: 1,
                width: desiredWidth,
                height: desiredHeight
            }}
        />
    )
}

const Demo = () => {
    return (
        <View style={{
            flex: 1,
            alignItems: 'center',
            justifyContent: 'center'
        }}>
            <RemoteImage
                uri="https://via.placeholder.com/350x150"
                desiredWidth={200}
            />
        </View>
    )
}
🌐
Medium
mehrankhandev.medium.com › understanding-resizemode-in-react-native-dd0e455ce63
Understanding “resizeMode” in React Native | by Mehran Khan | Medium
November 5, 2019 - Scale the image uniformly (maintain ... of the view (minus padding). ... Image size = “1200*1200” (aspect ratio 1:1) , Image View Dimension “300*200”, and resizeMode = “cover” , when the image is scaled this will ...
🌐
GitHub
github.com › huiseoul › react-native-fit-image
GitHub - huiseoul/react-native-fit-image: Responsive image component to fit perfectly itself.
... import FitImage from 'react-native-fit-image'; // custom styles for FitImage var styles = StyleSheet.create({ fitImage: { borderRadius: 20, }, fitImageWithSize: { height: 100, width: 30, }, }); // draws image to fit inherited space ...
Starred by 582 users
Forked by 53 users
Languages   TypeScript 100.0% | TypeScript 100.0%
🌐
Repeato
repeato.app › home › effective techniques for resizing images in react native
Effective Techniques for Resizing Images in React Native - Repeato
December 17, 2024 - contain: Scales the image uniformly (maintaining aspect ratio) so that both dimensions fit within the container. cover: Scales the image uniformly (maintaining aspect ratio) so that both dimensions fill the container, cropping the image if necessary. Here’s a practical example of how to implement image resizing in your React Native app:
🌐
Medium
medium.com › the-react-native-log › tips-for-react-native-images-or-saying-goodbye-to-trial-and-error-b2baaf0a1a4d
Tips for React Native Images (or saying goodbye to trial and error) | by Gustavo Machado | The React Native Log | Medium
February 2, 2017 - If the image can’t fill the entire frame, the it will be scaled up until it does and then it will be centered. You can easily see this here: Finally, if you use contain the image will maintain it’s original aspect ratio, but it will try to fit as much of the image as possible.
🌐
Medium
medium.com › @Sarmilasivaraja › creating-responsive-images-in-react-native-1194bf036e98
Creating Responsive Images in React Native | by Sarmila Sivaraja | Medium
June 19, 2023 - The Image component has flex: 1, width: "100%", and height: "100%". By setting flex: 1, the image will expand to fill the available space within the parent View. The width and height are set to "100%" to ensure that the image scales proportionally ...
🌐
Cloudinary
cloudinary.com › home › how to easily resize an image with react native
How to Easily Resize an Image with React Native | Cloudinary
January 14, 2026 - Use Cloudinary’s auto responsive breakpoints for device-specific delivery React Native runs on various screen sizes and resolutions, making responsive image handling crucial. Use Cloudinary’s auto breakpoints in your transformation URL (w_auto) to dynamically adapt image widths based on device screens.
🌐
Medium
medium.com › @nima-ahmadi › react-native-image-resizemode-a-visual-guide-f1958d27c615
React Native Image ResizeMode: A Visual Guide | by Nima Ahmadi | Medium
July 24, 2021 - I will also include all resizeMode ... cover: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus ...