forked from fabioh8010/ExpoImageTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native-fast-image+8.6.3.patch
63 lines (62 loc) · 3.09 KB
/
react-native-fast-image+8.6.3.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
diff --git a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java
index 34fcf89..2a8d0bd 100644
--- a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java
+++ b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageViewWithUrl.java
@@ -142,7 +142,9 @@ class FastImageViewWithUrl extends AppCompatImageView {
.apply(FastImageViewConverter
.getOptions(context, imageSource, mSource)
.placeholder(mDefaultSource) // show until loaded
- .fallback(mDefaultSource)); // null will not be treated as error
+ .fallback(mDefaultSource)) // null will not be treated as error
+ .transform(new ResizeTransformation()); // Apply custom ResizeTransformation with a maximum height of 8000
+
if (key != null)
builder.listener(new FastImageRequestListener(key));
diff --git a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/ResizeTransformation.java b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/ResizeTransformation.java
new file mode 100644
index 0000000..cd0a5d8
--- /dev/null
+++ b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/ResizeTransformation.java
@@ -0,0 +1,41 @@
+package com.dylanvann.fastimage;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+
+import androidx.annotation.NonNull;
+
+import com.bumptech.glide.load.Transformation;
+import com.bumptech.glide.load.engine.Resource;
+import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
+import com.bumptech.glide.load.resource.bitmap.BitmapResource;
+
+import java.security.MessageDigest;
+
+public class ResizeTransformation implements Transformation<Bitmap> {
+
+ private final double MAX_BYTES = 25000000.0;
+
+ @NonNull
+ @Override
+ public Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) {
+ Bitmap toTransform = resource.get();
+
+ if (toTransform.getByteCount() > MAX_BYTES) {
+ double scaleFactor = Math.sqrt(MAX_BYTES / (double) toTransform.getByteCount());
+ int newHeight = (int) (outHeight * scaleFactor);
+ int newWidth = (int) (outWidth * scaleFactor);
+
+ BitmapPool pool = GlideApp.get(context).getBitmapPool();
+ Bitmap scaledBitmap = Bitmap.createScaledBitmap(toTransform, newWidth, newHeight, true);
+ return BitmapResource.obtain(scaledBitmap, pool);
+ }
+
+ return resource;
+ }
+
+ @Override
+ public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
+ messageDigest.update(("ResizeTransformation").getBytes());
+ }
+}
\ No newline at end of file