Skip to content

fixed defaultProps #82

@jimmydjabali

Description

@jimmydjabali

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @georstat/react-native-image-cache@3.1.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@georstat/react-native-image-cache/src/CacheManager.ts b/node_modules/@georstat/react-native-image-cache/src/CacheManager.ts
index 46bdcf2..fca26b3 100644
--- a/node_modules/@georstat/react-native-image-cache/src/CacheManager.ts
+++ b/node_modules/@georstat/react-native-image-cache/src/CacheManager.ts
@@ -1,6 +1,7 @@
 // @ts-ignore
 import SHA1 from 'crypto-js/sha1';
 import { FileStat, FileSystem } from 'react-native-file-access';
+import * as ExpoFileSystem from "expo-file-system";
 
 import { Config, DownloadOptions } from './types';
 import defaultConfiguration from './defaultConfiguration';
@@ -179,7 +180,7 @@ export default class CacheManager {
   }
 
   static async clearCache(): Promise<void> {
-    if (await FileSystem.exists(CacheManager.config.baseDir)) {
+    if ((await ExpoFileSystem.getInfoAsync(CacheManager.config.baseDir)).exists) {
       const files = await FileSystem.ls(CacheManager.config.baseDir);
       for (const file of files) {
         try {
@@ -265,7 +266,7 @@ export default class CacheManager {
       while (overflowSize > 0 && files.length) {
         const file = files.shift();
         if (file) {
-          if (await FileSystem.exists(file.path)) {
+          if ((await ExpoFileSystem.getInfoAsync(file.path)).exists) {
             overflowSize = overflowSize - file.size;
             await FileSystem.unlink(file.path).catch(e => {
               if (__DEV__) {
@@ -300,11 +301,11 @@ const getCacheEntry = async (
 
   // TODO: maybe we don't have to do this every time
   try {
-    await FileSystem.mkdir(CacheManager.config.baseDir);
+    // await FileSystem.mkdir(CacheManager.config.baseDir);
   } catch (e) {
     /* do nothing */
   }
-  const exists = await FileSystem.exists(path);
+  const exists = (await ExpoFileSystem.getInfoAsync(path)).exists;
 
   if (maxAge && exists) {
     const { lastModified } = await FileSystem.stat(path);
diff --git a/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx b/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
index 9549160..148dc3c 100644
--- a/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
+++ b/node_modules/@georstat/react-native-image-cache/src/CachedImage.tsx
@@ -7,6 +7,7 @@ import React, {
   useRef,
 } from 'react';
 import {
+  ImageErrorEventData,
   ImageLoadEventData,
   ImageSourcePropType,
   NativeSyntheticEvent,
@@ -26,10 +27,6 @@ import { isAndroid, isImageWithRequire, isRemoteImage } from './helpers';
 const AnimatedImage = Animated.Image;
 const AnimatedView = Animated.View;
 
-const defaultProps = {
-  onError: () => {},
-};
-
 function useIsComponentMounted() {
   const isMounted = useRef(false);
   // @ts-ignore
@@ -58,13 +55,13 @@ function useStateIfMounted<S>(
   return [state, newSetState];
 }
 
-const CachedImage = (props: IProps & typeof defaultProps) => {
+const CachedImage = ({ onError: propsOnError = () => {}, ...props }: IProps) => {
   const [error, setError] = useStateIfMounted<boolean>(false);
   const [uri, setUri] = useStateIfMounted<string | undefined>(undefined);
   const { source: propsSource, options: propsOptions } = props;
   const currentSource = useRef<string>(propsSource);
 
-  const animatedImage = useSharedValue(0);
+  const animatedImage = useSharedValue(1);
   const animatedThumbnailImage = useSharedValue(0);
   const animatedLoadingImage = useSharedValue(1);
 
@@ -146,9 +143,9 @@ const CachedImage = (props: IProps & typeof defaultProps) => {
     });
   };
 
-  const onImageError = (): void => {
-    if (props.onError) {
-      props.onError();
+  const onImageError = (e: NativeSyntheticEvent<ImageErrorEventData>): void => {
+    if (propsOnError) {
+      propsOnError(e);
     }
     setError(true);
   };
@@ -291,6 +288,4 @@ const styles = StyleSheet.create({
   },
 });
 
-CachedImage.defaultProps = defaultProps;
-
 export default CachedImage;

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions