-
Notifications
You must be signed in to change notification settings - Fork 306
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
aspectRatio should be optional? #32
Comments
You have the point. One of the three properties could be calculated from the two others. If I didn't miss anything, looking at the code, you can see that width property is ignored at all. It is directly calculated from height * aspectRatio. It would make sense to remove either width or aspectRatio from Props. |
I started fixing this one myself; but ended up in a rewrite of this library. So I didn't feel for a PR anymore. To give something back; I just posted it as a gist. You can take a look; in case you might need some inspiration / an other point of view. https://gist.github.com/smeijer/02638a47c5dd31e64ddf84c2cb62cc12 This one also solves #28. But I did remove the responsiveness. Because I believe that it is something that shouldn't be in this lib. I solve by wrapping the component in |
@smeijer does your approach to addressing the responsiveness aspect simply add columns when the container gets wide or does it resize and grow the images like what this library currently does? Thanks for the insights. |
@neptunian, my approach is a combination, but out of the scope of that gist. The gallery it self, scales the images to fit the width of the container. Like this library does. Trough For example; if react-measure says the I can add the gallery like: // written in the comment to show the idea, so bugs are likely to exists
render() {
const { maxImageWidth } = this.props;
return (
<Measure whitelist={['width']}>{({ width }) => (
<Gallery cols={Math.ceil(width / maxImageWidth)}>....</Gallery>
)}
</Measure>
);
} Maximum or Minimum width can easiliy be changed by changing Math.ceil with Math.floor. |
@smeijer I see. Okay i'll think about using this measure tool for adding more columns based on the container width. thanks! |
@smeijer I tried your solution with Measure component but it gives me the width of the app and not the Gallery div's width. Is there any way to measure the actual Gallery component so as to pass in the appropriate number of columns based on the Gallery's width and not the app's width? |
In my opinion the Gallery should take the full width of its parent. It's not up to the Gallery to decide how wide it should become. If the user wants to limit it's width, he can simply do so with a parent, or if you want with a pass-trough style property. <div style={{ width: 650 }}>
<Gallery photos={[...]} />
</div> <Gallery photos={[...]} style={{ width: 600 }} /> Gallery should here have a render method like: render() {
const { photos, style } = this.props;
return (
<div style={{ width: '100%', ...style }}>
{photos.map(...)}
</div>
)
} React Measure will return the width of the element he is surrounding. This is here either the 100% of the parent, or the by the user limited number or pixels trough a style property. |
Perhaps I'm missing the point of
aspectRatio
, but I cannot see why this field is required. Even better; I don't see why this should be a api property at all.Isn't the
aspectRatio
simplywidth
/height
? Anything else results in distortion no?The text was updated successfully, but these errors were encountered: