Skip to content

Add left-to-right push animation support#1

Open
kartikeyajar wants to merge 2 commits intoflowstacks-0.3.5from
left-to-right-push-animation
Open

Add left-to-right push animation support#1
kartikeyajar wants to merge 2 commits intoflowstacks-0.3.5from
left-to-right-push-animation

Conversation

@kartikeyajar
Copy link
Copy Markdown
Collaborator

Summary

  • Adds new .pushLeftToRight navigation style for reverse push animations
  • Fixes animation bleeding between normal and left-to-right pushes
  • Implements separate push/pop animation flags to respect original push direction

Changes

New Navigation Style

  • Added .pushLeftToRight case to Route enum and RouteStyle
  • Provides opposite animation direction from standard iOS right-to-left push
  • Works seamlessly with existing push/sheet/cover navigation styles

Implementation Details

  • Created NavigationControllerDelegate.swift with custom UIViewControllerAnimatedTransitioning
  • Added NavigationControllerModifier.swift for SwiftUI integration
  • Each screen now tracks its push direction independently via separate flags
  • iOS-only feature (wrapped in #if os(iOS) directives)

Usage

  • routes.pushLeftToRight(screen) - Push with left-to-right animation
  • navigator.pushLeftToRight(screen) - Convenience method on FlowNavigator
  • Fully backward compatible with existing navigation methods

…ot respecting push direction Split single animation flag into separate push/pop flags so each screen remembers how it was pushed.
extension View {
func customNavigationTransition(useLeftToRightForPush: Bool, useLeftToRightForPop: Bool) -> some View {
#if os(iOS)
let delegate = CustomNavigationControllerDelegate()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we create CustomNavigationControllerDelegate() on every function call, or we should use a singleton or something?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this implementation, every view rendering it will create new instance of CustomNavigationControllerDelegate. View rendering will happen on view initialisation, view updates, state update, Animation.
Singleton will not be thread safe in this case.
Recommended to create a container which holds with delegate and allow that container to access the NavigationControllerAccessor

if let navigationController = uiViewController.navigationController {
navigationController.delegate = delegate
} else {
DispatchQueue.main.async {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why DispatchQueue.main.async here?

}

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 0.35
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of hardcoding this value, please use it from a var, may that can be passed from outside.

@kartikeyajar kartikeyajar force-pushed the left-to-right-push-animation branch from 665ce57 to aa4e1d4 Compare April 17, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants