Skip to content

chore(Android): make ImageLoader onLoaded's result nullable#4247

Merged
kligarski merged 1 commit into
mainfrom
@kligarski/image-loader-change-result-callback-type
Jul 2, 2026
Merged

chore(Android): make ImageLoader onLoaded's result nullable#4247
kligarski merged 1 commit into
mainfrom
@kligarski/image-loader-change-result-callback-type

Conversation

@kligarski

@kligarski kligarski commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

Follow-up to #4242. Ensures that onLoaded callback is called even if bitmap was null.

Closes https://github.com/software-mansion/react-native-screens-labs/issues/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

  • Ensured that CI passes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Android ImageLoader helper to allow onLoaded to receive a nullable Drawable, so callers can still be notified when Fresco produces a null bitmap (e.g., preventing UI updates from being skipped when an icon fails to materialize as a bitmap).

Changes:

  • Change ImageLoader.loadImage / loadImageInternal callback type from (Drawable) -> Unit to (Drawable?) -> Unit.
  • Call onLoaded(null) when Fresco returns a CloseableStaticBitmap with a null underlying bitmap.
Comments suppressed due to low confidence (1)

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

  • loadImage returns early when ImageSource(...).getUri(context) is null, which means the callback is never invoked. Now that onLoaded accepts Drawable?, it should still be called (with null) so callers waiting on the callback can proceed (matching the PR’s goal of not missing onLoaded).
    onLoaded: (Drawable?) -> Unit,
) {
    // 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

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 59 to +63
if (bitmap != null) {
val drawable = bitmap.toDrawable(context.resources)
onLoaded(drawable)
} else {
onLoaded(null)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to introduce such changes now, we can maybe create an issue to look into the image loader in general.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kligarski kligarski changed the title chore(Android) make ImageLoader onLoaded's result nullable chore(Android): make ImageLoader onLoaded's result nullable Jul 2, 2026
@kligarski kligarski requested a review from t0maboro July 2, 2026 10:25

@kkafar kkafar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems sensible.

@kligarski kligarski merged commit 11ff7d5 into main Jul 2, 2026
6 checks passed
@kligarski kligarski deleted the @kligarski/image-loader-change-result-callback-type branch July 2, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants