-
Notifications
You must be signed in to change notification settings - Fork 27.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
onLoadingComplete()
should pass naturalWidth
and naturalHeight
#27213
Comments
see #27152 also |
^ Locked #27152 and moved the discussion here. |
This appears to have been fixed in (or by) 11.0.2-canary.20 |
You'll need to updated to the latest canary to get We are not providing the ref/element at this time because it would be too easy to break the component if you had raw access to the underlying image, for example changing inline styles. In your example where you use |
@styfle Basically a messy, dense gallery grid from a stream of photos outside of my control. Think tetris, but photos of various aspect ratios. |
You can find the width & height from the parent element since For example, this parent div is 300x500 so the image will also be 300x500. next.js/examples/image-component/pages/layout-fill.js Lines 9 to 11 in f5ee9ed
|
@styfle yeah, I get that, and honestly I might be expecting too much from next/image. But basically I'm setting the width and height of parent element after image is loaded. > Have grid with auto columns at 10px wide This is the look I'm trying to achieve![image](https://user-images.githubusercontent.com/80008674/127542339-d445b6db-a6f6-4431-a278-92d8b84ab8a2.png)I could show everything as squares, but the site is for artists and I'd like to respect their creative decisions, like composition. Also, if next/image just had a fileAspectRatio prop that could work I think, but I don't know what I'm talking about in regards to image optimization. E2A: At this point, I've misunderstood the purpose of the onLoadingComplete, feel free to close the issue if discussion isn't helpful. |
If |
@styfle 100% yes, it would. I was unaware of those properties. |
onLoadingComplete()
should pass naturalWidth
and naturalHeight
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
11.0.2-canary.16
What version of Node.js are you using?
14.16.0
What browser are you using?
Brave (Chromium)
What operating system are you using?
Windows
How are you deploying your application?
next dev
Describe the Bug
onLoadingComplete() event handler does not pass any props.
Expected Behavior
The expected behavior for onLoadingComplete (unless I'm missing the point of this prop) is the same as onLoad for regular old HTML and onLoadedMetadata/onCanPlay for videos -- a synthetic react event with .target prop.
To Reproduce
I have a function/event handler that calculates the aspect ratio of an image as soon as it is loaded:
Here's how I've implemented next/image:
and videos:
Currently the calcAspectRatio returns
undefined
for next/image - afaiu, this would mean it doesn't pass any reference to itself when loading is completeAnd returns this (expected) for video:
The text was updated successfully, but these errors were encountered: