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

Controlled PanZoom #21

Open
alextouzel opened this issue Aug 17, 2019 · 1 comment
Open

Controlled PanZoom #21

alextouzel opened this issue Aug 17, 2019 · 1 comment

Comments

@alextouzel
Copy link

alextouzel commented Aug 17, 2019

Hi there! I'm incorporating PanZoom in an application and I have a use case where it would be useful to have a controlled PanZoom component. I would like to be able to absolutely set the position and the scale when some props are updated. It seems to me like this feature could be useful for many use cases.

One way to achieve it right now is to use the zoomAbs method that is actually not documented in the readme (is this on purpose?) and also never used in the PanZoom component itself.

It works fine with this method but I would have expected one of the following:

  1. Document the zoomAbs method in the readme.
  2. Add some props to achieve this. Something like initialPosition and initialScale.

EDIT: You cannot absolutely set the position using zoomAbs. You can only set the zoom. So I don't see any way to control the position except using ref.setState({x: 10, y: 10}) but this seems like a terrible pattern to me.

@n1ru4l
Copy link
Contributor

n1ru4l commented Oct 14, 2019

As you told this could be achieved via props. However, depending on how often those changes (e.g. you want to sync em over the network in realtime, etc.) the performance could become very bad.

A more performant solution could be a two-way data binding with the usage of a library like Animated:

https://github.com/animatedjs/animated
https://www.youtube.com/watch?v=xtqUJVqpKNo

Example:

https://codesandbox.io/s/great-mayer-2is9v?from-embed

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

No branches or pull requests

2 participants