-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[iOS]:- fixed image resize mode in release mode for iOS #44763
base: main
Are you sure you want to change the base?
Conversation
Base commit: 4a8f0ee |
@cipolleschi 😅 can you review this? |
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.
nit, but it looks good!
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cipolleschi 😅 are the fb internal linter fail related to my change since it is only accessible to meta employees! |
@cipolleschi friendly ping 😀 |
Is it good. I had to lint it with the internal linter and there were some unrelated tests failing. I rebased it as well, and I hope we can land it before EOW. |
thanks @cipolleschi , for helping me out with this PR! hoping to make react native more awesome 😊 |
Some tests were failing internally. I'm fixing them and I hope to get this approved internally soon, so I can land it. |
hey @cipolleschi its definitely okay and i understand appreciate the work you are doing 😊. |
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.
Sorry for the late rieview. A concern has been risen internally.
I added the comment in the code.
fmax(fmin(sourceSize.width, targetPixelSize.width), fmin(sourceSize.height, targetPixelSize.height)); | ||
UIImage *__nullable RCTDecodeImageWithLocalAssetURL(NSURL *url, CGSize destSize, CGFloat destScale, RCTResizeMode resizeMode) | ||
{ | ||
CGImageSourceRef sourceRef = CGImageSourceCreateWithURL((__bridge CFURLRef)url, NULL); |
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.
Sorry for the late reviewev. A concern has been raised internallt that this implementation might bypass [UIImage imageNamed:]
which also works as a cache and it is more efficient for small images like icons.
A suggestion is to use decodeImageFromCGImageSourceRef
only if the resizeMode is different from the default.
So, the logic would be (pseudocode here):
if (resizeMode is the default) {
return RCTImageFromLocalAssetURL(url);
}
//rest of the current method
what do you think?
Friendly ping @cipolleschi :-) |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Hi @Biki-das! Sorry for this to taking too long, but we are not convinced by the fix. We are a bit scared that the there would be perf implications and this difference between Debug and Release is a bit weird. The right approach here is to understand why image decoding would fail, and avoid going into the It could also be that the issue is not in the image loading code but in the sequence that is used to set the resizeMode. If it is not too much of an ask, would you prepare a simple repro, like the one you are using in the videos, starting from this template? |
The reason image decoding fails is because in debug only mode it's using the method the point that i understand as of now is the the image decoding does not fail as far as i understand, the resize mode just gets ignored in case of release build while using the well further ok let me try to create a reproduce repo cc @cipolleschi |
just tinkering and have a added a CFRelease method call to ensure the sourceRef is release one thing i am trying to understand is there a lot of performance diff between calling would like to know more as i don't have much idea of the same |
this is the method being used currently to handle the image decoding for the release mode. no resize mode aspects are taken here |
I think that the suggestion revolves more around: how can we make The root difference, IIUC, is that:
The proper solution would be not to decode everything from scratch, but to extend What do you think? Does it make more sense? |
Thanks @cipolleschi for the explanation yeah now it is clear to me what is expected let me take a look at the same during the weekend to come up with something |
Hello, |
@thepdatoi sorry to hear that you are having the same error and yes, even if you downgrade, you'll still have the same issue, sadly. |
Summary:
On iOS, when attempting to use a local image with a different resizeMode than the default one in a release build, it doesn't work as expected if the image is a local asset. The problem lies in how the image is loaded and processed.
In a debug build, the image loads correctly with the desired resizeMode. This is because the method RCTDecodeImageWithData is employed, which handles the resizeMode properly.
debug.mp4
In contrast, in a release build, the image does not load with the desired resizeMode. This is due to the use of RCTImageFromLocalAssetURL, which is designed specifically to load an image by URL and does not handle resizeMode.
To address this issue, a new method called RCTDecodeImageWithLocalAssetURL has been introduced. This method replicates the resizeMode handling strategy of RCTDecodeImageWithData but loads the image by URL instead of by data.
To ensure backwards compatibility and handle edge cases where the image cannot be loaded using the new method, a fallback to RCTImageFromLocalAssetURL is retained.
Following has been done to fix the same:-
Changelog:
[IOS] [FIXED] - fixed resize mode in release mode for iOS
Test Plan:
tried to implement the changes in a react native scaffold by changing the node_module files and it worked perfectly
Release.mp4
cc @NickGerleman @cipolleschi @javache @blakef