UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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!

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.