From ecda2fcb8063edd34349d2291819ec667f28359c Mon Sep 17 00:00:00 2001 From: duguyihou Date: Sun, 28 Jul 2024 12:54:07 +1000 Subject: [PATCH] 280 feat disable hardware bitmaps for android (#281) * feat: allowHardware for Android * docs: allowHardware --- README.md | 4 ++++ android/src/main/java/com/turboimage/TurboImageView.kt | 1 + .../src/main/java/com/turboimage/TurboImageViewManager.kt | 6 ++++++ src/TurboImage.tsx | 2 ++ src/types.ts | 1 + 5 files changed, 14 insertions(+) diff --git a/README.md b/README.md index aa7d089..56eff64 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,10 @@ The color is applied to every non-transparent pixel, causing the image’s shape Enables Live Text interaction with the image. +### `allowHardware?: boolean` (Android only) + +Setting this to false this will reduce performance on API 26 and above. Only disable this if necessary. [Coil's docs](https://coil-kt.github.io/coil/recipes/#shared-element-transitions) + ### `format?: String` Specify the format for special image, e.g. `svg`, `gif` and `apng`. In general, TurboImage will determine the decoder automatically. diff --git a/android/src/main/java/com/turboimage/TurboImageView.kt b/android/src/main/java/com/turboimage/TurboImageView.kt index 30da26f..e5245c1 100644 --- a/android/src/main/java/com/turboimage/TurboImageView.kt +++ b/android/src/main/java/com/turboimage/TurboImageView.kt @@ -32,6 +32,7 @@ class TurboImageView(private val reactContext: ThemedReactContext) : var blur: Int? = null var monochrome: Int? = null var tint: Int? = null + var allowHardware: Boolean? = null var format: String? = null diff --git a/android/src/main/java/com/turboimage/TurboImageViewManager.kt b/android/src/main/java/com/turboimage/TurboImageViewManager.kt index 44dd076..51ab340 100644 --- a/android/src/main/java/com/turboimage/TurboImageViewManager.kt +++ b/android/src/main/java/com/turboimage/TurboImageViewManager.kt @@ -61,6 +61,7 @@ class TurboImageViewManager : SimpleViewManager() { view.load(view.uri) { view.headers?.let { headers(it) } + view.allowHardware?.let { allowHardware(it) } listener(TurboImageListener(view)) diskCachePolicy( if (view.cachePolicy != "memory") @@ -184,6 +185,11 @@ class TurboImageViewManager : SimpleViewManager() { view.tint = tint } + @ReactProp(name = "allowHardware") + fun setAllowHardware(view: TurboImageView, allowHardware: Boolean?) { + view.allowHardware = allowHardware + } + @ReactProp(name = "format") fun setFormat(view: TurboImageView, format: String?) { view.format = format diff --git a/src/TurboImage.tsx b/src/TurboImage.tsx index 0e5b5e7..8bcd271 100644 --- a/src/TurboImage.tsx +++ b/src/TurboImage.tsx @@ -43,6 +43,7 @@ const TurboImage = (props: TurboImageProps) => { resize, tint, enableLiveTextInteraction, + allowHardware, format, onStart, onSuccess, @@ -91,6 +92,7 @@ const TurboImage = (props: TurboImageProps) => { resize={resize} tint={processColor(tint)} enableLiveTextInteraction={enableLiveTextInteraction} + allowHardware={allowHardware} format={format} onStart={onStart} onSuccess={onSuccess} diff --git a/src/types.ts b/src/types.ts index 4d057f8..f37883b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -65,6 +65,7 @@ export interface TurboImageProps extends AccessibilityProps, ViewProps { tint?: number | ColorValue; cachePolicy?: CachePolicy; enableLiveTextInteraction?: boolean; + allowHardware?: boolean; format?: Format; onStart?: (result: NativeSyntheticEvent) => void; onSuccess?: (result: NativeSyntheticEvent) => void;