Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-scalable-image

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-scalable-image

React Native Image component which scales width or height automatically to keep the aspect ratio

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Native Scalable Image

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.

This library provides an <Image/> component which scales width or height automatically to keep the aspect ratio. It is useful when you don't know the aspect ratio in advance (e.g. user-uploaded content) but want to display the entire image and limit it only by width or height to fit the container component.

The following example creates an image which fits the full screen width and keeps the aspect ratio:

import React from 'react';
import { Dimensions } from 'react-native';
import Image from 'react-native-scalable-image';

const image = (
   <Image
       width={Dimensions.get('window').width} // height will be calculated automatically
       source={{uri: '<image uri>'}}
   />
);

Install

npm install react-native-scalable-image --save

Usage

Specify width or height which may be calculated dynamically like in the example above. All other props are the same as in regular React Native <Image/> component.

props

nametypedefaultdescription
heightnumbernoneMaximum image height
widthnumbernoneMaximum image width
backgroundbooleanfalseSet to true when used as a background
componentReact.ReactNodenoneCustom image component
onPressfunctionnoneonPress callback
onSizefunctionnoneIs called with { width, height } as the first arg once image size is calculated

Versions

The latest major version of react-native-scalable-image is implemented with hooks. If you are using a pre-hooks React version please use react-native-scalable-image version 0.5.1

React VersionScalable Image Version
< 16.80.5.1
>= 16.8> 1.0.0

Keywords

FAQs

Package last updated on 12 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc