Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public void setResizeMode(FastImageViewWithUrl view, String resizeMode) {
view.setScaleType(scaleType);
}


@ReactProp(name = "useLastImageAsDefaultSource")
public void useLastImageAsDefaultSource(FastImageViewWithUrl view, @Nullable Boolean isActivated) {
view.useLastImageAsDefaultSource(isActivated);
}

@Override
public void onDropViewInstance(@NonNull FastImageViewWithUrl view) {
// This will cancel existing requests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.dylanvann.fastimage;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;

import static com.dylanvann.fastimage.FastImageRequestListener.REACT_ON_ERROR_EVENT;

Expand Down Expand Up @@ -28,6 +30,8 @@
import javax.annotation.Nonnull;

class FastImageViewWithUrl extends AppCompatImageView {
private Boolean mUseLastImageAsDefaultSource = false;

private boolean mNeedsReload = false;
private ReadableMap mSource = null;
private Drawable mDefaultSource = null;
Expand All @@ -38,16 +42,31 @@ public FastImageViewWithUrl(Context context) {
super(context);
}

public void setSource(@Nullable ReadableMap source) {
mNeedsReload = true;
mSource = source;
public void setSource(@Nullable ReadableMap source) {
mNeedsReload = true;
mSource = source;

if (mUseLastImageAsDefaultSource) {
Drawable currentDrawable = this.getDrawable();
if (currentDrawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) currentDrawable).getBitmap();
if (bitmap != null && !bitmap.isRecycled()) {
Bitmap defaultBitmap = bitmap.copy(bitmap.getConfig(), false);
setDefaultSource(new BitmapDrawable(getResources(), defaultBitmap));
}
}
}
}

public void setDefaultSource(@Nullable Drawable source) {
mNeedsReload = true;
mDefaultSource = source;
}

public void useLastImageAsDefaultSource(@Nullable Boolean isActivated) {
mUseLastImageAsDefaultSource = isActivated;
}

private boolean isNullOrEmpty(final String url) {
return url == null || url.trim().isEmpty();
}
Expand Down
1 change: 1 addition & 0 deletions ios/FastImage/FFFastImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@property (nonatomic, copy) RCTDirectEventBlock onFastImageError;
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoad;
@property (nonatomic, copy) RCTDirectEventBlock onFastImageLoadEnd;
@property (nonatomic, assign) BOOL useLastImageAsDefaultSource;
@property (nonatomic, assign) RCTResizeMode resizeMode;
@property (nonatomic, strong) FFFastImageSource *source;
@property (nonatomic, strong) UIImage *defaultSource;
Expand Down
8 changes: 7 additions & 1 deletion ios/FastImage/FFFastImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ - (void) setResizeMode: (RCTResizeMode)resizeMode {
}
}

- (void) setUseLastImageAsDefaultSource: (BOOL*)useLastImageAsDefaultSource {
if (useLastImageAsDefaultSource != _useLastImageAsDefaultSource) {
_useLastImageAsDefaultSource = useLastImageAsDefaultSource;
}
}

- (void) setOnFastImageLoadEnd: (RCTDirectEventBlock)onFastImageLoadEnd {
_onFastImageLoadEnd = onFastImageLoadEnd;
if (self.hasCompleted) {
Expand Down Expand Up @@ -205,7 +211,7 @@ - (void) reloadImage {
- (void) downloadImage: (FFFastImageSource*)source options: (SDWebImageOptions)options context: (SDWebImageContext*)context {
__weak typeof(self) weakSelf = self; // Always use a weak reference to self in blocks
[self sd_setImageWithURL: _source.url
placeholderImage: _defaultSource
placeholderImage: _useLastImageAsDefaultSource == YES ? [super image] : _defaultSource
options: options
context: context
progress: ^(NSInteger receivedSize, NSInteger expectedSize, NSURL* _Nullable targetURL) {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@applicaster/react-native-fast-image",
"version": "8.7.2",
"version": "8.8.1",
"description": "🚩 FastImage, performant React Native image component.",
"keywords": [
"cache",
Expand Down Expand Up @@ -78,5 +78,6 @@
"peerDependencies": {
"react": "^17 || ^18",
"react-native": ">=0.60.0"
}
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
1 change: 1 addition & 0 deletions src/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type FastImageProps = $ReadOnly<{|
tintColor?: number | string,
resizeMode?: ?ResizeModes,
fallback?: ?boolean,
useLastImageAsDefaultSource?: ?boolean,
testID?: ?string,
|}>

Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface FastImageProps extends AccessibilityProps, ViewProps {
defaultSource?: ImageRequireSource
resizeMode?: ResizeMode
fallback?: boolean
useLastImageAsDefaultSource?: boolean

onLoadStart?(): void

Expand Down