• Stars
    star
    146
  • Rank 252,769 (Top 5 %)
  • Language
    Java
  • License
    MIT License
  • Created about 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An image component for react-native with persistent disk and memory caching.

React Native WebImage

An image component for react-native with persistent disk and memory caching.

It is mostly a wrapper around native libraries which actually do the hard work. On Android it uses Glide, on iOS – SDWebImage.

⚠️ The package is currently in alpha stage of development. If you find a bug or missing functionality, please feel free to report, but better fix or implement what you want and send a pull request to GitHub repository.

Installation

npm install --save react-native-web-image
react-native link
version react-native
0.0.5 - 0.0.6 >=0.47.0
0.0.3 - 0.0.4 >=0.40.0
<=0.0.2 <0.40.0 (tested with 0.37.0)

Usage

import React, { Component } from 'react'
import { StyleSheet, Text, View } from 'react-native'
import WebImage from 'react-native-web-image'

export default class App extends Component {
  render() {
    const imageUri = 'https://placeholdit.imgix.net/~text?txtsize=33&txt=200x150&w=200&h=150'
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Sample image</Text>
        <View style={styles.imgContainer}>
          <WebImage style={styles.img} source={{uri:imageUri}}/>
        </View>
      </View>
    )
  }
}

const white = '#FFFFFF'
const blue = 'rgb(0,0,255)'
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: white,
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  img: {
    flex: 1,
  },
  imgContainer: {
    flexDirection: 'row',
    flex: 1,
    borderWidth: 1,
    borderColor: blue,
  }
})

API

WebImage element

<WebImage source={source}/>
Attribute Type Description
source Object Describes image source (mimics original Image element)
source.uri String (Required) URL of the image
resizeMode Enum{'cover','contain','stretch','center'} Determine resize mode for image. Default: 'contain'
onError Function Will be called on error
onLoad Function Will be called when loading of image completed

Resize modes

  • contain - Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
  • cover - Scale the image uniformly so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
  • stretch - Scale width and height independently, aspect ration will not be preserved.
  • center - Scale the image down so that it is completely visible, if bigger than the area of the view. The image will not be scaled up. The image will be placed at the center of the view.

onError(event)

  • event.nativeEvent.error - String representation of error (platform dependent)
  • event.nativeEvent.uri - URI which leads to error

onLoad(event)

  • event.nativeEvent.source.uri - URI of the loaded image
  • event.nativeEvent.source.width - width of the loaded image
  • event.nativeEvent.source.height - height of the loaded image

Author

Vladimir Timofeev

Contributors

License

  • Main source code is licensed under the MIT License.
  • SDWebImage (embedded in project) is licensed under the MIT License.
  • Glide (included via gradle) is licensed under Apache 2.0 License.

More Repositories

1

input-source-switcher

Command line input source switcher for Mac.
C++
139
star
2

go-sjson

Fast and simple JSON parser for Go
Go
21
star
3

DemoCurrencies

Demo to facilitate clean design of ReactNative applications
TypeScript
11
star
4

react-native-stylable

Cascading styles for ReactNative
JavaScript
10
star
5

mock-websocket

javascript library to mock websockets
TypeScript
8
star
6

jsc-android

Pre-build version of JavaScriptCore to be used by React Native apps
C++
5
star
7

rachota

My clone of Rachota (http://rachota.sourceforge.net). Rachota is a portable application for timetracking different projects.
Java
4
star
8

data-binarybuffer

Perl module to effectively work with binary data.
C++
3
star
9

react-native-apple-wallet

Objective-C
3
star
10

WxSharp

Try make wxWidgets bindings for .Net from scratch...
C#
3
star
11

Class-Accessor-Inherited-XS

Fast XS inherited, object and class accessors
Perl
3
star
12

perl-libevent

libevent2 bindings for Perl
C
2
star
13

react-native-certificate-check

Check certificate for validity
Objective-C
2
star
14

eslint-plugin-std

JavaScript
1
star
15

run-with-schedule

Cron for docker
Go
1
star
16

react-native-safe-area-plus

Objective-C
1
star
17

vovkasm-tslint-config

JavaScript
1
star
18

perl-Panda-NSS

Perl bindings to NSS library.
XS
1
star
19

dbicx-txninsert

Allows DBIx-Class to wrap all inserts in the transaction
Perl
1
star
20

react-native-textinput-bug

Sample to demonstrate bug #18874
Objective-C
1
star
21

RNUploadDemo

Demo react-native application that can upload files to remote server.
JavaScript
1
star
22

DBIx-RetryOverDisconnects

Release history of DBIx-RetryOverDisconnects
Perl
1
star
23

js-benchmarks

Various js benchmarks
JavaScript
1
star
24

vovkasm-eslint-config

Eslint config used by vovkasm
JavaScript
1
star
25

Catalyst-View-Component-SubInclude

Use subincludes in your Catalyst views (clone)
Perl
1
star
26

rn-ts-3.1.1

TypeScript
1
star