@onekeyfe/react-native-image 3.0.102 → 3.0.104
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.margelo.nitro.onekeyimage
|
|
2
2
|
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.ContextWrapper
|
|
3
5
|
import android.graphics.Canvas
|
|
4
6
|
import android.graphics.Color
|
|
5
7
|
import android.graphics.Paint
|
|
@@ -7,6 +9,7 @@ import android.graphics.drawable.Animatable
|
|
|
7
9
|
import android.graphics.drawable.Drawable
|
|
8
10
|
import android.view.View
|
|
9
11
|
import android.widget.ImageView
|
|
12
|
+
import androidx.fragment.app.FragmentActivity
|
|
10
13
|
import com.bumptech.glide.Glide
|
|
11
14
|
import com.bumptech.glide.load.DataSource
|
|
12
15
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|
@@ -22,6 +25,17 @@ import com.margelo.nitro.skeleton.OneKeySkeletonRenderer
|
|
|
22
25
|
import com.margelo.nitro.views.RecyclableView
|
|
23
26
|
import kotlin.math.ceil
|
|
24
27
|
|
|
28
|
+
private fun Context.findFragmentActivity(): FragmentActivity? {
|
|
29
|
+
var currentContext: Context? = this
|
|
30
|
+
while (currentContext is ContextWrapper) {
|
|
31
|
+
if (currentContext is FragmentActivity) return currentContext
|
|
32
|
+
val baseContext = currentContext.baseContext
|
|
33
|
+
if (baseContext === currentContext) return null
|
|
34
|
+
currentContext = baseContext
|
|
35
|
+
}
|
|
36
|
+
return currentContext as? FragmentActivity
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
private class OneKeyImageHostView(context: ThemedReactContext) : ImageView(context) {
|
|
26
40
|
private val fallbackPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
|
27
41
|
color = Color.rgb(110, 110, 120)
|
|
@@ -123,10 +137,12 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
123
137
|
private enum class DisplayState { LOADING, IMAGE, ERROR, FALLBACK }
|
|
124
138
|
|
|
125
139
|
private val hostView = OneKeyImageHostView(context)
|
|
126
|
-
//
|
|
127
|
-
//
|
|
140
|
+
// The Activity outlives ScreenStack Fragments but still provides bounded
|
|
141
|
+
// background and destruction lifecycle handling for image requests.
|
|
128
142
|
private val requestManager by lazy(LazyThreadSafetyMode.NONE) {
|
|
129
|
-
|
|
143
|
+
val activity = context.findFragmentActivity()
|
|
144
|
+
?: (context.currentActivity as? FragmentActivity)
|
|
145
|
+
Glide.with(requireNotNull(activity) { "A FragmentActivity is required to load images" })
|
|
130
146
|
}
|
|
131
147
|
private var loadRunnable: Runnable? = null
|
|
132
148
|
private var currentTarget: CustomViewTarget<OneKeyImageHostView, Drawable>? = null
|
|
@@ -213,6 +229,7 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
213
229
|
hostView.onReadyForRequest = { scheduleLoad() }
|
|
214
230
|
hostView.onAttachmentChanged = { attached ->
|
|
215
231
|
if (attached) {
|
|
232
|
+
scheduleLoad()
|
|
216
233
|
schedulePendingDisplayIfNeeded()
|
|
217
234
|
} else {
|
|
218
235
|
displayRunnable?.let(hostView::removeCallbacks)
|
|
@@ -411,6 +428,8 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
411
428
|
|
|
412
429
|
override fun onResourceCleared(placeholder: Drawable?) {
|
|
413
430
|
if (requestGeneration == generation && currentTarget === this) {
|
|
431
|
+
currentTarget = null
|
|
432
|
+
lastSignature = null
|
|
414
433
|
requestActive = false
|
|
415
434
|
hostView.skeletonRequested = false
|
|
416
435
|
hostView.setImageDrawable(null)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-image",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.104",
|
|
4
4
|
"description": "High-performance native image view for OneKey",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"typescript": "^5.9.2"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@onekeyfe/react-native-skeleton": "3.0.
|
|
84
|
+
"@onekeyfe/react-native-skeleton": "3.0.104",
|
|
85
85
|
"react": "*",
|
|
86
86
|
"react-native": "*",
|
|
87
87
|
"react-native-nitro-modules": "0.37.0"
|