eiriklv / react-masonry-component

A React.js component for using @desandro's Masonry
MIT License
1.44k stars 145 forks source link

onLayoutComplete triggered before any layout has taken place #139

Open JuRomand opened 6 years ago

JuRomand commented 6 years ago

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 commented 5 years ago

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

TheBosZ commented 5 years ago

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 commented 4 years ago

@TheBosZ will this be merged any time soon?

TheBosZ commented 4 years ago

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