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

Clarify documentation about when onLayout is called #2056

Closed
evelant opened this issue Jul 16, 2020 · 18 comments
Closed

Clarify documentation about when onLayout is called #2056

evelant opened this issue Jul 16, 2020 · 18 comments
Labels
Stale Issues/PR that are not getting much activity and are closer to be closed

Comments

@evelant
Copy link

evelant commented Jul 16, 2020

Description

https://reactnative.dev/docs/view#onlayout

Trying to animate elements in my app to the screen locations of other elements. I get the position of those elements in their onLayout callbacks and cache the results. In some (unknown, undocumented) situations onLayout is not called when an element changes position.

The current documentation states

Invoked on mount and layout changes with:

{nativeEvent: { layout: {x, y, width, height}}}

This event is fired immediately once the layout has been calculated, but the new layout may not yet be reflected on the screen at the time the event is received, especially if a layout animation is in progress.

This does not specify that in some situations the layout information will be incorrect or transitional. It also does not specify in which situations onLayout will not be called. In my case it appears that onLayout is only called on mount but not when a parent changing size causes an element to change x/y position but remain the same size.

It would be helpful if the documentation for onLayout were expanded to detail exactly in which situations onLayout will be called and in which situations the position/size information may be inaccurate. What exactly constitutes layout changes to fire the event?

edit: here are some related issues detailing the undocumented quirks/bugs with onLayout.
facebook/react-native#28775 (animations of transforms don't trigger onLayout)
facebook/react-native#3282 (measure returns undefined on android unless onLayout or collapsable are specified)
facebook/react-native#24219 (reanimated, standard with expo, changes onLayout behavior)
facebook/react-native#23443 (device rotation doesn't trigger onLayout in some situations)
facebook/react-native#19872 (onLayout removed elevation on Android)

Documentation version

v0.63

@stale
Copy link

stale bot commented Dec 25, 2020

👋 Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Issues/PR that are not getting much activity and are closer to be closed label Dec 25, 2020
@olosegres
Copy link

@Stale Issue does not fixed

@stale stale bot removed the Stale Issues/PR that are not getting much activity and are closer to be closed label Jan 21, 2021
@dennisbouwpas
Copy link

@Stale Issue does not fixed!

@chrisbobbe
Copy link

chrisbobbe commented Feb 4, 2021

The answer to the following would also be great to document: are x and y relative to the top-left of the whole screen, or to the top-left of the parent? I believe they're relative to the parent, but I don't want to start a false rumor; my investigation might be wrong. 🙂

But the answer is quite important and would be great to have documented.

@lon9man
Copy link

lon9man commented May 12, 2021

+1

@mrcordova
Copy link

Has anyone found a solution or a work around to get onlayout to fire when size is changed with animation?

@audrew
Copy link

audrew commented Nov 13, 2021

I am trying to find a solution too. Hopefully, that can help https://reactnative.dev/docs/direct-manipulation

@J6ey
Copy link

J6ey commented Jan 22, 2022

Don't quote me, but what I'm understanding is that onLayout is only called when that View UI is updated, so if you're changing its position or size in the background but is not reflecting the UI, then onLayout will not get triggered. It may also get called again if the View hits the re-render phrase.

@github-actions
Copy link

👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues/PR that are not getting much activity and are closer to be closed label Apr 23, 2022
@evelant
Copy link
Author

evelant commented Apr 23, 2022

Issues don't become invalid just because nobody has bothered to look at them.

@github-actions github-actions bot removed the Stale Issues/PR that are not getting much activity and are closer to be closed label Apr 24, 2022
@github-actions
Copy link

👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues/PR that are not getting much activity and are closer to be closed label Jul 23, 2022
@evelant
Copy link
Author

evelant commented Jul 23, 2022

Still needs attention

@github-actions github-actions bot removed the Stale Issues/PR that are not getting much activity and are closer to be closed label Jul 24, 2022
@topheroes
Copy link

Hello, @evelant, did you solve the problem? In my case onLayout gets fired on mount only. Not on translation, rotation, etc.

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues/PR that are not getting much activity and are closer to be closed label Nov 9, 2022
@evelant
Copy link
Author

evelant commented Nov 9, 2022

No, the documentation is still unclear

@github-actions github-actions bot removed the Stale Issues/PR that are not getting much activity and are closer to be closed label Nov 10, 2022
@github-actions
Copy link

github-actions bot commented Feb 9, 2023

👋 Hey there, it looks like there has been no activity on this issue in the last 90 days. Has the issue been fixed, or does it still require the community attention? This issue will be closed in the next 7 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale Issues/PR that are not getting much activity and are closer to be closed label Feb 9, 2023
@github-actions
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@NickGerleman NickGerleman reopened this Jul 19, 2023
@github-actions
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Issues/PR that are not getting much activity and are closer to be closed
Projects
None yet
Development

No branches or pull requests

10 participants