NavigationLink in macOS app

Hello,

I am trying to use a NavigationLink in my macOS app. The problem is that the destination View is shown as a "speech bubble" and not as new normal View in the app.

Here is a sample code to replicate the problem...


import SwiftUI

struct MainView: View {

    var body: some View {

        NavigationView {

            Text("Sidebar")

            NavigationLink(destination: SubView()) {

                Text("click me")

            }

        }

    }

}



struct SubView: View {

    var body: some View {

        Text("Hello, World!")

    }

}




// Preview


struct MainView_Previews: PreviewProvider {

    static var previews: some View {

        MainView()

    }

}

If the NavigationLink is in the Sidebar it works as intended (normal new View)

Answered by Jonas54 in 705182022

Hello, i found a nice package to use until there is official support:

https://github.com/lbrndnr/StackNavigationView

Accepted Answer

Hello, i found a nice package to use until there is official support:

https://github.com/lbrndnr/StackNavigationView

The package works but a more elegant way is to just use enums and then switch over those to show different subviews. With .transition this can even be animated.

Can you provide a short code example to explain what you mean by this?

NavigationLink in macOS app
 
 
Q