Skip to content

Commit

Permalink
280 feat disable hardware bitmaps for android (#281)
Browse files Browse the repository at this point in the history
* feat: allowHardware for Android

* docs: allowHardware
  • Loading branch information
duguyihou authored Jul 28, 2024
1 parent a405965 commit ecda2fc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions android/src/main/java/com/turboimage/TurboImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions android/src/main/java/com/turboimage/TurboImageViewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TurboImageViewManager : SimpleViewManager<TurboImageView>() {

view.load(view.uri) {
view.headers?.let { headers(it) }
view.allowHardware?.let { allowHardware(it) }
listener(TurboImageListener(view))
diskCachePolicy(
if (view.cachePolicy != "memory")
Expand Down Expand Up @@ -184,6 +185,11 @@ class TurboImageViewManager : SimpleViewManager<TurboImageView>() {
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
Expand Down
2 changes: 2 additions & 0 deletions src/TurboImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const TurboImage = (props: TurboImageProps) => {
resize,
tint,
enableLiveTextInteraction,
allowHardware,
format,
onStart,
onSuccess,
Expand Down Expand Up @@ -91,6 +92,7 @@ const TurboImage = (props: TurboImageProps) => {
resize={resize}
tint={processColor(tint)}
enableLiveTextInteraction={enableLiveTextInteraction}
allowHardware={allowHardware}
format={format}
onStart={onStart}
onSuccess={onSuccess}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface TurboImageProps extends AccessibilityProps, ViewProps {
tint?: number | ColorValue;
cachePolicy?: CachePolicy;
enableLiveTextInteraction?: boolean;
allowHardware?: boolean;
format?: Format;
onStart?: (result: NativeSyntheticEvent<TaskState>) => void;
onSuccess?: (result: NativeSyntheticEvent<Success>) => void;
Expand Down

0 comments on commit ecda2fc

Please sign in to comment.