WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Nested Navigation Views

Forums > SwiftUI

Hello,

I am trying to programmatically nest lists within each other so the app transitions like NavigationLinks towards the right, and you can progressively step in and out of lists, but the Navigation Bar keeps expanding (image in the StackOverflow link below). Is there a better way to structure and implement this than NavigationViews?

My data structure is as follows, some children may have nested arrays (I can change this). Eg:

{"News":
  "Business": "Energy", "Industrials", "Finance" : [{"Banking", "Markets"}],
  "Tech": {"Developers", "Startups", "FAANG", "Indie"},
  "Current Affairs"
  }

This StackOverflow discussion says there should only be one NavigationView.

When I used NavigationLinks without declaring it in a NavigationView for a "middle" child views ("Finance" or "Tech"), the back button goes directly to the root view, but I would like for it traverse the prior views too. For example, News -> Business -> Finance -> Banking, and then using the back button to go from Banking -> Finance -> Business -> News rather than Banking -> News

Using .navigationBarHidden(true) on the root and middle views ends up showing 2 or more back buttons as shown in this image

I'm trying to replicate the UI for browsing Spotify's Podcast Categories, but I have subcategories too.

I would really appreciate any help or pointers for this!

1      

Hacking with Swift is sponsored by Emerge

SPONSORED Why are Swift reference types bad for app startup time, and what’s the performance cost of protocol conformances? That’s just a couple of the topics you can learn about on the Emerge blog — written by the app performance experts behind Emerge’s advanced app optimization and monitoring tools, based on their experience of working at companies like Apple, Airbnb, Snap, and Spotify.

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.