Skip to content

Commit

Permalink
Merge pull request #391 from itbel/ib-cachedimage-bug
Browse files Browse the repository at this point in the history
Bypassed cache due to downloading to cache sometime crashes the app
  • Loading branch information
itbel committed Jul 21, 2023
2 parents 6729c28 + 1fc41eb commit 15700b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
31 changes: 18 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,23 @@ export function App({ skipLoadingScreen }: Props): JSX.Element {
const navRef = createRef<NavigationContainerRef>();

async function loadResourcesAsync() {
await SplashScreen.preventAutoHideAsync();
await Promise.all([
Font.loadAsync({
'Graphik-Regular-App': require('../assets/fonts/Graphik-Regular-App.ttf'),
'Graphik-Medium-App': require('../assets/fonts/Graphik-Medium-App.ttf'),
'Graphik-Bold-App': require('../assets/fonts/Graphik-Bold-App.ttf'),
'Graphik-Semibold-App': require('../assets/fonts/Graphik-Semibold-App.ttf'),
'Graphik-RegularItalic': require('../assets/fonts/Graphik-RegularItalic.otf'),
}),
]);
setLoadingComplete(true);
await SplashScreen.hideAsync();
try {
await SplashScreen.preventAutoHideAsync();
await Promise.all([
Font.loadAsync({
'Graphik-Regular-App': require('../assets/fonts/Graphik-Regular-App.ttf'),
'Graphik-Medium-App': require('../assets/fonts/Graphik-Medium-App.ttf'),
'Graphik-Bold-App': require('../assets/fonts/Graphik-Bold-App.ttf'),
'Graphik-Semibold-App': require('../assets/fonts/Graphik-Semibold-App.ttf'),
'Graphik-RegularItalic': require('../assets/fonts/Graphik-RegularItalic.otf'),
}),
]);
} catch (error) {
console.log({ error });
} finally {
setLoadingComplete(true);
await SplashScreen.hideAsync();
}
}

async function registerForPushNotificationsAsync(): Promise<DevicePushToken | null> {
Expand Down Expand Up @@ -262,7 +267,7 @@ export function App({ skipLoadingScreen }: Props): JSX.Element {
await trackUserId(user);
} catch (e) {
console.debug(e);
setLocationData({ id: 'unknown', name: 'unknown' });
setLocationData({ id: 'unknown', name: 'unknown' } as LocationData);
try {
const location = await SecureStore.getItemAsync('location');
if (location) {
Expand Down
8 changes: 5 additions & 3 deletions src/hooks/useCachedImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ export default function useCachedImage(url: string, cacheKey: string) {
const path = `${FileSystem.cacheDirectory}${name}`;
const image = await FileSystem.getInfoAsync(path);
if (image.exists) {
console.log({ success: image.uri });
setUri(image.uri);
return;
}
// console.warn('Image doesnt exist!', { memoizedURL }, { name });
const newImage = await FileSystem.downloadAsync(memoizedURI, path);
setUri(newImage.uri);
console.warn({ path });
// const newImage = await FileSystem.downloadAsync(memoizedURI, path);
setUri(url);
} catch (error) {
console.error({ error });
setUri(memoizedURL);
} finally {
setIsLoading(false);
}
})();
}, [memoizedKey, memoizedURI, memoizedURL]);
}, [url, memoizedKey, memoizedURI, memoizedURL]);
return { isLoading, uri, setUri };
}

0 comments on commit 15700b6

Please sign in to comment.