react-responsive-masonry icon indicating copy to clipboard operation
react-responsive-masonry copied to clipboard

feat: distribute children by height

Open yangchristina opened this issue 1 year ago • 7 comments

Resolves #117

Before: Screenshot 2024-07-10 at 3 21 06 PM

After: Screenshot 2024-07-10 at 3 19 02 PM

Uses a greedy algorithm - this keeps items in a similar order as what was passed in. For the best column distribution you probably need some form of sorting the children like here. You could also use something like MUI's masonry's sequential prop to use the old distribution algorithm.

This is my first time really working with react class components, so I'm not sure if this is a good method. I couldn't really figure out how to get the demo running (had some errors), so I just tested on my own project instead.

Sorry the commit name is misleading, this is not sequential

yangchristina avatar Jul 10 '24 22:07 yangchristina

Hello @yangchristina . Thanks for your help! I tried you branch but the ResponsiveMasonry demo is broken. localhost_1190_

cedricdelpoux avatar Jul 26 '24 03:07 cedricdelpoux

@cedricdelpoux I've fixed it. I was able to run the demo before merging with master, so I've confirmed it works, but I wasn't able to figure out running it after merging, so I can't confirm whether it works or not with the new updates.

yangchristina avatar Aug 16 '24 21:08 yangchristina

Can we merge it?

piszczu4 avatar Aug 24 '24 13:08 piszczu4

Sorry for the delay. @yangchristina can you resolve conflicts? After that I will merge. Thank you

cedricdelpoux avatar Sep 10 '24 08:09 cedricdelpoux

@cedricdelpoux I don't see any conflicts?

yangchristina avatar Sep 13 '24 04:09 yangchristina

@yangchristina

Screenshot 2024-09-16 at 11 14 36

cedricdelpoux avatar Sep 16 '24 09:09 cedricdelpoux

@yangchristina I think it's because your first commit Merge remote-tracking branch 'upstream/master'.

Could you rebase your branch on master and apply only your 3 last commits? Or better squash your 3 last commit in just one?

Thank you

cedricdelpoux avatar Sep 16 '24 09:09 cedricdelpoux

Looking forward to this so I wanted to bump. Happy to help rebase

fostergn avatar Sep 22 '24 22:09 fostergn

@fostergn thanks for the reminder, I'd forgotten about this. @cedricdelpoux I've rebased it, is this okay? I still can't run it, so would you mind checking if this is still fine?

yangchristina avatar Sep 22 '24 23:09 yangchristina

@yangchristina Sorry I just tried your branch and the ResponsiveMasonry demo is still broken. The second and third column are in the DOM but empty. Screenshot 2024-09-23 at 12 17 35

The same demo on master works as expected like here.

you need to run yarn start to run the demo locally

cedricdelpoux avatar Sep 23 '24 10:09 cedricdelpoux

@cedricdelpoux That's what I've been trying but it doesn't work. It just terminates immediately

Screenshot 2024-09-23 at 11 03 25 AM

Before, I got it to run by using node 16, but now even that isn't working.

What node and yarn versions are you using?

yangchristina avatar Sep 23 '24 18:09 yangchristina

node v22.3.0 yarn 1.22.21

cedricdelpoux avatar Sep 25 '24 13:09 cedricdelpoux

any update here? Would love this feature!

nathandaven avatar Oct 10 '24 18:10 nathandaven

@cedricdelpoux Should be fixed now, distributing children by height will only occur when the height of every child is > 0 The problem before was that distributeChildren was running before images had loaded, so they all had a height of 0

Not sure if this is a good solution, since it only reorders things after every image has loaded, so I added a sequential prop to use old behaviour

Running it worked when I ran yarn set version 1.22.21

yangchristina avatar Oct 11 '24 20:10 yangchristina

Thanks! Published in 2.4.0

cedricdelpoux avatar Oct 12 '24 06:10 cedricdelpoux

Sorry @yangchristina, your PR was causing issues. https://github.com/cedricdelpoux/react-responsive-masonry/issues/131

I reverted for now

cedricdelpoux avatar Dec 04 '24 06:12 cedricdelpoux

@yangchristina If you want to re-submit the PR, the fix is rather simple: https://github.com/cedricdelpoux/react-responsive-masonry/issues/131#issuecomment-2516680319

ADTC avatar Dec 04 '24 09:12 ADTC

Sorry about this, thanks @ADTC! I've opened another PR in #134

yangchristina avatar Dec 04 '24 18:12 yangchristina

Hi @yangchristina the re-submitted PR is merged.

Would it be possible for you to help update the type definitions here? If you have some experience contributing PRs to DefinitelyTyped:

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-responsive-masonry

It's actually missing all of these. Maybe I will try it some other time, but I don't have experience contributing to the DT project.

  containerTag: PropTypes.string,
  itemTag: PropTypes.string,
  itemStyle: PropTypes.object,
  sequential: PropTypes.bool,
Name PropType Description Default
containerTag String Tag name of the container element "div"
itemTag String Tag name of the item element "div"
itemStyle Object Style object applied to each item {}
sequential Boolean If true, items are placed in the order they are passed false

ADTC avatar Dec 07 '24 18:12 ADTC

@ADTC I've made a PR for this https://github.com/DefinitelyTyped/DefinitelyTyped/pull/71485

yangchristina avatar Dec 22 '24 03:12 yangchristina

@yangchristina you are awesome!! 😎

ADTC avatar Dec 22 '24 04:12 ADTC

@ADTC you are the awesome one, if it wasn't for you figuring out what the fix for this pr was, I would have gotten quite panicked about causing a regression, so thanks for that!

yangchristina avatar Dec 22 '24 05:12 yangchristina

Thank you @yangchristina!

This right here is the spirit of open source. A community of people volunteering to come together to solve challenges, not for their own benefit, but for the greater good and for the benefit of all.

ADTC avatar Dec 22 '24 06:12 ADTC