-
-
Notifications
You must be signed in to change notification settings - Fork 595
fix(iOS): load header items icons synchronously when feasible #3355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(iOS): load header items icons synchronously when feasible #3355
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we have this ugly effect now.
The situation here is a bit more complex.
First: in release mode, the code using RCTImageLoader will work just fine if we remove dispatch_async in completion block -> because this is the source of the delay.
In debug mode, when the assets are not loaded from application bundle (not talking about JS bundle here, rather NSBundle), but are downloaded from packager, RCTImageLoader does this asynchronously, indeed.
Since RCTConvert for image related conversions got deprecated, I'd like to limit its usage only for debug mode, where we can not load images synchronously in any other way. We could do this manually, but I'd like to avoid that option even more.
I'll start conversation with React Native team about giving us support for synchronous loading, since this will be rather a regression if the RCTConvert UIImage gets removed and we don't have any other sync API.
|
Also disadvantage of using RCTConvert is that we don't have any image caching. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm drafting a refactor & noticed this. Just a question.
| return self; | ||
| } | ||
|
|
||
| self.title = dict[@"title"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you resign from setting title here and postponed it for later? Was there a particular reason here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to set the title before remote images had been downloaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But shouldn't be needed anymore since from what I understand also remote images will be loaded synchronously in production mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only assets stored on the device will be loaded synchronously. If you need to download header button images from some remote source during runtime (is this a valid use case?) it'll be done asynchronously. Packager (metro) assets are treated like device-local assets, so they're exception to that rule & will be loaded synchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't think its a valid use case. Just something to be aware of that the title will be shown until the image is loaded then if the download is done asynchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored the code a bit. I'll be willing to land this if you confirm that also works for you.
Thank you! And thanks for explaining how RCTImageLoader works in production/debug mode. Your refactor is working in my testing so feel free to merge |
One thing to be aware of now though is that you cant load images of type |
Now we use RCTConvert in debug mode & RCTImageLoader in release.
6ee8302 to
5db502d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this.
I'll land this PR once CI passes.
Regarding ImageURISource - thanks for reporting this. We might wanna handle this separately.
## Description It seems like in #3355, `react-navigation` submodule has been changed from `7.x` branch (react-navigation/react-navigation@3d1e4ef) to older commit from `main` branch (react-navigation/react-navigation@782b6d4). We probably want to keep in sync with `7.x` branch for now. This PR updates `react-navigation` submodule to latest commit from `7.x` branch. ## Changes - update `react-navigation` submodule to react-navigation/react-navigation@359df7d ## Test code and steps to reproduce Run example app. ## Checklist - [x] Ensured that CI passes
Description
When using RCTImageLoader for images in headerRightItems/headerLeftItems the asynchronous
loadImageWithURLRequestproduces som layout bugs as shown under "Screenshots". These are:Changes
ImageRequireSourceload the image with[RCTConvert UIImage]. I know its deprecated but thats the only synchronous image loader that I know of.ImageURISourceset the bar button title in the completion block ofloadImageWithURLRequestBarButtonItemsexample to latest types/api from react-navigation/native-stack.Screenshots / GIFs
Before
Title briefly shown
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2025-10-29.at.21.51.42.mov
Wide bar button item while
loadImageWithURLRequestcompletesSimulator.Screen.Recording.-.iPhone.17.Pro.-.2025-10-29.at.22.19.46.mov
After
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2025-10-29.at.22.20.18.mov
Test code and steps to reproduce
Use any of the examples with required images in BarButtonItems
Checklist