rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
907 stars 95 forks source link

[Question] Is there a way to disable animation when popToRoot ? #47

Closed lmcmz closed 2 years ago

lmcmz commented 2 years ago

Hi, this's a great project ! 🤩 I love to use it. but I got an issue at the moment which might need some help.

For example, my navigation looks like A -> ( B1 -> B2 ) -> C

Once, user from B2 -> C, I need dismiss the whole B coordinator reset the navigation stack to A -> C . Currently, I'm using this code to make it work.

routerA?
.popToRoot()
.route(to: \.c)

But visually, the navigation got pop back animation from B2 -> C instead of standard push forward animation. Is there a way like UIKit that we can disable the animation when popToRoot ?

func popToRootViewController(animated: Bool)
rundfunk47 commented 2 years ago

Hi, sorry for the late reply!

Since stinsen uses SwiftUI under the hood, rather than UIKit, I don't think this is possible unfortunately until SwiftUI adds support for it. One way you could do it using stinsen though might be by using a @Root instead of a @Route for View C. For instance, check how the transition is done between unauthenticated / authenticated in the example app to get a good view of how it can be done.

lmcmz commented 2 years ago

Thanks, @rundfunk47, I have checked the @Root but seems that one even doesn't have any animation in transition. All good, I will keep it for now.

yuriyFedyunkin commented 2 years ago

@rundfunk47 Hi! First of all thx for the great project!

Writing here because seems I have similar question. There is a stack with screens pushed like A1 -> A2 -> A3 -> A4 -> A5

A5(last) is a summary view filled by inputs from previous screens. Tried to implement possibility to go back to selected screen from last to edit some data. Only one way I found is to use focusFirst but it causes unpredictable transition animation and randomly shows 1-2 screen from stack before destination. My assumption that it's due to SwiftUI and isActive binding logic but maybe you could recommend another way.

Thanks