Skip to content

Commit 0a6c2a5

Browse files
authored
feat: migrate from Glide to Coil (#145)
1 parent 04eea94 commit 0a6c2a5

File tree

6 files changed

+25
-150
lines changed

6 files changed

+25
-150
lines changed

android/build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,17 @@ repositories {
111111
def kotlin_version = getExtOrDefault("kotlinVersion")
112112

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

122-
api "com.github.bumptech.glide:glide:${GLIDE_VERSION}"
123-
kapt "com.github.bumptech.glide:compiler:${GLIDE_VERSION}"
124-
125-
api 'com.caverock:androidsvg-aar:1.4'
122+
implementation("io.coil-kt.coil3:coil:${COIL_VERSION}")
123+
implementation("io.coil-kt.coil3:coil-network-okhttp:${COIL_VERSION}")
124+
implementation("io.coil-kt.coil3:coil-svg:${COIL_VERSION}")
126125
}
127126

128127
if (isNewArchitectureEnabled()) {

android/src/main/java/com/rcttabview/RCTTabView.kt

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ import android.view.View
1616
import android.view.ViewGroup
1717
import android.widget.TextView
1818
import androidx.appcompat.content.res.AppCompatResources
19-
import com.bumptech.glide.Glide
20-
import com.bumptech.glide.load.DataSource
21-
import com.bumptech.glide.load.engine.GlideException
22-
import com.bumptech.glide.request.RequestListener
23-
import com.bumptech.glide.request.target.Target
19+
import coil3.ImageLoader
20+
import coil3.asDrawable
2421
import com.facebook.react.bridge.Arguments
2522
import com.facebook.react.bridge.ReadableArray
2623
import com.facebook.react.bridge.WritableMap
@@ -29,6 +26,8 @@ import com.facebook.react.modules.core.ReactChoreographer
2926
import com.facebook.react.views.imagehelper.ImageSource
3027
import com.facebook.react.views.text.ReactTypefaceUtils
3128
import com.google.android.material.bottomnavigation.BottomNavigationView
29+
import coil3.request.ImageRequest
30+
import coil3.svg.SvgDecoder
3231

3332

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

49+
private val imageLoader = ImageLoader.Builder(context)
50+
.components {
51+
add(SvgDecoder.Factory())
52+
}
53+
.build()
54+
5055
private val layoutCallback = Choreographer.FrameCallback {
5156
isLayoutEnqueued = false
5257
measure(
@@ -177,33 +182,19 @@ class ReactBottomNavigationView(context: Context) : BottomNavigationView(context
177182

178183
@SuppressLint("CheckResult")
179184
private fun getDrawable(imageSource: ImageSource, onDrawableReady: (Drawable?) -> Unit) {
180-
Glide.with(context)
181-
.`as`(Drawable::class.java)
182-
.load(imageSource.uri)
183-
.listener(object : RequestListener<Drawable> {
184-
override fun onLoadFailed(
185-
e: GlideException?,
186-
model: Any?,
187-
target: Target<Drawable>,
188-
isFirstResource: Boolean
189-
): Boolean {
190-
Log.e("RCTTabView", "Error loading image: ${imageSource.uri}", e)
191-
return false
185+
val request = ImageRequest.Builder(context)
186+
.data(imageSource.uri)
187+
.target { drawable ->
188+
post { onDrawableReady(drawable.asDrawable(context.resources)) }
189+
}
190+
.listener(
191+
onError = { _, result ->
192+
Log.e("RCTTabView", "Error loading image: ${imageSource.uri}", result.throwable)
192193
}
194+
)
195+
.build()
193196

194-
override fun onResourceReady(
195-
resource: Drawable,
196-
model: Any,
197-
target: Target<Drawable>?,
198-
dataSource: DataSource,
199-
isFirstResource: Boolean
200-
): Boolean {
201-
// Update images on the main queue.
202-
post { onDrawableReady(resource) }
203-
return true
204-
}
205-
})
206-
.submit()
197+
imageLoader.enqueue(request)
207198
}
208199

209200
override fun onDetachedFromWindow() {

android/src/main/java/com/rcttabview/TabViewAppGlideModule.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

android/src/main/java/com/rcttabview/svg/SVGDecoder.kt

Lines changed: 0 additions & 40 deletions
This file was deleted.

android/src/main/java/com/rcttabview/svg/SVGDrawableTranscoder.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.

android/src/main/java/com/rcttabview/svg/TabViewGlideModule.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)