@onekeyfe/react-native-image 3.0.104 → 3.0.105
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.
|
@@ -139,7 +139,7 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
139
139
|
private val hostView = OneKeyImageHostView(context)
|
|
140
140
|
// The Activity outlives ScreenStack Fragments but still provides bounded
|
|
141
141
|
// background and destruction lifecycle handling for image requests.
|
|
142
|
-
private val
|
|
142
|
+
private val activityRequestManager by lazy(LazyThreadSafetyMode.NONE) {
|
|
143
143
|
val activity = context.findFragmentActivity()
|
|
144
144
|
?: (context.currentActivity as? FragmentActivity)
|
|
145
145
|
Glide.with(requireNotNull(activity) { "A FragmentActivity is required to load images" })
|
|
@@ -156,6 +156,18 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
156
156
|
private var pendingDisplayGeneration: Long? = null
|
|
157
157
|
private var fallbackRunnable: Runnable? = null
|
|
158
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Native reusable containers own their request cleanup explicitly, so their
|
|
161
|
+
* requests must not inherit a transient React Native screen Fragment lifecycle.
|
|
162
|
+
*/
|
|
163
|
+
internal var usesApplicationRequestManager = false
|
|
164
|
+
|
|
165
|
+
private fun requestManager() = if (usesApplicationRequestManager) {
|
|
166
|
+
Glide.with(context.applicationContext)
|
|
167
|
+
} else {
|
|
168
|
+
activityRequestManager
|
|
169
|
+
}
|
|
170
|
+
|
|
159
171
|
override val view: View = hostView
|
|
160
172
|
|
|
161
173
|
override var sourceUri: String? = null
|
|
@@ -470,7 +482,7 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
470
482
|
}
|
|
471
483
|
}
|
|
472
484
|
currentTarget = target
|
|
473
|
-
requestManager
|
|
485
|
+
requestManager()
|
|
474
486
|
.asDrawable()
|
|
475
487
|
.load(OneKeyImageModel.build(requestUrl, headersJson))
|
|
476
488
|
.apply(requestOptions(policy))
|
|
@@ -547,7 +559,7 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
|
|
|
547
559
|
// Clear the field first so onResourceCleared from our own cancellation
|
|
548
560
|
// cannot erase state belonging to the next generation/request.
|
|
549
561
|
currentTarget = null
|
|
550
|
-
requestManager.clear(target)
|
|
562
|
+
requestManager().clear(target)
|
|
551
563
|
}
|
|
552
564
|
|
|
553
565
|
private fun scheduleOnDisplay(requestGeneration: Long) {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
package com.margelo.nitro.onekeyimage
|
|
2
|
+
|
|
3
|
+
import android.widget.FrameLayout
|
|
4
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
5
|
+
|
|
6
|
+
/** A native-only OneKeyImage host for reusable container views such as list cells. */
|
|
7
|
+
class OneKeyImageReusableView(context: ThemedReactContext) : FrameLayout(context) {
|
|
8
|
+
private val image = HybridOneKeyImage(context).apply {
|
|
9
|
+
usesApplicationRequestManager = true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
init {
|
|
13
|
+
addView(
|
|
14
|
+
image.view,
|
|
15
|
+
LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT),
|
|
16
|
+
)
|
|
17
|
+
clipChildren = true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fun configure(
|
|
21
|
+
sourceUri: String?,
|
|
22
|
+
sourceHeadersJson: String?,
|
|
23
|
+
variant: String,
|
|
24
|
+
contentFit: String,
|
|
25
|
+
cachePolicy: String,
|
|
26
|
+
autoplay: Boolean,
|
|
27
|
+
recyclingKey: String,
|
|
28
|
+
optimizeTos: Boolean,
|
|
29
|
+
overscan: Double,
|
|
30
|
+
loadingStrategy: String,
|
|
31
|
+
) {
|
|
32
|
+
image.sourceHeadersJson = sourceHeadersJson
|
|
33
|
+
image.variant = when (variant) {
|
|
34
|
+
"token" -> OneKeyImageVariant.TOKEN
|
|
35
|
+
"network" -> OneKeyImageVariant.NETWORK
|
|
36
|
+
"avatar" -> OneKeyImageVariant.AVATAR
|
|
37
|
+
else -> OneKeyImageVariant.GENERIC
|
|
38
|
+
}
|
|
39
|
+
image.contentFit = when (contentFit) {
|
|
40
|
+
"contain" -> OneKeyImageContentFit.CONTAIN
|
|
41
|
+
"fill" -> OneKeyImageContentFit.FILL
|
|
42
|
+
"center" -> OneKeyImageContentFit.CENTER
|
|
43
|
+
else -> OneKeyImageContentFit.COVER
|
|
44
|
+
}
|
|
45
|
+
image.cachePolicy = when (cachePolicy) {
|
|
46
|
+
"memory" -> OneKeyImageCachePolicy.MEMORY
|
|
47
|
+
"disk" -> OneKeyImageCachePolicy.DISK
|
|
48
|
+
"none" -> OneKeyImageCachePolicy.NONE
|
|
49
|
+
else -> OneKeyImageCachePolicy.MEMORY_DISK
|
|
50
|
+
}
|
|
51
|
+
image.autoplay = autoplay
|
|
52
|
+
image.recyclingKey = recyclingKey
|
|
53
|
+
image.optimizeTos = optimizeTos
|
|
54
|
+
image.overscan = overscan
|
|
55
|
+
image.loadingStrategy = when (loadingStrategy) {
|
|
56
|
+
"skeleton" -> OneKeyImageLoadingStrategy.SKELETON
|
|
57
|
+
"none" -> OneKeyImageLoadingStrategy.NONE
|
|
58
|
+
else -> OneKeyImageLoadingStrategy.STATIC
|
|
59
|
+
}
|
|
60
|
+
image.sourceUri = sourceUri
|
|
61
|
+
image.afterUpdate()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
fun prepareForReuse() {
|
|
65
|
+
image.prepareForRecycle()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fun dispose() {
|
|
69
|
+
image.onDropView()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// A native-only OneKeyImage host for reusable container views such as list cells.
|
|
4
|
+
public final class OneKeyImageReusableView: UIView {
|
|
5
|
+
private let image = HybridOneKeyImage()
|
|
6
|
+
|
|
7
|
+
public override init(frame: CGRect) {
|
|
8
|
+
super.init(frame: frame)
|
|
9
|
+
let imageView = image.view
|
|
10
|
+
imageView.frame = bounds
|
|
11
|
+
imageView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
12
|
+
addSubview(imageView)
|
|
13
|
+
clipsToBounds = true
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public required init?(coder: NSCoder) {
|
|
17
|
+
fatalError("init(coder:) has not been implemented")
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public func configure(
|
|
21
|
+
sourceUri: String?,
|
|
22
|
+
sourceHeadersJson: String?,
|
|
23
|
+
variant: String,
|
|
24
|
+
contentFit: String,
|
|
25
|
+
cachePolicy: String,
|
|
26
|
+
autoplay: Bool,
|
|
27
|
+
recyclingKey: String,
|
|
28
|
+
optimizeTos: Bool,
|
|
29
|
+
overscan: Double,
|
|
30
|
+
loadingStrategy: String
|
|
31
|
+
) {
|
|
32
|
+
image.sourceHeadersJson = sourceHeadersJson
|
|
33
|
+
image.variant = OneKeyImageVariant(fromString: variant) ?? .generic
|
|
34
|
+
image.contentFit = OneKeyImageContentFit(fromString: contentFit) ?? .cover
|
|
35
|
+
image.cachePolicy = OneKeyImageCachePolicy(fromString: cachePolicy) ?? .memoryDisk
|
|
36
|
+
image.autoplay = autoplay
|
|
37
|
+
image.recyclingKey = recyclingKey
|
|
38
|
+
image.optimizeTos = optimizeTos
|
|
39
|
+
image.overscan = overscan
|
|
40
|
+
image.loadingStrategy = OneKeyImageLoadingStrategy(fromString: loadingStrategy) ?? .static
|
|
41
|
+
image.sourceUri = sourceUri
|
|
42
|
+
image.afterUpdate()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public func prepareForReuse() {
|
|
46
|
+
image.prepareForRecycle()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
deinit {
|
|
50
|
+
image.onDropView()
|
|
51
|
+
}
|
|
52
|
+
}
|
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.105",
|
|
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.105",
|
|
85
85
|
"react": "*",
|
|
86
86
|
"react-native": "*",
|
|
87
87
|
"react-native-nitro-modules": "0.37.0"
|