Replies: 10 comments 9 replies
-
Hello. The Counter sample does demonstrate push/pop, including nested back stack. There is also the TodoApp example, which also demonstrates push/pop. Both examples have iOS SwiftUI attached. |
Beta Was this translation helpful? Give feedback.
-
Here is a code snippet from the counter sample:
From what i can see, it's a straight replace, nothing to do with pushing and popping transition. I was half expecting to see a NavigationView being used in swiftui |
Beta Was this translation helpful? Give feedback.
-
@Reedyuk Exactly, the same applicable for any other UI - Jetpack Compose, React, etc. The source of truth for the navigation is Decompose's Router. The Router exposes the navigation state, where there is an active child and a back stack (inactive children). The UI is only concerned about rendering whatever is currently active. So no need to use the The tricky part here is animating transitions between screens. Decompose provides APIs for Jetpack Navigation. But there is nothing out-of-the-box for SwiftUI. This was discussed in #21. The explanation of why it's not possible to include animation APIs for SwiftUI into Decompose can be found in the "old" repo - badoo/Decompose/issues/228. So currently, devs have to do something on their own for animations, something similar to what we have for Jetpack Compose. |
Beta Was this translation helpful? Give feedback.
-
Using a NavigationView can be desirable, especially when working on a SwiftUI project which targets i.e. both iOS, iPadOS and macOS to achieve visual consistency for each platform. And as far as I know, this is possible while using Decompose for Routing. @Reedyuk From my understanding, using a I am currently playing around with Decompose in a personal project and can add a code example if needed once I tested this approach. |
Beta Was this translation helpful? Give feedback.
-
@antoniusnaumann Thanks for the useful information. Please don't hesitate do add any code examples, as it may help other devs. PS: converted this issue to a discussion. |
Beta Was this translation helpful? Give feedback.
-
@antoniusnaumann, nice find on the |
Beta Was this translation helpful? Give feedback.
-
@dkulundzic Yeah, I have found a solution which works for my use case but with a few draw backs and things to be aware of. Currently I don't have much time to upload proper sample code. Here is a snippet similar to how I used it: NavigationLink(
destination: DestinationView(child: router.child as? RootChild.Detail),
isActive: Binding<Bool>(
get: { (router.child as? RootChild.Detail) != nil },
set: { if $0 { root.yourOnOpenDetailViewMethod() } else { root.yourOnCloseDetailViewMethod() } } )
) { /* YOUR LINK LABEL GOES HERE */ } (You can use EmptyView() and trigger root.onOpenDetailView() This snippet assumes that:
*observable object implementation which wraps router state. Note that Root.Child is RootChild in Swift if Root is an interface in Kotlin and Child a nested class declared inside this interface. class Router: ObservableObject {
private let root: Root
@Published
var routing: RouterState<AnyObject, RootChild>
init(_ root: Root) {
self.root = root
self.routing = root.routing.value
self.root.routing.subscribe(observer: observeRouter(state:))
}
private func observeRouter(state: RouterState<AnyObject, RootChild>) {
self.routing = state
}
var child: RootChild { self.routing.activeChild.instance }
deinit {
self.root.routing.unsubscribe(observer: observeRouter(state:))
}
} In this example, the Decompose router is still the only source of truth.
If you need to provide a navigation link for each of your child views, you can change the condition in This is currently only tested for .navigationViewStyle(.stack) (the style used on iOS by default) Most important thing to notice is that the |
Beta Was this translation helpful? Give feedback.
-
For anybody still interested in this question, you should check out SwiftUIs new NavigationStack and NavigationSplitView. In short, they seem to be more flexible, especially in regard to external navigation state management and when it comes to nested navigation. Did not have the time to play with it though. |
Beta Was this translation helpful? Give feedback.
-
Anyone having updates on this, maybe some more code snippets for NavigationView + NavigationLink? |
Beta Was this translation helpful? Give feedback.
-
Hey, check this out #268, maybe it will be useful for somebody. Trying to make native iOS navigation friendly to Decompose using UIKit interop |
Beta Was this translation helpful? Give feedback.
-
The decompose examples are great but they don't demonstrate a typical navigation stack of pushing and popping.
The counter and master detail examples show a 'replace' navigation but doesn't show a push transition - this is probably the most common navigation pattern used within ios/swiftui
Maybe you could take inspiration of this:
https://quickbirdstudios.com/blog/coordinator-pattern-in-swiftui/
Also would be cool to see an example using deeplink navigation, where a user can click an item in the list and this fires off a deeplink to push a view in the navigation.
Beta Was this translation helpful? Give feedback.
All reactions