@onekeyfe/react-native-image 3.0.99 → 3.0.100

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.
@@ -466,7 +466,7 @@ class HybridOneKeyImage(private val context: ThemedReactContext) :
466
466
  private fun requestOptions(policy: OneKeyImageCachePolicy): RequestOptions {
467
467
  val options = RequestOptions()
468
468
  .dontTransform()
469
- .downsample(OneKeyImageSafeDownsampleStrategy())
469
+ .downsample(OneKeyImageSafeDownsampleStrategy)
470
470
  return when (policy) {
471
471
  OneKeyImageCachePolicy.MEMORY_DISK -> options.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
472
472
  OneKeyImageCachePolicy.MEMORY -> options.diskCacheStrategy(DiskCacheStrategy.NONE)
@@ -23,7 +23,7 @@ class HybridOneKeyImageCache : HybridOneKeyImageCacheSpec() {
23
23
  }
24
24
  val baseOptions = RequestOptions()
25
25
  .dontTransform()
26
- .downsample(OneKeyImageSafeDownsampleStrategy())
26
+ .downsample(OneKeyImageSafeDownsampleStrategy)
27
27
  val options = when (source.cachePolicy ?: OneKeyImageCachePolicy.MEMORY_DISK) {
28
28
  OneKeyImageCachePolicy.MEMORY_DISK -> baseOptions
29
29
  .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
@@ -147,7 +147,7 @@ internal data class OneKeyImageDecodeDimensions(
147
147
  * 16 MiB area cap. `override()` alone cannot enforce an area cap for very wide
148
148
  * or tall sources because Glide's default strategy follows target edges.
149
149
  */
150
- internal class OneKeyImageSafeDownsampleStrategy : DownsampleStrategy() {
150
+ internal object OneKeyImageSafeDownsampleStrategy : DownsampleStrategy() {
151
151
  override fun getScaleFactor(
152
152
  sourceWidth: Int,
153
153
  sourceHeight: Int,
@@ -3,6 +3,7 @@ package com.margelo.nitro.onekeyimage
3
3
  import org.junit.Assert.assertEquals
4
4
  import org.junit.Assert.assertTrue
5
5
  import org.junit.Test
6
+ import java.lang.reflect.Modifier
6
7
 
7
8
  class OneKeyImageDecodeDimensionsTest {
8
9
  @Test
@@ -67,4 +68,19 @@ class OneKeyImageDecodeDimensionsTest {
67
68
 
68
69
  assertTrue(decodedBytes <= OneKeyImageDecodeDimensions.MAX_DECODE_BYTES)
69
70
  }
71
+
72
+ @Test
73
+ fun safeDownsampleStrategyIsSingletonForStableMemoryCacheIdentity() {
74
+ val strategyClass = Class.forName(
75
+ "com.margelo.nitro.onekeyimage.OneKeyImageSafeDownsampleStrategy",
76
+ false,
77
+ javaClass.classLoader,
78
+ )
79
+
80
+ assertTrue(
81
+ strategyClass.declaredFields.any { field ->
82
+ field.name == "INSTANCE" && Modifier.isStatic(field.modifiers)
83
+ },
84
+ )
85
+ }
70
86
  }
@@ -168,10 +168,13 @@ export function OneKeyImage({
168
168
  }) : undefined,
169
169
  onLoadEnd: needsLoadEnd ? callback(() => refs.current.onLoadEnd?.()) : undefined
170
170
  }), [hasOverlay, identity, needsDisplay, needsError, needsHybridRef, needsLoad, needsLoadEnd, needsLoadStart, normalized?.uri, placeholder]);
171
+ const flattenedStyle = StyleSheet.flatten(style);
172
+ const hasRoundedCorners = Boolean(flattenedStyle && [flattenedStyle.borderRadius, flattenedStyle.borderTopLeftRadius, flattenedStyle.borderTopRightRadius, flattenedStyle.borderBottomLeftRadius, flattenedStyle.borderBottomRightRadius, flattenedStyle.borderStartStartRadius, flattenedStyle.borderStartEndRadius, flattenedStyle.borderEndStartRadius, flattenedStyle.borderEndEndRadius].some(radius => typeof radius === 'number' && radius > 0));
173
+ const shouldWrapNative = hasOverlay || hasRoundedCorners;
171
174
  const native = /*#__PURE__*/createElement(NativeOneKeyImage, {
172
175
  ...viewProps,
173
176
  ...nativeCallbacks,
174
- style: hasOverlay ? StyleSheet.absoluteFill : style,
177
+ style: shouldWrapNative ? StyleSheet.absoluteFill : style,
175
178
  sourceUri: normalized?.uri,
176
179
  sourceHeadersJson: normalized?.headers ? JSON.stringify(normalized.headers) : undefined,
177
180
  variant,
@@ -183,7 +186,7 @@ export function OneKeyImage({
183
186
  overscan,
184
187
  loadingStrategy: placeholder == null ? loadingStrategy : OneKeyImageLoadingStrategy.NONE
185
188
  });
186
- if (!hasOverlay) return native;
189
+ if (!shouldWrapNative) return native;
187
190
  return /*#__PURE__*/_jsxs(View, {
188
191
  style: [style, styles.overlayContainer],
189
192
  collapsable: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-image",
3
- "version": "3.0.99",
3
+ "version": "3.0.100",
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.99",
84
+ "@onekeyfe/react-native-skeleton": "3.0.100",
85
85
  "react": "*",
86
86
  "react-native": "*",
87
87
  "react-native-nitro-modules": "0.37.0"
package/src/index.tsx CHANGED
@@ -307,10 +307,27 @@ export function OneKeyImage({
307
307
  ]
308
308
  );
309
309
 
310
+ const flattenedStyle = StyleSheet.flatten(style);
311
+ const hasRoundedCorners = Boolean(
312
+ flattenedStyle &&
313
+ [
314
+ flattenedStyle.borderRadius,
315
+ flattenedStyle.borderTopLeftRadius,
316
+ flattenedStyle.borderTopRightRadius,
317
+ flattenedStyle.borderBottomLeftRadius,
318
+ flattenedStyle.borderBottomRightRadius,
319
+ flattenedStyle.borderStartStartRadius,
320
+ flattenedStyle.borderStartEndRadius,
321
+ flattenedStyle.borderEndStartRadius,
322
+ flattenedStyle.borderEndEndRadius,
323
+ ].some((radius) => typeof radius === 'number' && radius > 0)
324
+ );
325
+ const shouldWrapNative = hasOverlay || hasRoundedCorners;
326
+
310
327
  const native = createElement(NativeOneKeyImage, {
311
328
  ...viewProps,
312
329
  ...nativeCallbacks,
313
- style: hasOverlay ? StyleSheet.absoluteFill : style,
330
+ style: shouldWrapNative ? StyleSheet.absoluteFill : style,
314
331
  sourceUri: normalized?.uri,
315
332
  sourceHeadersJson: normalized?.headers
316
333
  ? JSON.stringify(normalized.headers)
@@ -326,7 +343,7 @@ export function OneKeyImage({
326
343
  placeholder == null ? loadingStrategy : OneKeyImageLoadingStrategy.NONE,
327
344
  });
328
345
 
329
- if (!hasOverlay) return native;
346
+ if (!shouldWrapNative) return native;
330
347
 
331
348
  return (
332
349
  <View style={[style, styles.overlayContainer]} collapsable={false}>