Ability to listen for changes to the absolute position (ideally before painting) #373
Fearnbuster
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Please forgive me if this is not the correct place for my post.
If this is not the right place for my post, please direct me to where I should go instead, thanks a lot.
I'm wondering if it would be possible to make getting the absolute position of an element easier and faster than using various
measure***
methods?Somewhat like the
View
component''sonLayout
method only for absolute position instead?Ideally the absolute position would be returned before the element actually paints so that animations that are tied to user gestures can be adjusted accordingly without having any frames where the coordinates are incorrect.
A big problem with all of the
measure***
methods is that they will throw an error if they are called a large number of times within a short period of time.Also, these methods become very slow if called multiple times in a row and even at their fastest, they are often not fast enough when working with gestures.
Another problem is that the
onLayout
callback is called only if the givenView's
layout is directly affected by a given style change.If, however (and for example), a parent's margin changes, all of its children will be shifted (in absolute terms) without any way of being notified that their absolute position has changed.
Currently, I can simulate this functionality through the use of a custom
View
that will:1.a. Either relay its absolute position down to its children if it is at the top level of the application;
1.b. Or add its own relative position to the position it receives from higher up the hierarchy and then relay that value to its children;
2. Notify its children of position changes every time its layout changes (which is listened for through the
onLayout
callback).When these custom
Views
are nested, it's possible to find the absolute coordinates of a deeply nested component.However, the major downsides of my implementation are that:
Views
to be changed to my customView
;onLayout
callback is not called until the painting is done (at least that seems to be the case, please correct me if I'm wrong).Would it be possible for React Native to implement this type of functionality internally?
Main points of discussion:
Thanks a lot
Beta Was this translation helpful? Give feedback.
All reactions