# react-native-autosize-image

> react-native image width auto width or height computation

Latest version **0.1.3** (published 2020-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-autosize-image
pnpm add react-native-autosize-image
yarn add react-native-autosize-image
bun add react-native-autosize-image
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2020-09-29 |
| First published | 2020-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 28 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | vivaxy |
| Maintainers | egorshulga |
| Keywords | react-native, image, auto-height, auto-wudth, react, images |

## Links

- npm: https://www.npmjs.com/package/react-native-autosize-image
- Repository: https://github.com/egorshulga/react-native-autosize-image
- Homepage: https://github.com/egorshulga/react-native-autosize-image#readme
- Issues: https://github.com/egorshulga/react-native-autosize-image/issues
- npm.io page: https://npm.io/package/react-native-autosize-image

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2020-09-29
- 0.1.2 — 2020-09-18
- 0.1.1 — 2020-08-06
- 0.1.0 — 2020-08-06

## README

# react-native-autosize-image

Inspired by [vivaxy/react-native-auto-height-image](https://github.com/vivaxy/react-native-auto-height-image)

[![NPM Version](http://img.shields.io/npm/v/react-native-autosize-image.svg?style=flat-square)](https://www.npmjs.com/package/react-native-autosize-image)
[![NPM Downloads](https://img.shields.io/npm/dt/react-native-autosize-image.svg?style=flat-square)](https://www.npmjs.com/package/react-native-autosize-image)
[![MIT License](https://img.shields.io/npm/l/react-native-autosize-image.svg?style=flat-square)](./LICENSE)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg?style=flat-square)](https://conventionalcommits.org)
[![Financial Contributors on Open Collective](https://opencollective.com/react-native-autosize-image/all/badge.svg?label=financial+contributors)](https://opencollective.com/react-native-autosize-image)

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:

```js
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:

```js
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

| name               | type             | isRequired    | default           | description                                                           |
| ---                | ---              | ---           | ---               | ---                                                                   |
| `mainAxisSize`            | number           | ✔             | N/A               | image mainAxisSize to fit                                                    |
| `mainAxis`            | 'horizontal'|'vertical'           | ✔             | N/A               | main axis                                                    |
| `maxCrossAxisSize`            | number           | ✖             | `Infinity`               | image max crossAxisSize                                                    |
| `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: '...'})            |
| `onCrossAxisSizeChange`   | func             | ✖             | `(crossAxisSize) => {}`    | called when updating image crossAxisSize, the argument `crossAxisSize` might be `0` |
| `animated`        | bool              | ✖              | `false`               | Use `Animated.Image` instead of `Image` |

Other image props except `resizeMode` are accepted.

## Change Log

[Change log](./CHANGELOG.md)

## Contributing

[Contributing](./CONTRIBUTING.md)

## Licence

[MIT](./LICENSE)

---
_Source: https://npm.io/package/react-native-autosize-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
