Skip to content

Commit

Permalink
feat: migrate from Glide to Coil (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Nov 13, 2024
1 parent 04eea94 commit 0a6c2a5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 150 deletions.
9 changes: 4 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ repositories {
def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
def GLIDE_VERSION = "4.16.0"
def COIL_VERSION = "3.0.2"
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.google.android.material:material:1.13.0-alpha06'

api "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
kapt "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"

api 'com.caverock:androidsvg-aar:1.4'
implementation("io.coil-kt.coil3:coil:${COIL_VERSION}")
implementation("io.coil-kt.coil3:coil-network-okhttp:${COIL_VERSION}")
implementation("io.coil-kt.coil3:coil-svg:${COIL_VERSION}")
}

if (isNewArchitectureEnabled()) {
Expand Down
51 changes: 21 additions & 30 deletions android/src/main/java/com/rcttabview/RCTTabView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import coil3.ImageLoader
import coil3.asDrawable
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.WritableMap
Expand All @@ -29,6 +26,8 @@ import com.facebook.react.modules.core.ReactChoreographer
import com.facebook.react.views.imagehelper.ImageSource
import com.facebook.react.views.text.ReactTypefaceUtils
import com.google.android.material.bottomnavigation.BottomNavigationView
import coil3.request.ImageRequest
import coil3.svg.SvgDecoder


class ReactBottomNavigationView(context: Context) : BottomNavigationView(context) {
Expand All @@ -47,6 +46,12 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
private var fontFamily: String? = null
private var fontWeight: Int? = null

private val imageLoader = ImageLoader.Builder(context)
.components {
add(SvgDecoder.Factory())
}
.build()

private val layoutCallback = Choreographer.FrameCallback {
isLayoutEnqueued = false
measure(
Expand Down Expand Up @@ -177,33 +182,19 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context

@SuppressLint("CheckResult")
private fun getDrawable(imageSource: ImageSource, onDrawableReady: (Drawable?) -> Unit) {
Glide.with(context)
.`as`(Drawable::class.java)
.load(imageSource.uri)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>,
isFirstResource: Boolean
): Boolean {
Log.e("RCTTabView", "Error loading image: ${imageSource.uri}", e)
return false
val request = ImageRequest.Builder(context)
.data(imageSource.uri)
.target { drawable ->
post { onDrawableReady(drawable.asDrawable(context.resources)) }
}
.listener(
onError = { _, result ->
Log.e("RCTTabView", "Error loading image: ${imageSource.uri}", result.throwable)
}
)
.build()

override fun onResourceReady(
resource: Drawable,
model: Any,
target: Target<Drawable>?,
dataSource: DataSource,
isFirstResource: Boolean
): Boolean {
// Update images on the main queue.
post { onDrawableReady(resource) }
return true
}
})
.submit()
imageLoader.enqueue(request)
}

override fun onDetachedFromWindow() {
Expand Down
18 changes: 0 additions & 18 deletions android/src/main/java/com/rcttabview/TabViewAppGlideModule.kt

This file was deleted.

40 changes: 0 additions & 40 deletions android/src/main/java/com/rcttabview/svg/SVGDecoder.kt

This file was deleted.

32 changes: 0 additions & 32 deletions android/src/main/java/com/rcttabview/svg/SVGDrawableTranscoder.kt

This file was deleted.

25 changes: 0 additions & 25 deletions android/src/main/java/com/rcttabview/svg/TabViewGlideModule.kt

This file was deleted.

0 comments on commit 0a6c2a5

Please sign in to comment.