Skip to content

Commit

Permalink
Fixed issue when there are duplicate image sources and both fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mthahzan committed Jun 4, 2017
1 parent b00789e commit 6130ce0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Image loader component with fallback options for React Native apps",
"main": "index.js",
"license": "MIT",
"version": "0.0.3",
"version": "0.0.4",
"keywords": [
"react-native",
"react-native-component",
Expand Down
7 changes: 5 additions & 2 deletions src/components/ImageLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class ImageLoader extends React.PureComponent {

// Return the filtered out image sources
// No null should be present here
return imageSources.filter((imageSource) => imageSource);
// Also, please no duplicates
return [...new Set(imageSources.filter((imageSource) => imageSource))];
}

/**
Expand Down Expand Up @@ -154,13 +155,15 @@ class ImageLoader extends React.PureComponent {
// Figure out what type of image we are dealing with
switch (typeof imageSource) {
case 'string':
// If a string is given, we assume it's a URI
source = {
uri: imageSource,
};

break;
case 'number':
// Opaque type returned by require('./image.jpg')
// If a number is given,
// we assume it's an opaque type returned by require('./image.jpg')
source = imageSource;

break;
Expand Down

0 comments on commit 6130ce0

Please sign in to comment.