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

Get relative coords #2400

Merged
merged 3 commits into from
Sep 27, 2021
Merged

Get relative coords #2400

merged 3 commits into from
Sep 27, 2021

Conversation

jmysliv
Copy link
Member

@jmysliv jmysliv commented Sep 9, 2021

Description

This pr introduces the getRelativeCoords function which enables to convert absolute coordinates to coordinates relative to the given view.

Changes

  • Added getRelativeCoords function
  • Updated docs

@jmysliv jmysliv self-assigned this Sep 9, 2021
@jmysliv jmysliv marked this pull request as ready for review September 10, 2021 09:57
Copy link
Member

@jakub-gonet jakub-gonet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't convert cords - it measures and then converts cords relative to passed arguments. Can we avoid passing absolute x & y or not really?

Copy link
Member

@piaskowyk piaskowyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current solution requires two calls of useAnimatedRef and two calls of measure. I think we can do it better. For example:
We can get the only ref to the current component, call the new version of measureWithParent - new implementation in JSI and calculate cords on the native side. What do you think?

docs/docs/api/miscellaneous/convertCoords.md Outdated Show resolved Hide resolved
src/reanimated2/utils.ts Outdated Show resolved Hide resolved
src/reanimated2/utils.ts Outdated Show resolved Hide resolved
@jmysliv jmysliv marked this pull request as draft September 23, 2021 13:05
@jmysliv jmysliv changed the title Convert coords Get relative coords Sep 27, 2021
@jmysliv
Copy link
Member Author

jmysliv commented Sep 27, 2021

x and y are passed to function because we can get them from gesture handler events. That is the main use case for this function to work with gesture handler.

@jmysliv jmysliv marked this pull request as ready for review September 27, 2021 08:05
@jmysliv jmysliv merged commit 756bd34 into master Sep 27, 2021
@jmysliv jmysliv deleted the @jmysliv/convert-cords branch September 27, 2021 13:28
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.

3 participants