@onekeyfe/react-native-image 6.7.0-alpha.466 → 6.8.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -86
- package/android/build.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +12 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyBlockieAvatarLoader.kt +1 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyIcon.kt +5 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImage.kt +240 -6
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageCache.kt +16 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageGlideModule.kt +17 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageGlideRegistry.kt +19 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageSafety.kt +41 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageStartupPrewarm.kt +1106 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyImageStartupProvider.kt +54 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyMainThreadDecode.kt +541 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyMediaPreviewCache.kt +199 -0
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyNamedSVG.kt +758 -61
- package/android/src/test/java/com/margelo/nitro/onekeyimage/OneKeyBlockieAvatarLoaderTest.kt +2 -1
- package/android/src/test/java/com/margelo/nitro/onekeyimage/OneKeyStartupPrewarmTest.kt +600 -0
- package/ios/OneKeyAvatarImageLoader.swift +1 -1
- package/ios/OneKeyIcon.swift +6 -0
- package/ios/OneKeyImage.swift +85 -2
- package/ios/OneKeyImageCache.swift +25 -5
- package/ios/OneKeyImageCoderBridge.m +42 -1
- package/ios/OneKeyImageRequestContext.swift +16 -2
- package/ios/OneKeyImageStartupPrewarm.swift +602 -0
- package/ios/OneKeyMainThreadDecode.swift +338 -0
- package/ios/OneKeyMediaPreviewCache.swift +209 -0
- package/ios/OneKeyNamedSVG.swift +437 -9
- package/ios/tests/OneKeyIconTests.swift +241 -0
- package/ios/tests/OneKeyImageInfrastructureTests.swift +611 -0
- package/ios/tests/OneKeyMediaPreviewCacheTests.swift +139 -0
- package/lib/module/index.js +5 -1
- package/package.json +1 -1
- package/src/index.tsx +23 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.margelo.nitro.onekeyimage
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.bumptech.glide.Glide
|
|
5
|
+
import com.bumptech.glide.GlideBuilder
|
|
6
|
+
import com.bumptech.glide.Registry
|
|
7
|
+
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
|
|
8
|
+
import com.bumptech.glide.module.GlideModule
|
|
9
|
+
|
|
10
|
+
@Suppress("DEPRECATION")
|
|
11
|
+
class OneKeyImageGlideModule : GlideModule {
|
|
12
|
+
override fun applyOptions(context: Context, builder: GlideBuilder) {
|
|
13
|
+
builder.setDiskCache(InternalCacheDiskCacheFactory(context, 320L * 1024 * 1024))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {}
|
|
17
|
+
}
|
|
@@ -44,6 +44,7 @@ internal object OneKeyImageGlideRegistry {
|
|
|
44
44
|
private var registered = false
|
|
45
45
|
|
|
46
46
|
fun ensureRegistered(context: Context) {
|
|
47
|
+
OneKeyImageStartupTrigger.startIfNeeded(context)
|
|
47
48
|
if (registered) return
|
|
48
49
|
synchronized(this) {
|
|
49
50
|
if (registered) return
|
|
@@ -80,6 +81,11 @@ internal object OneKeyImageGlideRegistry {
|
|
|
80
81
|
InputStream::class.java,
|
|
81
82
|
OneKeyImageRemoteModelLoaderFactory(imageHttpClient),
|
|
82
83
|
)
|
|
84
|
+
registry.append(
|
|
85
|
+
ByteBuffer::class.java,
|
|
86
|
+
SVG::class.java,
|
|
87
|
+
OneKeyByteBufferSvgDecoder(),
|
|
88
|
+
)
|
|
83
89
|
registry.append(
|
|
84
90
|
InputStream::class.java,
|
|
85
91
|
SVG::class.java,
|
|
@@ -255,6 +261,19 @@ private class OneKeyDataUriFetcher(private val dataUri: String) : DataFetcher<By
|
|
|
255
261
|
}
|
|
256
262
|
}
|
|
257
263
|
|
|
264
|
+
private class OneKeyByteBufferSvgDecoder : ResourceDecoder<ByteBuffer, SVG> {
|
|
265
|
+
private val delegate = OneKeySvgDecoder()
|
|
266
|
+
|
|
267
|
+
override fun handles(source: ByteBuffer, options: Options): Boolean = true
|
|
268
|
+
|
|
269
|
+
override fun decode(source: ByteBuffer, width: Int, height: Int, options: Options): Resource<SVG> {
|
|
270
|
+
val copy = source.asReadOnlyBuffer()
|
|
271
|
+
copy.position(0)
|
|
272
|
+
OneKeyImageSafety.requireEncodedLength(copy.remaining().toLong(), OneKeyImageSafety.MAX_ENCODED_BYTES)
|
|
273
|
+
return delegate.decode(com.bumptech.glide.util.ByteBufferUtil.toStream(copy), width, height, options)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
258
277
|
private class OneKeySvgDecoder : ResourceDecoder<InputStream, SVG> {
|
|
259
278
|
override fun handles(source: InputStream, options: Options): Boolean = true
|
|
260
279
|
|
|
@@ -129,6 +129,47 @@ internal object OneKeyImageSafety {
|
|
|
129
129
|
return decodedBytes.coerceAtLeast(0L)
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Decodes Base64 payloads using `android.util.Base64` (available since API 8,
|
|
134
|
+
* compatible with minSdkVersion 24). Falls back to a pure-Kotlin MIME Base64
|
|
135
|
+
* decoder only when running in JVM unit tests where `android.util.Base64.decode`
|
|
136
|
+
* is stubbed to return `null`.
|
|
137
|
+
*/
|
|
138
|
+
fun decodeDataUriBase64(payload: String): ByteArray {
|
|
139
|
+
try {
|
|
140
|
+
android.util.Base64.decode(payload, android.util.Base64.DEFAULT)?.let { return it }
|
|
141
|
+
} catch (error: RuntimeException) {
|
|
142
|
+
if (error is IllegalArgumentException) throw error
|
|
143
|
+
}
|
|
144
|
+
return decodeBase64Fallback(payload)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private fun decodeBase64Fallback(payload: String): ByteArray {
|
|
148
|
+
val out = ByteArrayOutputStream((payload.length * 3) / 4)
|
|
149
|
+
var buffer = 0
|
|
150
|
+
var bitsCollected = 0
|
|
151
|
+
for (i in payload.indices) {
|
|
152
|
+
val c = payload[i]
|
|
153
|
+
if (c == '=') break
|
|
154
|
+
val value = when (c) {
|
|
155
|
+
in 'A'..'Z' -> c.code - 'A'.code
|
|
156
|
+
in 'a'..'z' -> c.code - 'a'.code + 26
|
|
157
|
+
in '0'..'9' -> c.code - '0'.code + 52
|
|
158
|
+
'+', '-' -> 62
|
|
159
|
+
'/', '_' -> 63
|
|
160
|
+
' ', '\t', '\r', '\n' -> continue
|
|
161
|
+
else -> throw IllegalArgumentException("Invalid Base64 character")
|
|
162
|
+
}
|
|
163
|
+
buffer = (buffer shl 6) or value
|
|
164
|
+
bitsCollected += 6
|
|
165
|
+
if (bitsCollected >= 8) {
|
|
166
|
+
bitsCollected -= 8
|
|
167
|
+
out.write((buffer ushr bitsCollected) and 0xff)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return out.toByteArray()
|
|
171
|
+
}
|
|
172
|
+
|
|
132
173
|
fun isSafetyFailure(error: Throwable?): Boolean {
|
|
133
174
|
if (error == null) return false
|
|
134
175
|
val seen = Collections.newSetFromMap(IdentityHashMap<Throwable, Boolean>())
|