Closed davidvuong closed 6 years ago
By default it's placing each image the moment they are resolved based on the next position, since you are on alpha v0.5.0 you can the priority
property and set it to 'balance' and it will use heights and attempt to balance the masonry with it's current state.
@brh55 Thanks. Using a balanced priority seemed to have helped. I'm still seeing patchy areas but they're not as bad.
@brh55 Just an update: I've changed from 4 to 3 columns and set priority
to balance
and I don't think this is working correctly. Initially, all 3 columns have photos but as I add more, overtime the first column grows but other two remain unchanged.
In case this is useful at all: I'm now testing with about 1.3k images. This starts to happen when I insert images with differing heights. The first 24 images have the same height and width but the 25th image has a smaller height (although, same width). At this point masonry only updates the first column.
I've included a screenshot as an example:
I wanted to see if this was still a problem when the image heights are all the same. Unfortunately it is still an issue.
<Masonry
columns={3}
bricks={this.state.images}
sorted
priority="balance"
spacing={1.5}
imageContainerStyle={{
height: 180,
}}
/>
If you have all image heights the same, you should just use a standard flatlist
, there should be plenty of components available that will accomplished a grid effect.
The issue with masonry is it balances the grid using the component state. When each image is asynchronously resolved, it places the image within a column and then updates the state, but react setStates
is also asynchronous and will sometimes batch the state changes into one (for performance reasons). Hence why placements may be off as it's using an older state. Redux would probably solve this issue, but I'm not too keen on rewriting this as I'm not using the component myself for any production apps any longer.
I've included some examples of what I mean below:
As you can see, sometimes certain columns grow faster than others leaving large patchy areas. This is the code snippet I'm using for the above examples:
this.state.bricks
React Native: 0.55.4 React Native Masonry: 0.5.0-alpha.1
Any idea what might be wrong? I'm hoping there's a temporary workaround. Thanks!