Skip to content

Commit

Permalink
Allow a Parent Coordinator to finish its children
Browse files Browse the repository at this point in the history
  • Loading branch information
EBusch committed Dec 7, 2023
1 parent 9bc6084 commit 2995b19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Float.Core/UX/CoordinatorParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public abstract class CoordinatorParent : Coordinator, ICoordinatorParent
/// </summary>
readonly List<ICoordinator> childCoordinators = new ();

/// <summary>
/// The event args that have been used as we are waiting to finish all the children before closing the parent.
/// </summary>
EventArgs waitingToFinishEventArgs = null;

/// <summary>
/// Gets a value indicating whether this <see cref="CoordinatorParent"/> has children.
/// </summary>
Expand Down Expand Up @@ -98,6 +103,14 @@ public virtual void RemoveChild(ICoordinator coordinator)
}
}

/// <inheritdoc />
public virtual void FinishFamily(EventArgs args)
{
waitingToFinishEventArgs = args;
NavigationContext?.DismissPageAsync(false);
NavigationContext?.Reset(false);
}

/// <summary>
/// Use to determine if this coordinator already contains a certain type of child coordinator.
/// </summary>
Expand Down Expand Up @@ -149,6 +162,12 @@ protected virtual void HandleChildFinish(object sender, EventArgs args)
{
RemoveChild(child);
}

if (!HasChildren && waitingToFinishEventArgs != null)
{
Finish(waitingToFinishEventArgs);
waitingToFinishEventArgs = null;
}
}
}
}
8 changes: 8 additions & 0 deletions Float.Core/UX/ICoordinatorParent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace Float.Core.UX
{
/// <summary>
Expand All @@ -16,5 +18,11 @@ public interface ICoordinatorParent
/// </summary>
/// <param name="coordinator">The coordinator to remove.</param>
void RemoveChild(ICoordinator coordinator);

/// <summary>
/// Ensures all the children can properly finish before the parent finishes.
/// </summary>
/// <param name="args">The event args.</param>
void FinishFamily(EventArgs args);
}
}

0 comments on commit 2995b19

Please sign in to comment.