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

onLayoutComplete triggered before any layout has taken place #139

Open
JuRomand opened this issue Oct 10, 2018 · 4 comments
Open

onLayoutComplete triggered before any layout has taken place #139

JuRomand opened this issue Oct 10, 2018 · 4 comments

Comments

@JuRomand
Copy link

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>
		);
	}
}
@daveycakes
Copy link

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

@TheBosZ
Copy link

TheBosZ commented Jun 14, 2019

I think my PR will fix your issues.

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

@andreencar
Copy link

@TheBosZ will this be merged any time soon?

@TheBosZ
Copy link

TheBosZ commented May 8, 2020

@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.

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

No branches or pull requests

4 participants