@@ -10,6 +10,7 @@ import android.graphics.RectF
10
10
import android.graphics.Path
11
11
import android.graphics.drawable.BitmapDrawable
12
12
import android.graphics.drawable.Drawable
13
+ import android.net.Uri
13
14
import android.os.Build
14
15
import android.util.Base64
15
16
import android.view.View
@@ -18,6 +19,7 @@ import android.widget.ImageView.ScaleType
18
19
import androidx.appcompat.widget.AppCompatImageView
19
20
import coil.annotation.ExperimentalCoilApi
20
21
import coil.imageLoader
22
+ import coil.memory.MemoryCache
21
23
import coil.request.CachePolicy
22
24
import coil.request.ImageRequest
23
25
import coil.size.Scale
@@ -93,9 +95,10 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
93
95
val failureImage = options.getString(" failureImage" )
94
96
val grayscale = if (options.hasKey(" grayscale" )) options.getDouble(" grayscale" ) else 0.0
95
97
val allowHardware = if (options.hasKey(" allowHardware" )) options.getBoolean(" allowHardware" ) else true
96
- val headers = options.getMap(" headers" )
98
+ val headers = options.getMap(" headers" )
99
+ val ignoreQueryParamsForCacheKey = if (options.hasKey(" ignoreQueryParamsForCacheKey" )) options.getBoolean(" ignoreQueryParamsForCacheKey" ) else false
97
100
98
- val borderRadii = BorderRadii (
101
+ val borderRadii = BorderRadii (
99
102
uniform = if (options.hasKey(" borderRadius" )) options.getDouble(" borderRadius" ) else 0.0 ,
100
103
topLeft = if (options.hasKey(" borderTopLeftRadius" )) options.getDouble(" borderTopLeftRadius" ) else 0.0 ,
101
104
topRight = if (options.hasKey(" borderTopRightRadius" )) options.getDouble(" borderTopRightRadius" ) else 0.0 ,
@@ -128,6 +131,20 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
128
131
)
129
132
} else {
130
133
requestBuilder = requestBuilder.data(it)
134
+ if (ignoreQueryParamsForCacheKey) {
135
+ val uri = Uri .parse(it)
136
+ val keyUri = uri.buildUpon().clearQuery().build()
137
+ val cacheKey = keyUri.toString()
138
+ val memoryCacheKey = MemoryCache .Key (cacheKey)
139
+ if (cachePolicy.equals(" memory" )) {
140
+ requestBuilder = requestBuilder
141
+ .memoryCacheKey(memoryCacheKey)
142
+ } else {
143
+ requestBuilder = requestBuilder
144
+ .memoryCacheKey(memoryCacheKey)
145
+ .diskCacheKey(cacheKey)
146
+ }
147
+ }
131
148
headers?.let {
132
149
for (entry in it.entryIterator) {
133
150
requestBuilder.setHeader(entry.key, entry.value as String )
@@ -233,20 +250,6 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
233
250
234
251
private fun makeThumbHash (view : AppCompatImageView , hash : String ): Drawable {
235
252
val thumbHash = ThumbHash .thumbHashToRGBA(Base64 .decode(hash, Base64 .DEFAULT ))
236
- val bitmap = Bitmap .createBitmap(thumbHash.width, thumbHash.height, Bitmap .Config .ARGB_8888 )
237
- bitmap.setPixels(toIntArray(thumbHash.rgba), 0 , thumbHash.width, 0 , 0 , thumbHash.width, thumbHash.height)
238
- return BitmapDrawable (view.context.resources, bitmap)
239
- }
240
-
241
- private fun makeBlurHash (view : AppCompatImageView , hash : String ): Drawable {
242
- val bitmap = BlurHashDecoder .decode(hash, 8 , 8 )
243
- return BitmapDrawable (view.context.resources, bitmap)
244
- }
245
-
246
- private fun toIntArray (byteArray : ByteArray ): IntArray {
247
- val intArray = IntArray (byteArray.size)
248
- for (i in byteArray.indices) {
249
- intArray[i] = byteArray[i].toInt() and 0xFF
250
253
val intArray = IntArray (thumbHash.width * thumbHash.height)
251
254
for (i in intArray.indices) {
252
255
val r = thumbHash.rgba[i * 4 ].toInt() and 0xFF
@@ -260,6 +263,11 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
260
263
return BitmapDrawable (view.context.resources, bitmap)
261
264
}
262
265
266
+ private fun makeBlurHash (view : AppCompatImageView , hash : String ): Drawable {
267
+ val bitmap = BlurHashDecoder .decode(hash, 8 , 8 )
268
+ return BitmapDrawable (view.context.resources, bitmap)
269
+ }
270
+
263
271
companion object {
264
272
private val RESIZE_MODE = mapOf (
265
273
" contain" to ScaleType .FIT_CENTER ,
@@ -277,6 +285,7 @@ import com.facebook.react.uimanager.events.RCTEventEmitter
277
285
}
278
286
}
279
287
288
+
280
289
object ThumbHash {
281
290
/* *
282
291
* Encodes an RGBA image to a ThumbHash. RGB should not be premultiplied by A.
0 commit comments