Skip to content

Commit

Permalink
fix(API): Fix regression for local images
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Dec 6, 2017
2 parents 6dd125b + 3fbfcb0 commit 29df38f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,11 @@ export abstract class BaseCachedImage<P extends CachedImageProps> extends Compon
}


private checkSource(source: number | ImageURISource | ImageURISource[]): ImageURISource {
private checkSource(source: number | ImageURISource | ImageURISource[]): ImageURISource | number {
if (Array.isArray(source)) {
throw new Error(`Giving multiple URIs to CachedImage is not yet supported.
If you want to see this feature supported, please file and issue at
https://github.com/wcandillon/react-native-img-cache`);
} else if (typeof(source) === "number") {
throw new Error(`Provided an image that is available locally already.`);
}
return source;
}
Expand All @@ -202,15 +200,15 @@ export abstract class BaseCachedImage<P extends CachedImageProps> extends Compon
const {mutable} = this.props;
const source = this.checkSource(this.props.source);
this.setState({ path: undefined });
if (source.uri) {
if (typeof(source) !== "number" && source.uri) {
this.observe(source as CachedImageURISource, mutable === true);
}
}

componentWillReceiveProps(nextProps: P) {
const {mutable} = nextProps;
const source = this.checkSource(nextProps.source);
if (source.uri) {
if (typeof(source) !== "number" && source.uri) {
this.observe(source as CachedImageURISource, mutable === true);
}
}
Expand Down

0 comments on commit 29df38f

Please sign in to comment.