diff --git a/package.json b/package.json index 9581181..307d164 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ }, "dependencies": { "crypto-js": "^3.1.9-1", + "expo-asset": "^6.0.0", "lodash": "^4.17.4" }, "peerDependencies": { diff --git a/src/Image.tsx b/src/Image.tsx index 3c7afe0..84ad99d 100644 --- a/src/Image.tsx +++ b/src/Image.tsx @@ -13,6 +13,7 @@ import { StyleProp } from "react-native"; import { BlurView } from "expo-blur"; +import { Asset } from "expo-asset"; import CacheManager, { DownloadOptions } from "./CacheManager"; @@ -24,6 +25,7 @@ interface ImageProps { uri: string; transitionDuration?: number; tint?: "dark" | "light"; + fallback?: number; } interface ImageState { @@ -66,10 +68,13 @@ export default class Image extends React.Component { this.mounted = false; } - async load({ uri, options = {} }: ImageProps): Promise { + async load({ uri, options = {}, fallback }: ImageProps): Promise { if (uri) { - const path = await CacheManager.get(uri, options).getPath(); + let path = await CacheManager.get(uri, options).getPath(); if (this.mounted) { + if (!path && fallback && Number.isInteger(fallback)) { + path = Asset.fromModule(fallback).uri; + } this.setState({ uri: path }); } }