Skip to content

Commit

Permalink
Adicionado recurso para voltar a tela anterior (GoBack)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocandrade committed Dec 16, 2021
1 parent 3d708ba commit 574146d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Router4D.History.pas
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TRouter4DHistory = class
FInstanteObject : iRouter4DComponent;
FListCacheOrder : TList<String>;
FIndexCache : Integer;
FMaxCacheHistory : Integer;
procedure CreateInstancePersistent( aPath : String);
//procedure CacheKeyNotify(Sender: TObject; const Key: string; Action: TCollectionNotification);
public
Expand Down Expand Up @@ -72,6 +73,7 @@ TRouter4DHistory = class
function InstanteObject : iRouter4DComponent;
function GoBack : String;
function BreadCrumb(aDelimiter: char = '/') : String;
function addCacheHistory(aKey : String) : TRouter4DHistory;
function IndexCache : Integer;
end;

Expand Down Expand Up @@ -225,6 +227,21 @@ function TRouter4DHistory.AddHistory(aKey: String;
FListCache2.Add(aKey, CachePersistent);
end;

function TRouter4DHistory.addCacheHistory(aKey: String): TRouter4DHistory;
var
I: Integer;
begin
Result := Self;
for I := Pred(FListCacheOrder.Count) downto Succ(FIndexCache) do
FListCacheOrder.Delete(I);

if FListCacheOrder.Count > FMaxCacheHistory then
FListCacheOrder.Delete(0);

FListCacheOrder.Add(aKey);
FIndexCache := Pred(FListCacheOrder.Count);
end;

function TRouter4DHistory.AddHistory(aKey: String; aObject: TPersistentClass;
aSBKey : String; isVisible: Boolean): iRouter4DComponent;
var
Expand All @@ -244,6 +261,8 @@ constructor TRouter4DHistory.Create;
begin
FListCache := TObjectDictionary<String, TObject>.Create;
FListCache2 := TDictionary<String, TCachePersistent>.Create;
FListCacheOrder := TList<String>.Create;
FMaxCacheHistory := 10;
{$IFDEF HAS_FMX}
FListCacheContainer := TObjectDictionary<String, TFMXObject>.Create;
{$ELSE}
Expand Down Expand Up @@ -275,6 +294,7 @@ destructor TRouter4DHistory.Destroy;
FListCache.Free;
FListCache2.Free;
FListCacheContainer.Free;
FListCacheOrder.Free;
inherited;
end;

Expand Down
1 change: 1 addition & 0 deletions src/Router4D.Interfaces.pas
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface
function &To ( aPatch : String; aProps : TProps; aKey : String = '') : iRouter4DLink; overload;
function &To ( aPatch : String; aNameContainer : String) : iRouter4DLink; overload;
function IndexLink ( aPatch : String ) : iRouter4DLink;
function GoBack : iRouter4DLink;
end;

iRouter4DRender = interface
Expand Down
26 changes: 26 additions & 0 deletions src/Router4D.Link.pas
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TRouter4DLink = class(TInterfacedObject, iRouter4DLink)
function &To ( aPatch : String) : iRouter4DLink; overload;
function &To ( aPatch : String; aProps : TProps; aKey : String = '') : iRouter4DLink; overload;
function &To ( aPatch : String; aNameContainer : String) : iRouter4DLink; overload;
function GoBack : iRouter4DLink;
function IndexLink ( aPatch : String ) : iRouter4DLink;
end;

Expand Down Expand Up @@ -66,6 +67,7 @@ function TRouter4DLink.&To( aPatch : String; aComponent : TFMXObject ) : iRouter
aComponent
.AddObject(
Router4DHistory
.addCacheHistory(aPatch)
.GetHistory(aPatch)
.Render
);
Expand All @@ -85,6 +87,7 @@ function TRouter4DLink.&To( aPatch : String; aComponent : TPanel ) : iRouter4DLi
aComponent
.AddObject(
Router4DHistory
.addCacheHistory(aPatch)
.GetHistory(aPatch)
.Render
);
Expand All @@ -111,6 +114,7 @@ function TRouter4DLink.&To(aPatch, aNameContainer: String): iRouter4DLink;
aContainer
.AddObject(
Router4DHistory
.addCacheHistory(aPatch)
.GetHistory(aPatch)
.Render
);
Expand All @@ -131,6 +135,26 @@ destructor TRouter4DLink.Destroy;
inherited;
end;

function TRouter4DLink.GoBack : iRouter4DLink;
begin
Result := Self;
{$IFDEF HAS_FMX}
Router4DHistory.MainRouter.RemoveObject(0);
{$ELSE}
Router4DHistory.MainRouter.RemoveObject;
{$ENDIF}
Router4DHistory.InstanteObject.UnRender;
Router4DHistory
.MainRouter
.AddObject(
Router4DHistory
.GetHistory(Router4DHistory.GoBack)
.Render
);

if Assigned(FAnimation) then
FAnimation(Router4DHistory.MainRouter);
end;
function TRouter4DLink.IndexLink(aPatch: String): iRouter4DLink;
begin
Result := Self;
Expand Down Expand Up @@ -166,6 +190,7 @@ function TRouter4DLink.&To(aPatch: String) : iRouter4DLink;
.MainRouter
.AddObject(
Router4DHistory
.addCacheHistory(aPatch)
.GetHistory(aPatch)
.Render
);
Expand All @@ -188,6 +213,7 @@ function TRouter4DLink.&To(aPatch: String; aProps: TProps; aKey : String = '') :
.MainRouter
.AddObject(
Router4DHistory
.addCacheHistory(aPatch)
.GetHistory(aPatch)
.Render
);
Expand Down

0 comments on commit 574146d

Please sign in to comment.