Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.swmansion.rnscreens.gamma.tabs

import android.os.Handler
import android.os.Looper
import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.module.annotations.ReactModule
Expand Down Expand Up @@ -194,15 +192,7 @@ class TabScreenViewManager :
) {
val uri = value?.getString("uri")
if (uri != null) {
val context = view.context
loadTabImage(context, uri) { drawable ->
// Since image loading might happen on a background thread
// ref. https://frescolib.org/docs/intro-image-pipeline.html
// We should schedule rendering the result on the UI thread
Handler(Looper.getMainLooper()).post {
view.icon = drawable
}
}
loadTabImage(view.context, uri, view)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.swmansion.rnscreens.gamma.tabs.image

import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.core.graphics.drawable.toDrawable
import androidx.core.net.toUri
Expand All @@ -13,8 +15,24 @@ import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.imagepipeline.image.CloseableImage
import com.facebook.imagepipeline.image.CloseableStaticBitmap
import com.facebook.imagepipeline.request.ImageRequestBuilder
import com.swmansion.rnscreens.gamma.tabs.TabScreen

internal fun loadTabImage(
context: Context,
uri: String,
view: TabScreen,
) {
// Since image loading might happen on a background thread
// ref. https://frescolib.org/docs/intro-image-pipeline.html
// We should schedule rendering the result on the UI thread
loadTabImageInternal(context, uri) { drawable ->
Handler(Looper.getMainLooper()).post {
view.icon = drawable
}
}
}

private fun loadTabImageInternal(
context: Context,
uri: String,
onLoaded: (Drawable) -> Unit,
Expand Down
Loading