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

Question: How to change transition of the view which was already pushed into nav stack #32

Closed
cuhte3 opened this issue Oct 7, 2020 · 2 comments

Comments

@cuhte3
Copy link

cuhte3 commented Oct 7, 2020

First of all thanks for the great library! Am trying to figure out how to achieve different transitions on a view which was already pushed to the stack. Let's say i pushed a view with a default transition and on the view there are two buttons: one is leading to the next screen with a default transition but the other is showing a view over the current like a popover. Because the host view is already pushed to the stack with defined push and pop transition i cannot see a way how to modify it for my needs. Any ideas are appreciated! Thanks!

@matteopuc
Copy link
Owner

Hi @cuhte3 I'd really like to get what you need, I often need it myself. This question is kind of related to this other one #17 , so I'll close this to keep the conversation on a single thread. Long story short: at the moment what you're asking is not possible. The navigation stack just allows you to specify a transition animation during its creation. We need to find a way to change the navigation stack to include this feature. It seems easy and I tried it, but unfortunately I failed and I haven't had time to try again with other possible solutions. Of course, any help on this would be really really appreciated. Let's keep talking about this on the other issue I linked here above and thank you.

@cuhte3
Copy link
Author

cuhte3 commented Jan 27, 2021

Hi @matteopuc, in iOS14 now we have a .fullScreenCover modifier which seems a suitable solution for the issue. I've extended NavigationType adding a .present as well as extending NavigationStack with present function to support the new type of navigation. Here is my modified NavigationStackView body as an example:

     public var body: some View {
	let showRoot = navigationStack.currentView == nil
	let navigationType = navigationStack.navigationType
	let currentView = navigationStack.currentView
	let currentViewPushTransition = currentView?.pushTransition ?? defaultTransitions.push
	let currentViewPopTransition = currentView?.popTransition ?? defaultTransitions.pop
	
	return Group {
		if showRoot {
			rootView
				.id(rootViewID)
				.transition(navigationType == .push ? rootViewtransitions.push : rootViewtransitions.pop)
		} else {
			currentView?.wrappedElement
				.id(currentView!.id)
				.transition(navigationType == .push ? currentViewPushTransition : currentViewPopTransition)
				.if(modalViewIsPresenting) {
					$0.fullScreenCover(isPresented: $modalViewIsPresenting, content: {
						navigationStack.presentedView?.wrappedElement
					})
				}
		}
	}
	.environmentObject(navigationStack)
	.onReceive(navigationStack.$navigationType) { navType in
		modalViewIsPresenting = navType == .present
	}
}

this works however somehow transition of the modal view isn't animated. Any ideas of how to make the transition animatable?

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

No branches or pull requests

2 participants