Skip to content
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(gatsby-image): add matchMedia to fix wrong aspect ratio and dimensions in art-directed image arrays #19887

Merged
merged 6 commits into from
Dec 16, 2019

Conversation

timhagn
Copy link
Contributor

@timhagn timhagn commented Nov 30, 2019

Description

This PR introduces a matchMedia() query for fluid or fixed art-directed arrays.
This prevents retrieving the wrong image (the first from the art-direction stack ain't always the correct one) when ascertaining its aspectRatio or width & height respectively.

It adds tests for fluid or fixed art-directed stacks as well.

Of course this sadly only works during rendering in the browser, and falls back to the default first image from the array, but at least in the browser the correct image is chosen ; ).

Related Issues

Addresses #15189
Addresses a few of the pain points in ##13395
(And probably a few other issues ; )

Best,

Tim.

P.S.: Works quite well for me in gatsby-backrgound-image ; ).

@timhagn timhagn requested a review from a team as a code owner November 30, 2019 15:35
@timhagn timhagn changed the title fix(gatsby-image): add matchMedia to fix wrong aspect ratio in art-directed image arrays fix(gatsby-image): add matchMedia to fix wrong aspect ratio and dimensions in art-directed image arrays Nov 30, 2019
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've left some comments. Please have a look :)

packages/gatsby-image/src/__tests__/index.js Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
change wording according to review

Co-Authored-By: Peter van der Zee <209817+pvdz@users.noreply.github.com>
@timhagn
Copy link
Contributor Author

timhagn commented Dec 2, 2019

Hi @pvdz,

thanks for the reviews, gonna continue attending them now. I just took the getCurrentSrcData() from gatsby-background-image and there is quite some use for just using fluid | fixed as an object (e.g. directly being able to pass (converted)props into the functions), but I see your point for gatsby-image. Am in the code : ).

Best,

Tim.

#done Adapted everything to your reviews / change requests and commented on the other two : ).

@timhagn timhagn requested a review from pvdz December 2, 2019 20:13
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement, thank you!

What's left is mostly about typing.

packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
packages/gatsby-image/src/index.js Show resolved Hide resolved
packages/gatsby-image/src/index.js Outdated Show resolved Hide resolved
@timhagn
Copy link
Contributor Author

timhagn commented Dec 11, 2019

Hi @pvdz,

thanks again for the reviews and sorry that I didn't get back to you earlier, was just fully booked last week and got me a stomach bug over the weekend : (.
Gonna try getting your change requests in this week, though.

Best,

Tim.

@timhagn
Copy link
Contributor Author

timhagn commented Dec 12, 2019

Hi @pvdz,

while having a short break of both my bug & work and looking through your requests, I finally realize, why most of gatsby-image doesn't use JSDOC at all ^^.
But am at it.

Best, Tim.

@timhagn timhagn requested a review from pvdz December 12, 2019 13:31
@timhagn
Copy link
Contributor Author

timhagn commented Dec 12, 2019

Hi again, hope I now id change all comments and requests accordingly : ).

Best,

Tim.

@timhagn
Copy link
Contributor Author

timhagn commented Dec 12, 2019

Mkay. The starters_validate failing seems to have nothing to do with this PR, any ideas?

Best,

Tim.

EDIT: Oh, I forgot to merge in the other changes from upstream % ).

Copy link
Contributor Author

@timhagn timhagn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now everything should be according to your requests - else I'm just stripping out the JSDocs ; ).

Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all the issues and for creating this PR in the first place :D

@pvdz pvdz merged commit b3c000b into gatsbyjs:master Dec 16, 2019
@timhagn
Copy link
Contributor Author

timhagn commented Dec 16, 2019

Thanks @pvdz!

Hope I didn't get the JSDocs too wrong ^^. Glad something from gbi made it back to
gatbsy-image : ).

Best,

Tiim.

EDIT: Smiley split corrected; ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants