@onekeyfe/react-native-image 6.7.0-alpha.475 → 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/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 +4 -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 +1 -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 +1 -1
- package/android/src/main/java/com/margelo/nitro/onekeyimage/OneKeyNamedSVG.kt +758 -61
- 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 +2 -0
- 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 +20 -12
- 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 +49 -0
- package/lib/module/index.js +5 -1
- package/package.json +1 -1
- package/src/index.tsx +23 -2
|
@@ -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>())
|