2.3.1 • Published 6 years ago

react-native-responsive-image v2.3.1

Weekly downloads
662
License
ISC
Repository
github
Last release
6 years ago

React Native Responsive Image

David npm GitHub commits npm

Why?

React Native's Image size is rendered the same regardless of device screen size and screen resolution. This component scales itself seemlesly on all iOS and Android devices.

Installation

npm install react-native-responsive-image --save

Usage

<ResponsiveImage> is expecting initWidth and initHeight props.

These values are used to set image size on any device that has screen size iPhone Plus, or larger. Image is then scaled down for any smaller device.

Optional prop component is used to pass down either an Image or ImageBackground imported react-native (defaults to Image if not provided)

Example

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, View } from 'react-native';
import ResponsiveImage from 'react-native-responsive-image';

class App extends Component {
  render() {
    return (
      <View style={{ flexGrow: 1, justifyContent: 'center', alignItems: 'center', flexDirection: 'row' }}>
          <ResponsiveImage source={{uri: 'https://reactjs.org/logo-og.png'}} initWidth="138" initHeight="138"/>
          <ResponsiveImage source={{uri: 'https://reactjs.org/logo-og.png'}} initWidth="138" initHeight="138"/>
          <ResponsiveImage source={{uri: 'https://reactjs.org/logo-og.png'}} initWidth="138" initHeight="138"/>
      </View>
    );
  }
}

AppRegistry.registerComponent('ResponsiveImageExample', () => App);

For initWidth=138 it looks like this:

DeviceScreen widthScale<Image> width
iPhone SE3200.77106
iPhone X3750.902117
iPhone8 Plus4141138
Nokia 53600.87120
iPad (or any tablet)-1138

Just one image?

It sounds like you could save some loading by delivering low resolution images to screens with lower resolution. The best way is to serve just one high-resolution (retina) well compressed image. It’s surprising how well they can be compressed, and the result looks the same.

Retina Compression

Example project

Create project

create-react-native-app ResponsiveImageExample

cp ./example/App.js ./ResponsiveImageExample/App.js

cp -R ./src ./ResponsiveImageExample

cd ResponsiveImageExample

yarn start

Development

  1. Modify any files in ./src directory

  2. Propagate changes by cp -R ./src ./ResponsiveImageExample/src

2.3.1

6 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.4

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

9 years ago

0.1.1

9 years ago

0.0.9

9 years ago