Skip to content

Commit c11e153

Browse files
authored
refactor(Android, Tabs): Move image loader logic to TabsImageLoader (#3292)
## Description Minor refactor, separating icon loading logic from the view manager. Fixes software-mansion/react-native-screens-labs#469 ## Changes - Moving the logic related to icon loading to `TabsImageLoader` ## Test code and steps to reproduce Performed regression testing on TestBottomTabs ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes
1 parent 12704e5 commit c11e153

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

android/src/main/java/com/swmansion/rnscreens/gamma/tabs/TabScreenViewManager.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.swmansion.rnscreens.gamma.tabs
22

3-
import android.os.Handler
4-
import android.os.Looper
53
import com.facebook.react.bridge.Dynamic
64
import com.facebook.react.bridge.ReadableMap
75
import com.facebook.react.module.annotations.ReactModule
@@ -194,15 +192,7 @@ class TabScreenViewManager :
194192
) {
195193
val uri = value?.getString("uri")
196194
if (uri != null) {
197-
val context = view.context
198-
loadTabImage(context, uri) { drawable ->
199-
// Since image loading might happen on a background thread
200-
// ref. https://frescolib.org/docs/intro-image-pipeline.html
201-
// We should schedule rendering the result on the UI thread
202-
Handler(Looper.getMainLooper()).post {
203-
view.icon = drawable
204-
}
205-
}
195+
loadTabImage(view.context, uri, view)
206196
}
207197
}
208198

android/src/main/java/com/swmansion/rnscreens/gamma/tabs/image/TabsImageLoader.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.swmansion.rnscreens.gamma.tabs.image
22

33
import android.content.Context
44
import android.graphics.drawable.Drawable
5+
import android.os.Handler
6+
import android.os.Looper
57
import android.util.Log
68
import androidx.core.graphics.drawable.toDrawable
79
import androidx.core.net.toUri
@@ -13,8 +15,24 @@ import com.facebook.drawee.backends.pipeline.Fresco
1315
import com.facebook.imagepipeline.image.CloseableImage
1416
import com.facebook.imagepipeline.image.CloseableStaticBitmap
1517
import com.facebook.imagepipeline.request.ImageRequestBuilder
18+
import com.swmansion.rnscreens.gamma.tabs.TabScreen
1619

1720
internal fun loadTabImage(
21+
context: Context,
22+
uri: String,
23+
view: TabScreen,
24+
) {
25+
// Since image loading might happen on a background thread
26+
// ref. https://frescolib.org/docs/intro-image-pipeline.html
27+
// We should schedule rendering the result on the UI thread
28+
loadTabImageInternal(context, uri) { drawable ->
29+
Handler(Looper.getMainLooper()).post {
30+
view.icon = drawable
31+
}
32+
}
33+
}
34+
35+
private fun loadTabImageInternal(
1836
context: Context,
1937
uri: String,
2038
onLoaded: (Drawable) -> Unit,

0 commit comments

Comments
 (0)