diff --git a/android/build.gradle b/android/build.gradle index 17081ae..c1d0268 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -111,7 +111,7 @@ 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 @@ -119,10 +119,9 @@ dependencies { 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()) { diff --git a/android/src/main/java/com/rcttabview/RCTTabView.kt b/android/src/main/java/com/rcttabview/RCTTabView.kt index 2245f4a..427435f 100644 --- a/android/src/main/java/com/rcttabview/RCTTabView.kt +++ b/android/src/main/java/com/rcttabview/RCTTabView.kt @@ -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 @@ -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) { @@ -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( @@ -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 { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target, - 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?, - dataSource: DataSource, - isFirstResource: Boolean - ): Boolean { - // Update images on the main queue. - post { onDrawableReady(resource) } - return true - } - }) - .submit() + imageLoader.enqueue(request) } override fun onDetachedFromWindow() { diff --git a/android/src/main/java/com/rcttabview/TabViewAppGlideModule.kt b/android/src/main/java/com/rcttabview/TabViewAppGlideModule.kt deleted file mode 100644 index f6c5540..0000000 --- a/android/src/main/java/com/rcttabview/TabViewAppGlideModule.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.rcttabview - -import android.content.Context -import android.util.Log -import com.bumptech.glide.GlideBuilder -import com.bumptech.glide.annotation.GlideModule -import com.bumptech.glide.module.AppGlideModule - -@GlideModule -class TabViewAppGlideModule : AppGlideModule() { - override fun applyOptions(context: Context, builder: GlideBuilder) { - super.applyOptions(context, builder) - - builder.setLogLevel( - Log.ERROR - ) - } -} diff --git a/android/src/main/java/com/rcttabview/svg/SVGDecoder.kt b/android/src/main/java/com/rcttabview/svg/SVGDecoder.kt deleted file mode 100644 index 8f098a0..0000000 --- a/android/src/main/java/com/rcttabview/svg/SVGDecoder.kt +++ /dev/null @@ -1,40 +0,0 @@ -package com.rcttabview.svg - -import com.bumptech.glide.load.Options -import com.bumptech.glide.load.ResourceDecoder -import com.bumptech.glide.load.engine.Resource -import com.bumptech.glide.load.resource.SimpleResource -import com.caverock.androidsvg.SVG -import com.caverock.androidsvg.SVGParseException -import java.io.IOException -import java.io.InputStream - - -class SVGDecoder : ResourceDecoder { - override fun handles(source: InputStream, options: Options) = true - - companion object { - const val DEFAULT_SIZE = 40f - } - - @Throws(IOException::class) - override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource? { - return try { - val svg: SVG = SVG.getFromInputStream(source) - // Taken from https://github.com/expo/expo/blob/215d8a13a7ef3f0b36b14eead41291e2d2d6cd0c/packages/expo-image/android/src/main/java/expo/modules/image/svg/SVGDecoder.kt#L28 - if (svg.documentViewBox == null) { - val documentWidth = svg.documentWidth - val documentHeight = svg.documentHeight - if (documentWidth != -1f && documentHeight != -1f) { - svg.setDocumentViewBox(0f, 0f, documentWidth, documentHeight) - } - } - - svg.documentWidth = DEFAULT_SIZE - svg.documentHeight = DEFAULT_SIZE - SimpleResource(svg) - } catch (ex: SVGParseException) { - throw IOException("Cannot load SVG from stream", ex) - } - } -} diff --git a/android/src/main/java/com/rcttabview/svg/SVGDrawableTranscoder.kt b/android/src/main/java/com/rcttabview/svg/SVGDrawableTranscoder.kt deleted file mode 100644 index 91ad2db..0000000 --- a/android/src/main/java/com/rcttabview/svg/SVGDrawableTranscoder.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.rcttabview.svg - -import android.content.Context -import android.graphics.Bitmap -import android.graphics.Canvas -import android.graphics.drawable.BitmapDrawable -import android.graphics.drawable.Drawable -import android.graphics.drawable.PictureDrawable -import com.bumptech.glide.load.Options -import com.bumptech.glide.load.engine.Resource -import com.bumptech.glide.load.resource.SimpleResource -import com.bumptech.glide.load.resource.transcode.ResourceTranscoder -import com.caverock.androidsvg.SVG - -class SVGDrawableTranscoder(val context: Context) : ResourceTranscoder { - override fun transcode(toTranscode: Resource, options: Options): Resource { - val svg = toTranscode.get() - val picture = svg.renderToPicture() - val drawable = PictureDrawable(picture) - - val returnedBitmap = Bitmap.createBitmap( - drawable.intrinsicWidth, - drawable.intrinsicHeight, - Bitmap.Config.ARGB_8888 - ) - - val canvas = Canvas(returnedBitmap) - canvas.drawPicture(drawable.picture) - val bitMapDrawable = BitmapDrawable(context.resources, returnedBitmap) - return SimpleResource(bitMapDrawable) - } -} diff --git a/android/src/main/java/com/rcttabview/svg/TabViewGlideModule.kt b/android/src/main/java/com/rcttabview/svg/TabViewGlideModule.kt deleted file mode 100644 index db6579d..0000000 --- a/android/src/main/java/com/rcttabview/svg/TabViewGlideModule.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.rcttabview.svg - -import android.content.Context -import android.graphics.drawable.Drawable -import com.bumptech.glide.Glide -import com.bumptech.glide.Registry -import com.bumptech.glide.annotation.GlideModule -import com.bumptech.glide.module.LibraryGlideModule -import com.caverock.androidsvg.SVG -import java.io.InputStream - - -@GlideModule -class SvgModule: LibraryGlideModule() { - override fun registerComponents( - context: Context, glide: Glide, registry: Registry - ) { - registry - .register( - SVG::class.java, - Drawable::class.java, SVGDrawableTranscoder(context) - ) - .append(InputStream::class.java, SVG::class.java, SVGDecoder()) - } -}