unit uMain;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  DPF.iOS.BaseControl, DPF.iOS.UIButton, DPF.iOS.UILabel, DPF.iOS.UIView,
  DPF.iOS.UIToolbar, DPF.iOS.UIImageView;

type
  TFPanGestureRecognizer = class( TForm )
    DPFUIView1: TDPFUIView;
    DPFUIView2: TDPFUIView;
    DPFToolbar1: TDPFToolbar;
    DPFImageView1: TDPFImageView;
    procedure FormShow( Sender: TObject );
    procedure DPFUIView2PanGestureRecognizer( Sender: TObject; CurPosition, Translation, Center, Velocity: DPFNSPoint; State: TDPFPanGestureRecognizeState; var MoveCenter: Boolean );
    procedure DPFToolbar1BarItems0Click( Sender: TObject );
  private
    { Private declarations }
  protected
    procedure PaintRects( const UpdateRects: array of TRectF ); override;
  public
    { Public declarations }
  end;

var
  FPanGestureRecognizer: TFPanGestureRecognizer;

implementation

{$R *.fmx}

procedure TFPanGestureRecognizer.DPFToolbar1BarItems0Click( Sender: TObject );
begin
  if ( DPFUIView2.Position.x > width / 2 ) then
  begin
    DPFUIView2.SetAnimationTransition( DPFUIView2.Position.X, 0, DPFUIView2.Position.y, DPFUIView2.Position.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 );
  end
  else
  begin
    DPFUIView2.SetAnimationTransition( DPFUIView2.Position.X, Width - 50, DPFUIView2.Position.y, DPFUIView2.Position.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 );
  end
end;

procedure TFPanGestureRecognizer.DPFUIView2PanGestureRecognizer( Sender: TObject; CurPosition, Translation, Center, Velocity: DPFNSPoint; State: TDPFPanGestureRecognizeState; var MoveCenter: Boolean );
var
  originalCenter: DPFNSPoint;
begin

  if State = grsBegan then
  begin
    originalCenter := center;

  end
  else if ( state = grsChanged ) then
  begin
    MoveCenter := true;
    // CGPoint translation = [recognizer translationInView:self.view];

    // recognizer.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y);
  end
  else if ( state = grsEnded ) or ( state = grsCancelled ) or ( state = grsFailed ) then
  begin
    if ( Velocity.x > 0 ) and ( CurPosition.x > 50 ) then
      DPFUIView2.SetAnimationTransition( CurPosition.X, Width - 50, CurPosition.y, CurPosition.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 )
    else if ( Velocity.x > 0 ) and ( CurPosition.x < 50 ) then
      DPFUIView2.SetAnimationTransition( CurPosition.X, 0, CurPosition.y, CurPosition.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 )
    else if ( Velocity.x < 0 ) and ( CurPosition.x > 50 ) then
      DPFUIView2.SetAnimationTransition( CurPosition.X, 0, CurPosition.y, CurPosition.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 )
    else if ( Velocity.x < 0 ) and ( CurPosition.x > Width - 100 ) then
      DPFUIView2.SetAnimationTransition( CurPosition.X, Width - 50, CurPosition.y, CurPosition.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 )
    else
      DPFUIView2.SetAnimationTransition( CurPosition.X, 0, CurPosition.y, CurPosition.y, DPFUIView2.Width, DPFUIView2.Width, DPFUIView2.Height, DPFUIView2.Height, 0.25 )

  end
  // MoveCenter := true;
end;

procedure TFPanGestureRecognizer.FormShow( Sender: TObject );
begin
  DPFUIView2.SetBounds( 0, 0, Width, Height );
  Application.Terminate;
end;

procedure TFPanGestureRecognizer.PaintRects( const UpdateRects: array of TRectF );
begin

  { }

end;

end.
