GithubHelp home page GithubHelp logo

jiaoxuebing2014 / react-native-responsive-image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ladas-larry/react-native-responsive-image

0.0 2.0 0.0 210 KB

Responsive image component for React Native

Java 23.09% JavaScript 26.64% Objective-C 50.27%

react-native-responsive-image's Introduction

React Native Responsive Image

React Native <Image> component, that rescales itselfs correctly on iOS and Android devices.

##Why?

React Native's Image size is rendered the same regardless of device size and resolution. Desired behaviour in is to have a component, that scales appropriately.

##Installation

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

##Usage

Use the <ResponsiveImage> component and set it's initWidth and initHeight props.

These values are used as they are for iPhone6 Plus, and they are scaled down on any smaller iOS/Android device.

##Example

Three images in one full-width row:

var React = require('react-native');
var ResponsiveImage = require('react-native-responsive-image');
var {
  AppRegistry,
  StyleSheet,
  View,
} = React;

var App = React.createClass({
  render: function() {
    return (
        <View style={{flex: 1, justifyContent: 'center',}}>
            <View style={{flexDirection: 'row',}}>
  	 				<ResponsiveImage source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} initWidth="138" initHeight="138"/>
                    <ResponsiveImage source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} initWidth="138" initHeight="138"/>
                    <ResponsiveImage source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}} initWidth="138" initHeight="138"/>
            </View>
         </View>
    );
  }
});

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

##One image size?

We could have added support for multiple image sources, like https://github.com/exponentjs/react-native-responsive-image has. It sounds like you would save some bytes by delivering less-resolution images to devices with lower resolution.

But solution that worked the best for me was different. Actually you need to serve just one high-resolution compressed, and it will even save more bytes. Though @2x or @3x images have more pixels, it’s surprising how much they can be compressed.

Retina Compression

react-native-responsive-image's People

Contributors

ladas-larry avatar avishayil avatar bilalbudhani avatar taf2 avatar

Watchers

James Cloos avatar Billy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.