Tour of the Composable Architecture: Stacks

Episode #246 • Aug 21, 2023 • Subscriber-Only

We show how to add stack-based navigation to a Composable Architecture application, how to support many different kinds of screens, how to deep link into a navigation stack, and how to write deep tests for how navigation is integrated into the application.

Collection
The Composable Architecture
Tour of the Composable Architecture: Stacks
Locked

Unlock This Episode

Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.

Sign in with GitHub

Introduction

Stephen

Maybe later we can come along and add more tests to this as we add more logic and behavior, or we can make an exhaustive version of this test to make sure we understand how everything in the feature evolves.

We now have yet another feature under our belts, that of seeing the details of a standup and even editing the standup.

Brandon

There’s still a lot more left to implement in the detail screen, but I think the most interesting thing to look at next is how can we navigate to this new detail screen from the standups list. There are actually two ways to go about this, and we’ve explored both ways in past episodes on Point-Free.

  • The first style is what we like to call “tree-based navigation”. This is where you model navigation state with optionals, where nil represents you are not navigated to a feature, a non-nil represents an active navigation. We call this tree-based navigation because the optional states nest forming a tree-like structure. This is the style we have been using so far for our sheets, and it is the style we used when we built the Standups app in vanilla SwiftUI for our “Modern SwiftUI” series of episodes.

  • But then, for drill-down navigation in particular, there’s a second style that we like to call “stack-based navigation”. This is where you model navigation stack as a flat array of states. The act of drilling down to a feature corresponds to appending a value to the stack, and popping a feature corresponds to removing a value from the stack. We re-factored the vanilla SwiftUI Standups app to use stack-based navigation during a live stream a few months ago.

Each style has their pros and cons in turns of power, expressiveness, decoupling, safety, ergonomics, and more. There is no single right answer of which to use.

But, for this application, since we have already shown off tree-based navigation, and we will even have more examples of tree-based navigation coming up soon, we will employ stack-based navigation in order to navigate from the standups list down to the detail screen.

Let’s get started.

Navigating to the detail


References

Downloads

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 62 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing