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

Add support for dragging components inside scaled Div? #174

Closed
myleschuahiock opened this issue Jul 18, 2016 · 3 comments
Closed

Add support for dragging components inside scaled Div? #174

myleschuahiock opened this issue Jul 18, 2016 · 3 comments

Comments

@myleschuahiock
Copy link

I was having exactly the same problem as this issue here:
#139

I was able to solve it by doing what STRML said by dividing (or multiplying) the deltaX and deltaY with the scale value and adding it as an offset.

    onDrag = (e, data) => {
        const { deltaX, deltaY } = data;

        const id = this.props.id;
        const top = this.props.top;
        const left = this.props.left;
        const widget = {
            id,
            top: top+(deltaY/0.5), //for Zoom Scale(0.5)
            left: left+(deltaX/0.5)
        };  

        this.props.onWidgetChange(id, widget);
    }

While this works, it creates a 'ghosting effect', in which the component is dragged without the scale values applied, before magically being set in place with the proper offset when one lets go of the mouse.

I found another alternative, although it's something one should never do, which is to modify a small snippet of the react-draggable.js.

    function createDraggableData(draggable /*: Draggable*/, coreData /*: DraggableData*/) /*: DraggableData*/ {
      return {
        node: coreData.node,
        x: draggable.state.x + coreData.deltaX/0.5, //<-ZoomScale prop here
        y: draggable.state.y + coreData.deltaY/0.5, //<-ZoomScale prop here
        deltaX: coreData.deltaX,
        deltaY: coreData.deltaY,
        lastX: draggable.state.x,
        lastY: draggable.state.y
      };
    }

Of course, this would introduce breaking changes to the app whenever the module is updated (LOL). But this removes (from my experience) the need for tracking the deltas as STRML said and it also removes the 'ghosting effect' since it directly alters the DraggableData itself.

I was wondering if someone can add support by making a ZoomScale available as component prop. 😄

@houshuang
Copy link

Have the same problem with SVG and viewBox.

@onyxcool
Copy link

Hi guys,

would you be kind to share the solution here? It's still unclear how to support dynamically changeable scale value.

Thank you

@STRML
Copy link
Collaborator

STRML commented Dec 21, 2018

Fixed in #352

@STRML STRML closed this as completed Dec 21, 2018
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

4 participants