Giter VIP home page Giter VIP logo

react-native-image-progress's Introduction

react-native-image-progress Travis npm version

Progress indicator for networked images in React Native

Installation

yarn add react-native-image-progress

Note: Progress indicators has been broken out to a separate component; react-native-progress. To use them, please follow installation instructions for that package.

Usage

import Image from 'react-native-image-progress';
import ProgressBar from 'react-native-progress/Bar';
<Image 
  source={{ uri: 'http://loremflickr.com/640/480/dog' }} 
  indicator={ProgressBar} 
  style={{
    width: 320, 
    height: 240, 
  }}/>

Properties

Any Image property and the following:

Prop Description Default
imageStyle Styles applied to the inner image component. None
indicator A component to display progress, will be passed a progress prop with a number between 0 and 1 and indeterminate a boolean wether or not component has started recieveing data. ActivityIndicator
indicatorProps An object of props being passed to the indicator component. To disable indeterminate state, pass {indeterminate: false}. None
renderIndicator(progress, indeterminate) Function to render your own custom indicator, useful for something very simple. If not, consider breaking it out to a separate component and use indicator prop instead. None
renderError(error) Function to render your own custom error message or image fallback. None
threshold Number of milliseconds after mount to wait before displaying the indicator. Basically a workaround for cached images not to flash a spinner. Set to 0 to disable. 50

Note: onLoad* events are bubbled up, so if you want to do some custom thing when the image is loaded for example.

Demo

image-progress-demo

Example

Check full example in the Example folder.

Pie

import Image from 'react-native-image-progress';
import Progress from 'react-native-progress';
<Image 
  source={{ uri: 'http://loremflickr.com/640/480/dog' }} 
  indicator={Progress.Pie}
  indicatorProps={{
    size: 80,
    borderWidth: 0,
    color: 'rgba(150, 150, 150, 1)',
    unfilledColor: 'rgba(200, 200, 200, 0.2)'
  }}
  style={{
    width: 320,
    height: 240,
  }}/>

Using a custom image component

For some use cases such as better GIF support or more granular control over caching you might want to use a custom image component, to do this simply use the createImageProgress function:

import { createImageProgress } from 'react-native-image-progress';
import FastImage from 'react-native-fast-image';

const Image = createImageProgress(FastImage);

NOTE: the alternative image implementation must conform to the core Image component life cycle props, notably onProgress, onError, onLoad and onLoadStart.

License

MIT License. © Joel Arvidsson

react-native-image-progress's People

Contributors

adba avatar jjingrong avatar juangl avatar jwoo92 avatar kamal avatar koenpunt avatar oblador avatar ochanje210 avatar philipheinser avatar pizzaliu avatar rgabs avatar shuaibird avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-image-progress's Issues

Issue with StyleSheet.create()

when accessing properties from StyleSheet.create() it will return a number instead of an object. in the propType imageStyle its expecting an object which isn't 100% compatible. you should also say it can be a number.

rounded corners with Version 1.0.1

with version 0.6.0 the styles was passed to the ImageComponent, with the new version the are overrided:

style={StyleSheet.absoluteFill}

how can I create rounded images with the new version?

could it be a solution to use both styles on the image and not on the view:

style={[StyleSheet.absoluteFill, style]}

===update===

I just see the pull request #41 and your remark, what about two styles props one for the ViewWrapper and one for the image?

see my pull request #45

App has stopped

I have followed the example about ProgressPie and the application is not working.
I follow the first example about ProgressBar and it's working fine.
How could I solve it ?

Cannot read property 'loading' of undefined

When using this component I get the above error pointing to:

ImageProgress._this2.handleLoadStart
index.js:28

which relates to:

handleLoadStart = () => {
    if (!this.state.loading && this.state.progress !== 1) {

Just incase, I'm using:

"react": "^15.1.0",
"react-native": "^0.28.0",
"react-native-image-progress": "^0.6.0",

Progress doesn't work on Indicators

Hi, I've installed both libraries, and am using ProgressCircle:

import Image from 'react-native-image-progress';
import ProgressCircle from 'react-native-progress/Circle';

... 

<Image
        source={{ uri: 'http://loremflickr.com/640/480/dog' }}
        indicator={ProgressCircle}
        indicatorProps={{
          showsText: true,
        }}
        style={{
          width: 320,
          height: 240,
        }}
 />

But the indicator just spins randomly, no signal of any progress and no text showed as well. After a while the picture is rendered.

I also tried adding indeterminate: false into indicatorProps. This time it shows text but is locked at 0%; then after a while picture is rendered.

What possibly have I done wrong?

Error with react v0.20 - this._easing is undefined

When I updated to v0.20 (from v0.18) I get the following error using the image loader and progress components.

screen shot 2016-03-05 at 12 48 59

<ImageLoader
    indicator={Progress.CircleSnail}
    indicatorProps={{
        size: this.props.indicatorSize || 60,
        color: colour.blue
    }}
    threshold={100}
    {...this.props}
/>

[feature request] Do not show a loadingIndicator if the request happens within a short amount of time

Could you please provide an implementation with a threshold property? If the request finished before the threshold is reached, it will not show any loadingIndicator at all.

In my case it looks very strange when I'm going to show a'lot of cached images. It will flicker the indicator in and out.

I could try to implement it myself, if I got some time next week. What do you think about this feature?

Thanks a'lot!

Is this Library mentained?

Hey,
this library looks pretty good. Any chances the pending PR's are going to get merged or are there reasons why they aren't merged?

Thanks
Daniel

Compile to ES5 for usage on web?

Is it possible to run this module's ES6 through babel to compile down to ES5 before publishing to NPM? This way we can use this library on web projects via react-native-web!

renderError

Hi,When I load too many images in the list, I will execute the renderError function. Is there a solution?

Could not find image file yellow box warning

Hey there. I receive several "Could not find image file" yellow box warning when using this component. Any ideas how to "fix" this?

import { createImageProgress } from "react-native-image-progress";

const ImageComponent = props => {
    const style = [props.style, { borderRadius: 8 }];
    const newProps = { ...props, style };
    return <Image {...newProps} />;
};

const ImageProgress = createImageProgress(ImageComponent);

 <ImageProgress
            renderIndicator={() => (
                <ActivityIndicator
                    animating={true}
                    color={styles.thumbnailIndicatorColor}
                    size="small"
                    style={{ position: "absolute", right: 20 }}
                />
            )}
            source={{ uri: document.thumbnail }}
            style={styles.thumbnail}
        />

screen shot 2017-11-24 at 22 35 33

SVG support

Hello,

Does the lib support svg files ? I am trying to use the lib react-native-svg-uri in the renderIndicator() of the PlaceholderImage() but it seems that it doesn't work because I receive an error message : Failed prop type : Invalide prop 'source' supplied to 'Image'.

Thanks !

Request: Provide generic progress event/callback

For those of us who may have a completely different idea of how to show the progress indicator (and to save you from serving requests for different styles) you might consider adding a generic callback and/or event in the forms:

<Image indicator={(progress) => console.log(`${Math.round(progress * 100)}%`)}/>

or

<Image ref="blah"/>
...
this.refs.blah.on('progress', (progress) => console.log(`${Math.round(progress * 100)}%`));

Nice work so far! :)

Caching

Can you provide caching of images anytime soon? When re-rendering the host component - I don't want to fetch the images again and again in case they are from external source.

Compatibility with react-native-lightbox

Hey!

First, I just realised you were responsible for at least half of the components I use on my current project, and they are all awesome, so thank you deeply!

Funnily enough, I have a very small issue when combining the image progress and your awesome lightbox : When you tap on the Image to "grow", you can see the loader in front of the image for something like 300ms, and then disappear.

This is obviously not a pressing issue, and more of a heads up, I'm sure it's nothing!

Again thanks for your absolutely wonderful work, I'll start following what you do, awesome you!

1.0.0 Bug: Cannot specify Image height/width

After upgrading to 1.0.0, a bunch of my Image components are not being correctly sized. I am applying height and width via the style prop:

import Image from 'react-native-image-progress';

<Image
  ...
  source={...}
  style={{
    height: 50,
    width: 200,
  }}
  ...
/>

However on 1.0.0, these height and width style attributes are not being respected and the image is not being resized. The images are rendering at the source image's natural height and natural width.

resizeMode not working

Hi,

The resizeMode props for image is not working (or maybe, I don't know how to use it)...

screenshot from 2017-07-11 22-53-33

Here is my component :
<Image style={ style.image__element } source={{uri: this.props.randomBeer.image_url }} indicatorProps={{ color: '#B53409', size: 'large' }} ></Image>

Here is my style :
image__element: { flex: 1, resizeMode: 'contain' }

Is there an alternative ?

Thanks

Progress doesn't disappear for cached images

I am using this package along with react-native-fast-image. The first time when the image is opened, the progress bar is shown as expected and the progress bar disappears after the image is downloaded. But after that, when I view the image again, the progress bar is shown again and it just stays there. I expected the progress bar to not show up at all as the image is already cached. I tried using different values for threshold but that didn't help.

Below is the code to show the image

<ImageWithProgress
          source={{ uri: this.props.imagePath }}
          style={{
            position: 'absolute',
            right: 0,
            left: 0,
            top: 0,
            bottom: 0
          }}
          indicator={ProgressBar}
          indicatorProps={{
            size: 80,
            borderWidth: 0,
            color: 'rgba(150, 150, 150, 1)',
            unfilledColor: 'rgba(200, 200, 200, 0.2)'
          }}
          threshold={200}
        />

Below is a gif showing the continuous progress bar
progressimage

I am not sure if this is an issue or I am missing something in the code. Please comment either ways.

I am trying this on iOS emulator.

Version information:
react-native-image-progress - 1.0.1
react-native-progress - 3.4.0
react-native-fast-image - 2.0.1
react-native - 0.52.4

Followed instructions, but example only shows blank screen

I followed the instructions to install react-native-progress, and tested with the examples, it displays normally.
But when I copy the code in this repo's example folder to the project created with "react-native init",
run-ios only displays a blank screen, no error.

My package.json:

{
	"name": "ReactNativeImageProgress",
	"version": "0.0.1",
	"private": true,
	"scripts": {
		"start": "node node_modules/react-native/local-cli/cli.js start",
		"test": "jest"
	},
	"dependencies": {
		"react": "16.0.0-alpha.12",
		"react-native": "0.46.1",
		"react-native-image-progress": "^1.0.1",
		"react-native-progress": "^3.3.0"
	},
	"devDependencies": {
		"babel-jest": "20.0.3",
		"babel-preset-react-native": "2.1.0",
		"jest": "20.0.4",
		"react-test-renderer": "16.0.0-alpha.12"
	},
	"jest": {
		"preset": "react-native"
	}
}

My index.ios.js:

import React, { Component } from 'react';
import { StyleSheet, TouchableOpacity, View, AppRegistry } from 'react-native';

import Image from 'react-native-image-progress';
import * as Progress from 'react-native-progress';

const INDICATORS = [null, Progress.Bar, Progress.Circle, Progress.Pie];

const IMAGES = [
  'http://www.savethecat.com/wp-content/uploads/2015/06/cats.jpg',
  'http://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg',
  'http://media4.popsugar-assets.com/files/2014/08/08/878/n/1922507/caef16ec354ca23b_thumb_temp_cover_file32304521407524949.xxxlarge/i/Funny-Cat-GIFs.jpg',
  'http://media1.santabanta.com/full1/Animals/Cats/cats-87a.jpg',
  'http://awesomegifs.com/wp-content/uploads/cat-smacks-at-hands.gif',
];

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  image: {
    width: 300,
    height: 200,
  },
});

const pseudoRandom = () => 0.5 - Math.random();

const getRandomIndicator = () => INDICATORS.slice(0).sort(pseudoRandom)[0];

const getRandomImage = excludeUri => {
  const imageUrl = IMAGES.filter(
    uri => !excludeUri || excludeUri.indexOf(uri) !== 0,
  ).sort(pseudoRandom)[0];
  return `${imageUrl}?rand=${Date.now()}`;
};

const getRandomState = excludeUri => ({
  imageUri: getRandomImage(excludeUri),
  indicator: getRandomIndicator(),
});

export default class ReactNativeImageProgress extends Component {
  constructor(props) {
    super(props);
    this.state = getRandomState();
  }

  randomize = () => {
    this.setState(getRandomState(this.state.imageUri));
  };

  render() {
    console.log(this.state);
    return (
      <View style={styles.container}>
        <TouchableOpacity onPress={this.randomize}>
          <Image
            key={this.state.imageUri}
            source={{ uri: this.state.imageUri }}
            indicator={this.state.indicator}
            style={styles.image}
            onLoaded={() => console.log('Image was loaded!')}
          />
        </TouchableOpacity>
      </View>
    );
  }
}

AppRegistry.registerComponent('ReactNativeImageProgress', () => ReactNativeImageProgress);

I tried to clone this repo, and yarn inside example folder, run-ios inside it works just fine, strange.

`isWeb` prop for web compatibility

It would be awesome if this package exposed an isWeb prop or something of the sort. Instead of importing always from react-native, when isWeb prop is true the components import from react-native-web.

All of the components used by this package are exported by react-native-web, so adding this simple if / else would allow this package to work on web.

Thoughts?

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.