Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate from Glide to Coil #145

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading