nexequ
nexequ

Reputation: 371

SwiftuUI NavigationLink inside touchBar

I'm trying to create NavigationLink in MacBook touchBar with help of SwiftUI. Actually with my piece of code, the button is shown in touchbar, but unfortunately the link doesn't work.

NavigationView {
  .touchBar {
    NavigationLink(destination: BookView()) {
      Text("GoToBook")
    }
  }
}

struct BookView: View {
  var body: some View {
    Text("Hello")
  }
}

Upvotes: 1

Views: 201

Answers (1)

Asperi
Asperi

Reputation: 257693

Try instead with Button in touchBar activating NavigationLink programmatically, like below

@State private var isActive = false

...

// below in body
NavigationView {
  SomeView()      // << your view here 
  .background(NavigationLink(destination: BookView(), isActive: $isActive) { 
                EmptyView() 
              }  // hidden link
  )
  .touchBar {
     Button("GoToBook") { self.isActive.toggle() } // activate link
  }
}

Upvotes: 2

Related Questions