Skip to content

Add popAndPush convenience method (fixes #110)#112

Open
pgovindaraj1 wants to merge 1 commit into
johnpatrickmorgan:mainfrom
pgovindaraj1:feature/pop-and-push
Open

Add popAndPush convenience method (fixes #110)#112
pgovindaraj1 wants to merge 1 commit into
johnpatrickmorgan:mainfrom
pgovindaraj1:feature/pop-and-push

Conversation

@pgovindaraj1
Copy link
Copy Markdown

Picked up issue #110 — the ask was for a way to pop the current screen and push a new one with a proper push animation.

The problem with the current workaround of calling pop() and push() separately is that they fire as two distinct state updates, so SwiftUI only animates the pop and the push transition never happens. Not a great experience when you're trying to replace screen B with screen C and want it to feel like a forward navigation.

The fix is a pop​And​Push(_ screen:) method that performs both operations on the routes array in a single mutation. Since the net change is committed atomically, calculate​Steps(from​:to:) sees it as "pop, then push" and sequences the two animations correctly — you get the full push transition as expected.

Added the method to Array (the core implementation), Flow​Path, and Flow​Navigator to match the pattern of every other convenience method in the library. Also included unit tests covering replacing the top screen in a multi-screen stack and in a single-screen stack.

Adds a  method to  (where Element: RouteProtocol),
, and  that atomically pops the top pushed screen and
pushes a new screen in a single routes mutation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant