Socket
Book a DemoInstallSign in
Socket

react-native-autosize-image

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-autosize-image

react-native image width auto width or height computation

0.1.3
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

react-native-autosize-image

Inspired by vivaxy/react-native-auto-height-image

NPM Version NPM Downloads MIT License Conventional Commits Financial Contributors on Open Collective

This component provides you a simple way to load a remote image and automatically set Image crossAxisSize to the image dimension which fits the provided mainAxisSize.

ReactNative Image component needs users to set both mainAxisSize and crossAxisSize props.

Installation

yarn add react-native-autosize-image

npm install react-native-autosize-image

Usage

Use local or remote files:

import React, { Component } from 'react';
import AutoImage from 'react-native-autosize-image';

import image from 'gallifrey-falls.png';

export default class Demo extends Component {
  render() {
    return (
      <View>

        <AutoImage
          mainAxisSize={100}
          mainAxis='horizontal'
          source={image}
        />

        <AutoImage
          mainAxisSize={100}
          mainAxis='vertical'
          source={{uri: 'http://placehold.it/350x150'}}
        />

      </View>
    );
  }
}

You can even specify fallback images for when the source fails to load:

import React, { Component } from 'react';
import AutoImage from 'react-native-autosize-image';

import image from 'gallifrey-falls.png';

export default class Demo extends Component {
  render() {
    return (
      <AutoImage
        mainAxisSize={100}
        source={{uri: 'https://vivaxy.github.io/404'}}
        fallbackSource={image}
      />
    );
  }
}

Props

nametypeisRequireddefaultdescription
mainAxisSizenumberN/Aimage mainAxisSize to fit
mainAxis'horizontal''vertical'N/A
maxCrossAxisSizenumberInfinityimage max crossAxisSize
sourcenumber or objectN/Alocal (i.e. require/import) or remote image ({uri: '...'})
fallbackSourcenumber or objectN/Alocal (i.e. require/import) or remote image ({uri: '...'})
onCrossAxisSizeChangefunc(crossAxisSize) => {}called when updating image crossAxisSize, the argument crossAxisSize might be 0
animatedboolfalseUse Animated.Image instead of Image

Other image props except resizeMode are accepted.

Change Log

Change log

Contributing

Contributing

Licence

MIT

Keywords

react-native

FAQs

Package last updated on 29 Sep 2020

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.