From a201ca2c59881bec99da320aab5a14178b8c46b6 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Tue, 4 Feb 2025 22:22:20 +0000 Subject: [PATCH 01/12] feat: apply blinking patch to android --- .../fastimage/FastImageViewManager.java | 6 ++++++ .../fastimage/FastImageViewWithUrl.java | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java index 0e3329a61..390ac9a83 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java @@ -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. diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java index bd144b6fa..72853c0c1 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java @@ -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; @@ -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; @@ -41,6 +45,14 @@ public FastImageViewWithUrl(Context context) { public void setSource(@Nullable ReadableMap source) { mNeedsReload = true; mSource = source; + + if (mUseLastImageAsDefaultSource) { + BitmapDrawable currentDrawable = (BitmapDrawable) this.getDrawable(); + Bitmap toBmp = currentDrawable == null ? null : currentDrawable .getBitmap(); + if (toBmp != null && !toBmp.isRecycled()) { + this.setDefaultSource(new BitmapDrawable(getResources(), toBmp.copy(toBmp.getConfig(), false))); + } + } } public void setDefaultSource(@Nullable Drawable source) { @@ -48,6 +60,10 @@ public void setDefaultSource(@Nullable Drawable source) { mDefaultSource = source; } + public void useLastImageAsDefaultSource(@Nullable Boolean isActivated) { + mUseLastImageAsDefaultSource = isActivated; + } + private boolean isNullOrEmpty(final String url) { return url == null || url.trim().isEmpty(); } From e59fb7460eb2a2b8a965b6262eda83961220f2bf Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Tue, 4 Feb 2025 22:22:26 +0000 Subject: [PATCH 02/12] feat: apply blinking patch to ios --- ios/FastImage/FFFastImageView.h | 1 + ios/FastImage/FFFastImageView.m | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ios/FastImage/FFFastImageView.h b/ios/FastImage/FFFastImageView.h index e52fca798..f2951b18e 100644 --- a/ios/FastImage/FFFastImageView.h +++ b/ios/FastImage/FFFastImageView.h @@ -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; diff --git a/ios/FastImage/FFFastImageView.m b/ios/FastImage/FFFastImageView.m index f7100815e..f7cffc520 100644 --- a/ios/FastImage/FFFastImageView.m +++ b/ios/FastImage/FFFastImageView.m @@ -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) { @@ -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) { From 7b977835a5fb7fd9b101e06fe728dc552f7ddf60 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Tue, 4 Feb 2025 22:24:41 +0000 Subject: [PATCH 03/12] chore: bump to dev-version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83ed61d5a..2e4b08cbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@applicaster/react-native-fast-image", - "version": "8.7.2", + "version": "8.8.0-dev.0", "description": "🚩 FastImage, performant React Native image component.", "keywords": [ "cache", From c2db45ebc6d2015c6e2480d5a335bb0c0a5f5a7a Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Tue, 4 Feb 2025 22:54:35 +0000 Subject: [PATCH 04/12] chore: added new prop to types --- src/index.js.flow | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js.flow b/src/index.js.flow index 57908331d..b4358399b 100644 --- a/src/index.js.flow +++ b/src/index.js.flow @@ -64,6 +64,7 @@ export type FastImageProps = $ReadOnly<{| tintColor?: number | string, resizeMode?: ?ResizeModes, fallback?: ?boolean, + useLastImageAsDefaultSource?: ?boolean, testID?: ?string, |}> From 0102f68bd9d2f6d49ea4add296b03afc29296a70 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Tue, 4 Feb 2025 22:55:11 +0000 Subject: [PATCH 05/12] chore: bumped version --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2e4b08cbf..87cff7879 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@applicaster/react-native-fast-image", - "version": "8.8.0-dev.0", + "version": "8.8.0-dev.1", "description": "🚩 FastImage, performant React Native image component.", "keywords": [ "cache", @@ -78,5 +78,6 @@ "peerDependencies": { "react": "^17 || ^18", "react-native": ">=0.60.0" - } + }, + "packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610" } From 3c426cf882f4d185fea54d33b0a3034f65ad4cba Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Wed, 5 Feb 2025 12:05:10 +0000 Subject: [PATCH 06/12] chore: add type to ts --- src/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.tsx b/src/index.tsx index e1888961b..54dde32c9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -87,6 +87,7 @@ export interface FastImageProps extends AccessibilityProps, ViewProps { defaultSource?: ImageRequireSource resizeMode?: ResizeMode fallback?: boolean + useLastImageAsDefaultSource?: boolean onLoadStart?(): void From 86d60fe484f380f84f08c20bf73590cefa2c3451 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Wed, 5 Feb 2025 12:05:34 +0000 Subject: [PATCH 07/12] chore: version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 87cff7879..7cfd24804 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@applicaster/react-native-fast-image", - "version": "8.8.0-dev.1", + "version": "8.8.0-dev.2", "description": "🚩 FastImage, performant React Native image component.", "keywords": [ "cache", From 6a693c1d0802d7b6d8d466c233c4f22f810453bf Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Wed, 5 Feb 2025 20:06:29 +0000 Subject: [PATCH 08/12] feat: don't run new function if image wasnt set --- .../com/dylanvann/fastimage/FastImageViewWithUrl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java index 72853c0c1..6c7c9ae08 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java @@ -48,9 +48,11 @@ public void setSource(@Nullable ReadableMap source) { if (mUseLastImageAsDefaultSource) { BitmapDrawable currentDrawable = (BitmapDrawable) this.getDrawable(); - Bitmap toBmp = currentDrawable == null ? null : currentDrawable .getBitmap(); - if (toBmp != null && !toBmp.isRecycled()) { - this.setDefaultSource(new BitmapDrawable(getResources(), toBmp.copy(toBmp.getConfig(), false))); + if(currentDrawable != null) { + Bitmap toBmp = currentDrawable == null ? null : currentDrawable.getBitmap(); + if (toBmp != null && !toBmp.isRecycled()) { + this.setDefaultSource(new BitmapDrawable(getResources(), toBmp.copy(toBmp.getConfig(), false))); + } } } } From ccbd4446044196c5e87e057aa33aab39e64d0167 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Thu, 6 Feb 2025 12:10:26 +0000 Subject: [PATCH 09/12] chore: bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7cfd24804..3fd14a7da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@applicaster/react-native-fast-image", - "version": "8.8.0-dev.2", + "version": "8.8.0-dev.3", "description": "🚩 FastImage, performant React Native image component.", "keywords": [ "cache", From 694c5432f7e00a75e671be261a91286975a183f3 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Thu, 6 Feb 2025 15:39:31 +0000 Subject: [PATCH 10/12] chore: bumped to stable --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fd14a7da..017b733c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@applicaster/react-native-fast-image", - "version": "8.8.0-dev.3", + "version": "8.8.0", "description": "🚩 FastImage, performant React Native image component.", "keywords": [ "cache", From 9d1175f95f463dfde27eb0e138a967552fad4753 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Thu, 6 Feb 2025 16:01:43 +0000 Subject: [PATCH 11/12] chore: improve code reliability --- .../fastimage/FastImageViewWithUrl.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java index 6c7c9ae08..ccff6bce8 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java @@ -42,20 +42,21 @@ public FastImageViewWithUrl(Context context) { super(context); } - public void setSource(@Nullable ReadableMap source) { - mNeedsReload = true; - mSource = source; - - if (mUseLastImageAsDefaultSource) { - BitmapDrawable currentDrawable = (BitmapDrawable) this.getDrawable(); - if(currentDrawable != null) { - Bitmap toBmp = currentDrawable == null ? null : currentDrawable.getBitmap(); - if (toBmp != null && !toBmp.isRecycled()) { - this.setDefaultSource(new BitmapDrawable(getResources(), toBmp.copy(toBmp.getConfig(), false))); - } +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; From 8578addea749b0b9353d96fe8850f8054034f5f0 Mon Sep 17 00:00:00 2001 From: Pawel Buderaski Date: Thu, 6 Feb 2025 16:01:58 +0000 Subject: [PATCH 12/12] chore: bumped --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 017b733c5..77f5df5f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@applicaster/react-native-fast-image", - "version": "8.8.0", + "version": "8.8.1", "description": "🚩 FastImage, performant React Native image component.", "keywords": [ "cache",