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

feat: Add onLayoutInit callback #1811

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

antoinm
Copy link

@antoinm antoinm commented Dec 20, 2022

Goal of the PR

The goal of this PR is to be able to distinguish between the very first call to onLayoutChange made by RGL, from the ones that could be triggered manually by users.

Technical details

This work aims to add an onLayoutInit callback, that is called inside the componentDidMount, once the layout has been possibly corrected.

Practical use case

I have a use case where I want to keep a dirty state of my layout, in order to inform users whether they have unsaved modifications.
To handle this dirty state, I'm comparing the current layout with a reference layout stored after initialization.

Some layouts need to be corrected by RGL, so I need to set my layout reference after it has been possibly corrected.

At the moment, I have no way of distinguishing between onLayoutChange calls. (manually triggered by users VS called by RGL to "correct" the layout)
An onLayoutInit callback does the job and allows me to set my reference layout once the layout has been possibly corrected.

This work aims to add an `onLayoutInit` callback, that is called inside the componentDidMount, once the layout has been possibly corrected.
@STRML
Copy link
Collaborator

STRML commented Feb 24, 2023

I'm not sure why this is needed - onLayoutChange will be called if the layout is changed. If it is not called, it has not changed.

@antoinm
Copy link
Author

antoinm commented Feb 27, 2023

I'm not sure why this is needed - onLayoutChange will be called if the layout is changed. If it is not called, it has not changed.
Thanks for you question, I should have given a practical use case while submitting the PR. (Will add the use case to the PR's description.

The goal of this PR is to be able to distinguish between the very first call to onLayoutChange made by RGL, from the ones that could be triggered manually by users.

I have a use case where I want to keep a dirty state of my layout, in order to inform users whether they have unsaved modifications.
To handle this dirty state, I'm comparing the current layout with a reference layout stored after initialization.

Some layouts need to be corrected by RGL, so I need to set my layout reference after it has been possibly corrected.

At the moment, I have no way of distinguishing between onLayoutChange calls. (manually triggered by users VS called by RGL to "correct" the layout)
An onLayoutInit callback does the job and allows me to set my reference layout once the layout has been possibly corrected.

@STRML
Copy link
Collaborator

STRML commented Feb 27, 2023

Seems a local variable, e.g. (this.hasLayoutInit: boolean) in your component could fix this instead?

That is, you can know if the layout has changed if you've hit componentDidMount and the callback wasn't called yet.

@antoinm
Copy link
Author

antoinm commented Apr 13, 2023

Seems a local variable, e.g. (this.hasLayoutInit: boolean) in your component could fix this instead?

That is, you can know if the layout has changed if you've hit componentDidMount and the callback wasn't called yet.

I'm not sure to understand how you would do. The layout is considered initialized once it has been "auto-corrected". Since it displays remote data, it might or might not get autocorrected. How can I get the information that the layout has been autocorrected, and that I can use the new layouts as reference?
If that seems doable with the current API of the library, could you provide me with a small example that does the job?

Since my description of the issue was most likely not enough detailed to understand the issue I'm trying to resolve, I created a codesandbox, to illustrate the issue.

⚠️ Demo app should be opened as a separate full-screen width window so that the lg layout applies

On the left, you can see the example with the issue (App.tsx file), and on the right, the issue fixed by using the onLayoutInit callback. (AppFixed.tsx file)

@antoinm
Copy link
Author

antoinm commented Dec 11, 2023

@STRML Did you have the chance to take a look to the codesandbox I provided ? It should illustrate the issue I faced.

@STRML
Copy link
Collaborator

STRML commented Dec 13, 2023

Try this sandbox (modifications in AppFixed to use useEffect and useRef).

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

Successfully merging this pull request may close these issues.

None yet

2 participants