Skip to content

Commit 11ff7d5

Browse files
authored
chore(Android): make ImageLoader onLoaded's result nullable (#4247)
## Description Follow-up to #4242. Ensures that `onLoaded` callback is called even if bitmap was null. Closes software-mansion/react-native-screens-labs#1589. ### Reasoning E.g. in Stack v5 toolbar menu item implementation when update via view command contains icon, we delay updating the menu item until we load the image. We don't want to miss the onLoaded callback, otherwise we won't update the menu item at all. ## Changes - make `onLoaded`'s result in `ImageLoader.loadImage` and `ImageLoader.loadImageInternal` nullable `Drawable` (`Drawable?`) - no changes were required in existing code that uses the image loader ## Before & after - visual documentation N/A ## Test plan Ensure that images still load in tabs, stack v5. ## Checklist - [x] Ensured that CI passes
1 parent 926286f commit 11ff7d5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • android/src/main/java/com/swmansion/rnscreens/gamma/helpers

android/src/main/java/com/swmansion/rnscreens/gamma/helpers/ImageLoader.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private const val TAG = "ImageLoader"
2323
internal fun loadImage(
2424
context: Context,
2525
uri: String,
26-
onLoaded: (Drawable) -> Unit,
26+
onLoaded: (Drawable?) -> Unit,
2727
) {
2828
// Since image loading might happen on a background thread
2929
// ref. https://frescolib.org/docs/intro-image-pipeline.html
@@ -39,7 +39,7 @@ internal fun loadImage(
3939
private fun loadImageInternal(
4040
context: Context,
4141
uri: Uri,
42-
onLoaded: (Drawable) -> Unit,
42+
onLoaded: (Drawable?) -> Unit,
4343
) {
4444
val imageRequest =
4545
ImageRequestBuilder
@@ -59,6 +59,8 @@ private fun loadImageInternal(
5959
if (bitmap != null) {
6060
val drawable = bitmap.toDrawable(context.resources)
6161
onLoaded(drawable)
62+
} else {
63+
onLoaded(null)
6264
}
6365
}
6466

0 commit comments

Comments
 (0)