Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-auto-height-image

vivaxy26.8kMIT3.2.4TypeScript support: included

react-native auto height image

react-native, image, auto-height, react, images

readme

react-native-auto-height-image

Initialized by vivaxy/gt-npm-package

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 height to the image dimension which fits the provided width.

ReactNative Image component needs users to set both width and height props.

Installation

yarn add react-native-auto-height-image

npm install react-native-auto-height-image

Usage

Use local or remote files:

import React, { Component } from 'react';
import AutoHeightImage from 'react-native-auto-height-image';

import image from 'gallifrey-falls.png';

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

        <AutoHeightImage
          width={100}
          source={image}
        />

        <AutoHeightImage
          width={100}
          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 AutoHeightImage from 'react-native-auto-height-image';

import image from 'gallifrey-falls.png';

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

Props

name type isRequired default description
width number N/A image width to fit
maxHeight number Infinity image max height
source number or object N/A local (i.e. require/import) or remote image ({uri: '...'})
fallbackSource number or object N/A local (i.e. require/import) or remote image ({uri: '...'})
onHeightChange func (height) => {} called when updating image height, the argument height might be 0
animated bool false Use Animated.Image instead of Image

Other image props except resizeMode are accepted.

Change Log

Change log

Contributing

Contributing

Licence

MIT

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

3.2.4 (2021-02-04)

Bug Fixes

  • deps: update dependency expo to v40 (a99a92e)
  • deps: update dependency react-native-web to ~0.14.0 (3e038fd)
  • deps: update react monorepo to v16.14.0 (3e20f8e)
  • deps: update react monorepo to v17.0.1 (dbec1ff)

3.2.3 (2020-10-17)

Bug Fixes

  • deps: update dependency expo to v39 (9cf60e4)
  • deps: update dependency react to v16.14.0 (ed45e7e)
  • deps: update dependency react-native-web to ^0.14.0 (1ad617f)

3.2.2 (2020-07-25)

Bug Fixes

  • deps: update dependency expo to v38 (6b24bd8)
  • deps: update dependency react-native-web to ^0.13.0 (82d6270)

3.2.1 (2020-06-08)

3.2.0 (2020-05-27)

Features

  • :sparkles: support maxHeight prop, reuse image cache on initial rendering to optimize the performance (e5055c8)

3.1.3 (2020-05-07)

Bug Fixes

  • :bug: fix Can't perform a React state update on an unmounted component. (035e6a8), closes #44

3.1.2 (2020-04-18)

Bug Fixes

3.1.1 (2020-04-04)

Bug Fixes

  • android crash at imagePolyfill (21dc084)

3.1.0 (2020-03-31)

Features

3.0.0 (2020-01-17)

⚠ BREAKING CHANGES

  • changelog: Drop support for react before 16.8 and react-native before 0.59

  • changelog: :memo: commit a breaking change (03c9b81)

Bug Fixes

  • fix for fallback images (d825375)

Features

  • deps: bumped React to ^16.8 & React Native to ^0.59.0 (24edbc2)

2.0.0 (2020-01-09)

⚠ BREAKING CHANGES

  • incorporated imagepolyfill in codebase, removed from deps

Features

  • incorporated imagepolyfill in codebase, removed from deps (bfdca6f)

1.1.3 (2019-10-16)

1.1.1 (2019-08-13)

Reverts

  • open collective: :rewind: revert changes to package.json (37f3b17)

1.1.0 (2019-03-07)

Features

  • :sparkles:updateImageHeight with safe check (a2c9275)

1.0.5 (2018-10-22)

Bug Fixes

  • :bug:Fix updating the image size after change of the source (cfe1566)

1.0.4 (2018-10-09)

Bug Fixes

  • :bug:Remove trailing comma (89713a5)

1.0.3 (2018-10-09)

Features

  • Allowing Image props.

1.0.2 (2018-10-07)

Features

  • Add type definitions.

1.0.1 (2018-07-13)

Features

  • Reformat codes.

1.0.0 (2018-01-18)

Features

  • Support local images and fallback sources.

Breaking changes.

  • Remove imageURL, use source instead.

0.4.0 (2018-01-16)

Features

  • onError: :sparkles:Propagate errors to onError (4d9a14d)

0.3.4 (2017-12-20)

Features

  • Update image size on width change. (7a09dc0)

0.3.3 (2017-08-22)

Features

  • Optimize error handling from Image.getSize. (80158e7)

0.3.2 (2017-08-22)

Bug Fixes

  • rejection: :bug:Fix Possible Unhandled Promise Rejection warning. (02441ba), closes #4

0.3.1 (2017-08-08)

Bug Fixes

  • :bug:Fixed syntax error in index.js. (c384cd6)

0.3.0 (2017-07-31)

Features

  • onHeightChange: :sparkles:Provides a new api to extract the calculated height. (18c86e6)

0.2.2 (2017-05-27)

Documents

  • Update documents.

0.2.1 (2017-04-24)

Bug Fixes

  • :bug:Fix hasLoaded logic (1b8264c)

0.2.0 (2017-04-24)

Features

  • :sparkles:Support all image props (4088b73)

0.1.0 (2017-04-24)

Features