eiriklv/react-masonry-component

onLayoutComplete triggered before any layout has taken place

JuRomand opened this issue · 4 comments

Hello,

I have a problem with onLayoutComplete :
I'd like to wait for the layout and animations to be complete before showing the items but the event "onLayoutComplete" is triggered before any layout has taken place (I tried with debugger), and is then triggered a lot of times (more times than the number of items I need to display).

Did I miss something ?

I'm also not sure whether the event is supposed to be triggered once all items have been rendered properly or each time an item is render.

Thanks in advance for your help (and many thanks for this lib!!!)!

This is my code (simplified):

export class Masonry extends React.Component<{props}, State> {

	//...

	public constructor(props) {
		super(props);
		//...
		this.handleLaidOutItems = this.handleLaidOutItems.bind(this);
	}

	// ... component logic

	public handleLaidOutItems(laidOutItems) {
		//...
	}

	public render() {
		return (
			<InfiniteScroll
				pageStart={0}
				loadMore={this.renderMoreTweetCards}
				hasMore={this.hasMoreItems}
				useWindow={false}
				initialLoad={false} // Necessary: loads all items if true
				threshold={500}
			>
				<Masonry
					className="grid"
					options={{
						itemSelector: ".grid-item",
						transitionDuration: 0,
					}}
					enableResizableChildren={true}
					onLayoutComplete={this.handleLaidOutItems}
				>
					{children.map( id => {
						return <child key={id}/>
					})}
				</Masonry>
			</InfiniteScroll>
		);
	}
}

I have the same issue - the event fires about 6 times.
4 times before children have been passed in, 2 after.

I think my PR will fix your issues.

Let me know if it does and I'll update it to point to this ticket.

@TheBosZ will this be merged any time soon?

@andreencar I doubt it. I think this project is dead and I have no insight or perms to merge my PR. If you'd like my fix, you can use my fork.