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

Allow for easing functions on transform #151

Open
TimVanMourik opened this issue Aug 29, 2019 · 4 comments
Open

Allow for easing functions on transform #151

TimVanMourik opened this issue Aug 29, 2019 · 4 comments

Comments

@TimVanMourik
Copy link
Contributor

Feature request

Especially on a 'zoom to fit', it would be pretty neat if you could specificy a transition and a maybe a transition-ease-function.

Specifically, viewer.js would need to be updated:

<g
transform={toSVG(value)}
style={blockChildEvents ? {pointerEvents: "none"} : {}}>

One way to support this is with a transition prop in seconds and maybe an easeFunction prop with option as EASE_IN_OUT, EASE_LINEAR, etc.

I can give it a shot, if you want, if you have name a preferred implementation.

@chrvadala
Copy link
Owner

It seems a good feature, we might introduce a new prop to manually enable this extra feature. I was wondering if using a css transition is enough.
Feel free to start with a PR ;)

@krnlde
Copy link
Contributor

krnlde commented Nov 12, 2019

CSS transition unfortunately add a huge delay. I didn't quite understand why. You don't see any animation until you stop panning / zooming. Also CSS transitions don't feel very natural since the momentum/inertia is not calculated.

Here's the CSS I used:

.pan-zoom-wrapper > svg > g {
  transition: transform .1s ease-out;
}

A class to determine the transforming <g> element would be helpful to better select that.

@kriwi-jtpln
Copy link

kriwi-jtpln commented Apr 18, 2020

I recently ran into the same problem with the css transitions. What worked for me was to disable the transition during manual drag and zoom and use a state to add a class to the pan-zoom-wrapper. Its a hack but does the job.

<ReactSVGPanZoom
              ...
              className={`ReactSVGPanZoom ${renderWithTransition ? 'with-transition' : ''}`}
              onMouseDown={() => setRenderWithTransition(false)}
              onTouchStart={() => setRenderWithTransition(false)}
>

...and enable the class again when using fitToViewer or others

const onFitToViewer = () => {
    setRenderWithTransition(true)
    panZoomRef.current.fitToViewer(ALIGN_CENTER, ALIGN_CENTER)
  }

And big thanks for this great library.

@ulo
Copy link

ulo commented May 14, 2021

Hi, I would love to get a smooth scrolling by using transitions!
However, CSS transitions somehow do not work for me... I guess it is because the transform is an SVG attribute and not CSS.
Moving to CSS transformation, i.e. from

<g 
   transform={toSVG(value)} 
   style={blockChildEvents ? {pointerEvents: "none"} : {}}>

to

<g 
   style={blockChildEvents ? {pointerEvents: "none"} : { transform: toSVG(value), transition: "transform ease 0.1s" }}>

works very nice and very smooth for the zoom!

But does not really work for pan...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants