unit PullRefresh;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Controls.Presentation, FMX.StdCtrls,
FMX.ListBox, FMX.Layouts, FMX.Ani;
Type
TSensibility = (sLow, sMedium, sHigh, sVeryHigh);
type
TPullRefresh =
Class(TComponent)
constructor create(AOwner: TComponent);
virtual;
destructor Destroy;
override;
function Refresh: Boolean;
private
procedure MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure SetListBox(lBox: TListBox);
procedure SetSensibility(fsen: TSensibility);
var
fBox: TListBox;
fButton: TButton;
Sen: Single;
PosNow: Single;
Sensy: TSensibility;
published
property ListBox: TListBox
read fBox
write SetListBox
default nil;
property Sensibility: TSensibility
read Sensy
write SetSensibility
default sMedium;
End;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Extra', [TPullRefresh]);
end;
destructor TPullRefresh.Destroy;
begin
inherited Destroy;
end;
procedure TPullRefresh.SetSensibility(fsen: TSensibility);
begin
// ----------------Set Sensibility----------------------------
case fsen
of
sLow:
Sen := 0.3;
sMedium:
Sen := 0.5;
sHigh:
Sen := 0.6;
sVeryHigh:
Sen := 0.7;
end;
end;
procedure TPullRefresh.SetListBox(lBox: TListBox);
begin
fBox := lBox
end;
function TPullRefresh.Refresh: Boolean;
begin
if fButton.Position.Y >= 2
then
Result := True
else
Result := False;
fButton.AnimateFloat('
Position.Y', -80, 0.2, TAnimationType.
in, TInterpolationType.Exponential);
end;
constructor TPullRefresh.create(AOwner: TComponent);
begin
inherited create(AOwner);
// ----------------Button create----------------------------
fButton := TButton.create(fBox);
fButton.
Name := '
Refresh';
fButton.StyleLookup := '
refreshtoolbutton';
fButton.Align := TAlignLayout.Horizontal;
fButton.CanFocus := False;
fButton.HitTest := False;
fButton.Position.Y := -80;
fButton.Parent := fBox;
fButton.Scale.Y := 1.5;
fButton.Scale.X := 1.5;
// ----------------Set Procedures----------------------------
fBox.OnMouseDown := MouseDown;
fBox.OnMouseMove := MouseMove;
end;
procedure TPullRefresh.MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
if fBox.Content.Position.Y >= -2
then
PosNow := Y;
fButton.Position.Y := -80;
end;
procedure TPullRefresh.MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
var
P: Single;
begin
if fBox.Content.Position.Y >= -2
then
begin
P := (Y - PosNow) * Sen - fButton.Height;
fButton.Position.Y := P;
fButton.RotationAngle := P * 3;
fButton.Opacity := P * 0.04
end;
end;
end.