react-svg-pan-zoom icon indicating copy to clipboard operation
react-svg-pan-zoom copied to clipboard

use hooks?

Open sibelius opened this issue 5 years ago • 9 comments

hooks would make the code simpler

sibelius avatar Mar 01 '19 02:03 sibelius

I know, but to integrate hooks I have to rewrite a lot of code, moreover they are only available since React 16.8 and I don't want developers to upgrade to a new version. At the moment I don't have any plan, but let's see it in future.

https://reactjs.org/docs/hooks-intro.html#gradual-adoption-strategy

chrvadala avatar Mar 01 '19 13:03 chrvadala

it would be cool to provide some hooks like

useZoom, usePan and so on, that would handle mouse events

does this integrate well with d3 zoom behavior?

sibelius avatar Mar 01 '19 14:03 sibelius

It sounds interesting.... Do you think that add this hooks might require changes into the library itself or can we release it as a standalone library?

I was thinking about a new npm package called react-svg-pan-zoom-hooks... Are you interested to develop it?

chrvadala avatar Mar 01 '19 14:03 chrvadala

it could just be exported in this package

it still share a lot of existing code already

import { useZoom } from 'react-svg-pan-zoom'

later on we can migrate the existing code to use this hooks

what do you think?

sibelius avatar Mar 01 '19 14:03 sibelius

Since this is quite experimental, we could start from a standalone package and then move these features into the main. Are you available to work on it?

chrvadala avatar Mar 04 '19 16:03 chrvadala

We can get inspiration from here https://github.com/sandiiarov/use-events

chrvadala avatar Mar 05 '19 09:03 chrvadala

having a hook, we can reuse the same logic on react native

check this https://github.com/garblovians/react-native-svg-pan-zoom

sibelius avatar Mar 14 '19 15:03 sibelius

I see. Since add hooks supports might require times (for dev and testing), I was trying to figure out a way to do this without hooks feature.

I think that, to create a react native component, you can reuse all the exported features. Look at this file https://github.com/chrvadala/react-svg-pan-zoom/blob/master/src/viewer.js The whole logic is out of this component and can be imported, using react-svg-pan-zoom as dependency https://github.com/chrvadala/react-svg-pan-zoom/blob/master/src/index.js

Just a note: I see that ./features/interactions.js and ./features/interactions-touch.js aren't exported. I'm going to fix them adding them to the export file.

Thought?

chrvadala avatar Mar 15 '19 17:03 chrvadala

See WIP PR #152

I started rewriting the main compoments and I'll further investigate the useZoom and usePan idea :)

TimVanMourik avatar Sep 10 '19 21:09 TimVanMourik