Skip to content

Commit

Permalink
Add removeImageFromDiskByKey func
Browse files Browse the repository at this point in the history
  • Loading branch information
jasminmif committed Feb 24, 2024
1 parent fb68cb7 commit 199c928
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
11 changes: 11 additions & 0 deletions ios/FastImage/FFFastImageViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ - (FFFastImageView*)view {
RCT_EXPORT_VIEW_PROPERTY(onFastImageLoadEnd, RCTDirectEventBlock)
RCT_REMAP_VIEW_PROPERTY(tintColor, imageColor, UIColor)

RCT_EXPORT_METHOD(removeImageFromDiskByKey:(NSString *)src resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"Removing image from disk with key: %@", src);
#endif
[SDImageCache.sharedImageCache removeImageFromDiskForKey:src];

resolve(NULL);
}


@end
57 changes: 32 additions & 25 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, memo } from "react";
import React, { forwardRef, memo } from 'react';
import {
View,
Image,
Expand All @@ -11,36 +11,39 @@ import {
TransformsStyle,
AccessibilityProps,
ViewProps,
} from "react-native";
NativeModules,
} from 'react-native';

import preloaderManager from "./PreloaderManager";
import preloaderManager from './PreloaderManager';

export type ResizeMode = "contain" | "cover" | "stretch" | "center";
const FastImageViewModule = NativeModules.FastImageView;

export type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center';

const resizeMode = {
contain: "contain",
cover: "cover",
stretch: "stretch",
center: "center",
contain: 'contain',
cover: 'cover',
stretch: 'stretch',
center: 'center',
} as const;

export type Priority = "low" | "normal" | "high";
export type Priority = 'low' | 'normal' | 'high';

const priority = {
low: "low",
normal: "normal",
high: "high",
low: 'low',
normal: 'normal',
high: 'high',
} as const;

type Cache = "immutable" | "web" | "cacheOnly";
type Cache = 'immutable' | 'web' | 'cacheOnly';

const cacheControl = {
// Ignore headers, use uri as cache key, fetch only if not in cache.
immutable: "immutable",
immutable: 'immutable',
// Respect http headers, no aggressive caching.
web: "web",
web: 'web',
// Only load from cache.
cacheOnly: "cacheOnly",
cacheOnly: 'cacheOnly',
} as const;

export type Source = {
Expand All @@ -65,7 +68,7 @@ export interface OnProgressEvent {
}

export interface ImageStyle extends FlexStyle, TransformsStyle, ShadowStyleIOS {
backfaceVisibility?: "visible" | "hidden";
backfaceVisibility?: 'visible' | 'hidden';
borderBottomLeftRadius?: number;
borderBottomRightRadius?: number;
backgroundColor?: string;
Expand Down Expand Up @@ -148,7 +151,7 @@ function FastImageBase({
fallback,
children,
// eslint-disable-next-line no-shadow
resizeMode = "cover",
resizeMode = 'cover',
forwardedRef,
...props
}: FastImageProps & { forwardedRef: React.Ref<any> }) {
Expand Down Expand Up @@ -201,10 +204,10 @@ const FastImageMemo = memo(FastImageBase);
const FastImageComponent: React.ComponentType<FastImageProps> = forwardRef(
(props: FastImageProps, ref: React.Ref<any>) => (
<FastImageMemo forwardedRef={ref} {...props} />
)
),
);

FastImageComponent.displayName = "FastImage";
FastImageComponent.displayName = 'FastImage';

export interface FastImageStaticProperties {
resizeMode: typeof resizeMode;
Expand All @@ -213,8 +216,9 @@ export interface FastImageStaticProperties {
preload: (
sources: Source[],
onProgress?: PreloadProgressHandler,
onComplete?: PreloadCompletionHandler
onComplete?: PreloadCompletionHandler,
) => void;
removeImageFromDiskByKey: (source: string) => Promise<void>;
}

const FastImage: React.ComponentType<FastImageProps> &
Expand All @@ -229,18 +233,21 @@ FastImage.priority = priority;
FastImage.preload = (
sources: Source[],
onProgress?: PreloadProgressHandler,
onComplete?: PreloadCompletionHandler
onComplete?: PreloadCompletionHandler,
) => preloaderManager.preload(sources, onProgress, onComplete);

const styles = StyleSheet.create({
imageContainer: {
overflow: "hidden",
overflow: 'hidden',
},
});

FastImage.removeImageFromDiskByKey = (source) =>
FastImageViewModule.removeImageFromDiskByKey(source);

// Types of requireNativeComponent are not correct.
const FastImageView = (requireNativeComponent as any)(
"FastImageView",
'FastImageView',
FastImage,
{
nativeOnly: {
Expand All @@ -250,7 +257,7 @@ const FastImageView = (requireNativeComponent as any)(
onFastImageError: true,
onFastImageLoadEnd: true,
},
}
},
);

export default FastImage;

0 comments on commit 199c928

Please sign in to comment.