moveable icon indicating copy to clipboard operation
moveable copied to clipboard

Scale of container is not taken into account on a Groupable

Open jeroenm2 opened this issue 6 years ago • 11 comments

Environments

  • Framework name: React
  • Framework version: 16.13.1
  • Moveable Component version: 0.22.5 (react-moveable)

Description

When moving a single item in a scaled container (CSS transform: scale(0.5)), the throttleDrag and all the events (onDrag, etc) are adjusted to the scale of the container they're in. Moving a Groupable inside a scaled container, the throttleDrag and events such as onDragGroup delta aren't adjusted to the container its scale.

The difference can be seen in the sample below, when dragging the single item it correctly adjust its position to the mouse. When dragging the group, the group moves slower than the mouse.

https://codesandbox.io/s/happy-margulis-u5x3n?fontsize=14&hidenavigation=1&theme=dark

**Edit: ** updated to latest version of moveables and added rootContainer={document.body}

jeroenm2 avatar Sep 15 '20 15:09 jeroenm2

@jeroenm2

The movement of a single target is correct to move like a group.

So, the prop that added is rootContainer.

Set rootContainer={document.body}

<Moveable
    rootContainer={document.body} />

daybrush avatar Sep 16 '20 18:09 daybrush

@daybrush

Hi, thanks for you response

This seems to resolve the issue but unfortunately not on the latest version, I've updated the sample to the latest version of react-moveables

jeroenm2 avatar Sep 18 '20 08:09 jeroenm2

@jeroenm2

Update [email protected]

It's fixed.

daybrush avatar Sep 18 '20 19:09 daybrush

This code what i got same problem mentioned by @jeroenm2 Help me to find what i did wrong.

I set the transform programatically what i did wrong need to update anything in moveable?


const moveableElement = document.querySelector(".scena-viewport");
const moveable = new Moveable(moveableElement.parentElement, {
    container: moveableElement,
    target: [],
    rootContainer: document.body,
    draggable: true,
    scalable: true,
    rotatable: true,
    snappable: true,
    snapCenter: true,
    dragArea: true,
    roundable: true,
    roundRelative: true,
    origin: true,
    keepRatio: true,
    // throttleDrag: 0,
    // throttleResize: 0,
    // throttleScale: 0,
    // throttleRotate: 0,
    padding: {
        left: 10,
        top: 10,
        right: 10,
        bottom: 10
    },
    verticalGuidelines: [100, 200, 300],
    horizontalGuidelines: [0, 100, 200],
});


const helper = MoveableHelper.create();
moveable
    .on("dragStart", helper.onDragStart)
    .on("drag", helper.onDrag)
    .on("dragEnd", helper.onDragEnd)
    .on("dragGroupStart", helper.onDragGroupStart)
    .on("round", helper.onRound)
    .on("dragGroup", helper.onDragGroup)
    .on("scaleStart", helper.onScaleStart)
    .on("scale", helper.onScale)
    .on("scroll", helper.onScroll)
    .on("scale", helper.onScale)
    .on("scaleGroupStart", helper.onScaleGroupStart)
    .on("scaleGroup", helper.onScaleGroup)
    .on("rotateStart", helper.onRotateStart)
    .on("rotate", helper.onRotate)
    .on("rotateGroupStart", helper.onRotateGroupStart)
    .on("rotateGroup", helper.onRotateGroup)
    .on("transformStartEvent", helper.OnTransformStartEvent);


const selecto = new Selecto({
        container: document.querySelector("body"),
        dragContainer: ".scena-viewer",
        hitRate: 1,
        selectableTargets: ["[data-moveable]"],
        toggleContinueSelect: ["shift"],
        preventDefault:false,
        scrollOptions: {
            container: viewer.getContainer(),
            threshold: 30,
            throttleTime: 30,
            getScrollPosition: ({
                direction
            }) => {
                return [viewer.getScrollLeft(), viewer.getScrollTop()];
            }
        }
    })

Oct-09-2020 16-22-52

sooryaraj avatar Oct 09 '20 07:10 sooryaraj

@sooryaraj

add dragGroupStart event

    .on("dragGroupStart", helper.onDragGroupStart)
    .on("dragGroup", helper.onDragGroup)

daybrush avatar Oct 24 '20 18:10 daybrush

i had both functions but it's not working

sooryaraj avatar Oct 31 '20 05:10 sooryaraj

@sooryaraj

Is there any address that I can test?

daybrush avatar Oct 31 '20 06:10 daybrush

I had change style in transform that's why this problem. when i change transform to other style it's working

sooryaraj avatar Oct 31 '20 07:10 sooryaraj

@sooryaraj

MoveableHelper's start transform is

{
    translate: "0px, 0px",
    scale: "1, 1",
    rotate: "0deg",
}

If you want to use transform, you have to change the helper's start transform.

daybrush avatar Oct 31 '20 07:10 daybrush

my layouts are load from json. when it's loaded and trying to move place it's reset to default transform.

sooryaraj avatar Oct 31 '20 07:10 sooryaraj

if it's possible to set transform for every div and or get style of div and increase/decrease the pixels is little help in some ways

sooryaraj avatar Oct 31 '20 07:10 sooryaraj