Skip to content

Commit

Permalink
53 placeholder for android (#54)
Browse files Browse the repository at this point in the history
* feat(Android): wip

* feat(Android): placeholder
  • Loading branch information
duguyihou authored Nov 25, 2023
1 parent 0d3a717 commit f091fc8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import android.graphics.drawable.Drawable
import android.util.Base64
import kotlin.collections.HashMap

object TurboImageBase64 {
object Base64Placeholder {
private val cache = HashMap<String, Drawable>()

fun base64ToDrawable(context: Context, base64: String): Drawable {
fun toDrawable(context: Context, base64: String): Drawable {
if (cache.containsKey(base64)) {
return cache[base64]!!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.turboimage

import android.widget.ImageView
import coil.Coil
import coil.request.CachePolicy
import coil.request.Disposable
import coil.request.ImageRequest
import com.facebook.react.uimanager.SimpleViewManager
Expand All @@ -21,7 +22,10 @@ class TurboImageViewManager : SimpleViewManager<TurboImageView>() {

override fun onAfterUpdateTransaction(view: TurboImageView) {
super.onAfterUpdateTransaction(view)
val request = requestBuilder.data(view.url).crossfade(view.crossfade).build()
val placeholder = view.base64Placeholder?.let { Base64Placeholder.toDrawable(view.context, it) }
val request = requestBuilder.data(view.url)
.placeholder(placeholder).diskCachePolicy(CachePolicy.DISABLED)
.crossfade(view.crossfade).build()
disposable = Coil.imageLoader(view.context).enqueue(request)
}

Expand Down

0 comments on commit f091fc8

Please sign in to comment.