-
-
Notifications
You must be signed in to change notification settings - Fork 593
fix: use synchronous RCTConvert for asset images #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
base: main
Are you sure you want to change the base?
fix: use synchronous RCTConvert for asset images #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?
Now we use RCTConvert in debug mode & RCTImageLoader in release.
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.
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