Panning (how to get the updated left/top of the dropped image)


#1

Hi,
I’m trying to implement a drag and drop. I got the below code by Googling, and it worked perfectly for dragging an image. My question is when releasing (dropping) the image, args.state === 3, I need to know the updated left/top of the image, but what I’m getting is always the same, no matter where I drop the image. The image is inside an AbsoluteLayout container. What am I missing?
THANKS!

 private prevDeltaX:number;
 private prevDeltaY:number;

  onPan(args: PanGestureEventData) {
    if (args.state === 1) // down
      {
        this.prevDeltaX = 0;
        this.prevDeltaY = 0;
      }
      else if (args.state === 2) // panning
      {
        args.view.translateX += args.deltaX - this.prevDeltaX;
        args.view.translateY += args.deltaY - this.prevDeltaY;
    
        this.prevDeltaX = args.deltaX;
        this.prevDeltaY = args.deltaY;
      }
      else if (args.state === 3) // up
      {
        //TODO: handle drop
        **console.log(args.view.top); //always 404???**
      }
  }

#2

Did you try getLocationRelativeTo?


#3

Yes it worked. Thanks!

        let container = args.view.parent.getViewById('container') as View;
        let pt:Point = args.view.getLocationRelativeTo(container);
        console.log(pt.x);
        console.log(pt.y);