Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swipe from left to right to go back #8

Open
GaniduAsh opened this issue Feb 27, 2020 · 11 comments
Open

Swipe from left to right to go back #8

GaniduAsh opened this issue Feb 27, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@GaniduAsh
Copy link

Trying to implement a custom navigation as the NavigationView that SwiftUI supports doesnt provide many features,

Notice the one in here is quite impressive. But I noticed this doesnt have the feature to go back to the previous screen by dragging left to right (default go back feature that iOS provides)

Is there a way to get it done ?

@matteopuc
Copy link
Owner

Hi @GaniduAsh , thanks for asking. Unfortunately, at the moment, there's no easy way to get the "swipe to pop" feature with NavigationStackView. Anyway, it's a very interesting feature to work on.

@GaniduAsh
Copy link
Author

Yeah i Noticed it. I think the reason is having your own navigation stack as its hard to maintain all the features that default iOS navigation has, hence i used UIViewControllerRepresentable and the stack which comes with UINavigation.

@divyanshunegi
Copy link

I would like to have that swipe to pop gesture, and would help to implement the same, I am new to SwiftUI coming from Android, but not having this swipe gesture does not feel like iOS to me when implementing this Navigation Stack, apart from that it works smooth and easy to integrate.

@GaniduAsh
Copy link
Author

GaniduAsh commented Mar 16, 2020 via email

@matteopuc matteopuc changed the title Swipe from left to right to go back [Improvement] Swipe from left to right to go back Apr 15, 2020
@matteopuc matteopuc added the enhancement New feature or request label Sep 25, 2020
@matteopuc matteopuc changed the title [Improvement] Swipe from left to right to go back Swipe from left to right to go back Sep 25, 2020
@JuanVeGu-Ionix
Copy link

Is there any solution for this case?

@matteopuc
Copy link
Owner

@JuanVeGu-Ionix Unfortunately not yet.

@JuanVeGu-Ionix
Copy link

@JuanVeGu-Ionix Unfortunately not yet.

To solve this, for the moment, I get the swipe gesture to the right and pass it the pop() method 😬

@ln-12
Copy link

ln-12 commented Jun 10, 2021

@JuanVeGu-Ionix but I think this approach is not the same as the default iOS behavior. I mean you cannot swipe the current screen back and forth, right?

Would also love to see this feature!

@matteopuc
Copy link
Owner

@JuanVeGu-Ionix It would be great if you showed us how you've implemented this feature. We could find a way to integrate your implementation in this project. Thanks.

@ln-12
Copy link

ln-12 commented Jun 10, 2021

It's probably something like this where the pop() method is called in the .right case. But as I said, this does not replicate the iOS gesture which also includes swiping the current screen only partly.

@JuanVeGu-Ionix
Copy link

JuanVeGu-Ionix commented Jun 10, 2021

It's probably something like this where the pop() method is called in the .right case. But as I said, this does not replicate the iOS gesture which also includes swiping the current screen only partly.

Yes, I created a ViewModifier with the next structured

 struct BackToView: ViewModifier {
     let function: () -> Void
 
     func body(content: Content) -> some View {
         content.gesture(DragGesture(minimumDistance: 20, coordinateSpace: .global).onEnded { value in
             let horizontalAmount = value.translation.width as CGFloat
             let verticalAmount = value.translation.height as CGFloat
              
             if abs(horizontalAmount) > abs(verticalAmount) && horizontalAmount > 0 {
                 function()
             }
         })
     }
 }

I know, it's not the right answer, but it works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants