-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
add image size to onLoad nativeEvent #2364
add image size to onLoad nativeEvent #2364
Conversation
Excellent. :) |
@paramaggarwal can you tell me why the checks failed? This is my first PR... |
Network failed on the CI server. Try pushing another commit to trigger a new build. |
I think this returns the displayed size, not the intrinsic size. Can you verify? |
@ide @DUBERT RCTImageView gets the resized dimensions. Would need to change Relevant code: react-native/Libraries/Image/RCTImageLoader.m Line 220 in f0dd9fb
|
I don't know Objective-C, so here's my best shot. I expect there will be a number of revisions necessary to bring it up to snuff. I believe there is value in providing both the displayed size and intrinsic image size. So I kept Because I modified the imageLoader function and callback, I had to update it in a bunch of locations, passing |
Wow, I didn't know that RN resizes the image based on the size it will be used at. Quite a nice memory optimisation. My vote is that only |
I'm not sure it's worth showing the displayed size because that should be the size of the Image component. Basically what @paramaggarwal said. |
Updated to only show size for network images. |
Looks good! Small nitpick - no need for the |
@paramaggarwal I'm checking it so that I don't pass |
@DUBERT I don't think that is a problem. Let's wait for others' thoughts. |
@@ -126,7 +126,7 @@ - (void)reloadImage | |||
scale:RCTScreenScale() | |||
resizeMode:self.contentMode | |||
progressBlock:progressHandler | |||
completionBlock:^(NSError *error, id image) { | |||
completionBlock:^(NSError *error, id image, id dimensions) { |
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.
NSValue instead of id
b4b9c01
to
a40f9c1
Compare
@ide updated and squashed |
+1 |
cc @a2 @nicklockwood for review |
b0ffe88
to
fddc263
Compare
@paramaggarwal any idea why the checks have failed? You were able to help me last time |
|
77e25fe
to
8a3731c
Compare
@ide, @a2, @nicklockwood for review? 😸 |
@@ -194,7 +194,18 @@ - (void)reloadImage | |||
} | |||
} else { | |||
if (_onLoad) { | |||
_onLoad(nil); | |||
if (dimensions != nil) { | |||
CGSize size = [dimensions CGSizeValue]; |
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.
Could we greatly simplify this PR by using image.size
(may need to be careful to account for screen scale -- but it sure would make this PR super short :D )?
nvm, that goes back to my original comment on this PR
8a3731c
to
e9f6791
Compare
@DUBERT updated the pull request. |
e9f6791
to
e7383fe
Compare
@DUBERT updated the pull request. |
e7383fe
to
1e632f1
Compare
add dimensions and scale properties to the nativeEvent add comments add check for images without intrinsic size only show size for network images clean up formatting create event first, check for nil change id dimensions to NSValue *dimensions change to NSValue *dimensions catch http images remove file git included add tests fix tests fix errors remove console.log
@DUBERT updated the pull request. |
1e632f1
to
6544806
Compare
@DUBERT updated the pull request. |
I'm not sure I understand the purpose of this. Why not just get the size from the image directly? (image.size). Why do you care how big the image was originally before we resized it? How would this information be used? |
OK, sorry, should've read the attached issue properly. I understand the problem, but this is the wrong solution. Loading the image at the wrong size using the I'd be fine with sending the actual loaded image size in the callback. One option would be to do that, then you could load the image at the maximum possible size and then resize it. Still a hack, but at least the API would be logical. You could embed the In terms of solving the actual use case, I think we need to add a way to preload images and get their size without having to display the image while its loading. It would be relative easy to expose something like that, but I'll need to discuss with the Android team what the API should look like. |
I tried adding these on RN 0.13 and I couldn't get the project to start... 😢 |
I really need this fix as well. Is there any work going on here? |
@olofd Nope. I don't know how to proceed. It sounds like the FB devs don't like the way I solved this. But it's not a feature they are planning to provide themselves. So right now I'm just having to use a forked version of react-native. I'm several versions behind because I'm tired of rebasing :( |
Ok @DUBERT . for everyone who has a problem with this and want to be able to support remote images with unknown dimensions I made a hack you can use before the react team supports the use-case. This branch is not suppose to be beautiful, rather to touch as little as possible, so it'll be easy to keep merging, and still give you the functionality. It's based on 0.16.0: Compare against 0.16.0: To use it. Just change your package.json react-native-version to: I'll try to keep merging it with new releases. |
That looks great @olofd, I'll use it in my project. @nicklockwood Do you have any more thoughts about this PR? Should I go ahead and close it? Or is it worth trying to figure out how to preload images and get their size? Please keep in mind I have very little Objective-C experience. |
I'm still actively investigating the right API for preloading. I don't want to add something we won't be able to support moving forward. Sorry about the wait. |
Updated my branch with this feature for v0.17.0-rc: Use this in package.json: Compare-view: |
@olofd using your branch, too. Works like a charm 👍 |
Updated my branch with this feature for v0.17.0: Use this in package.json: |
So, what's the deal? |
Issue: #494
Related: #2180