3
ToolbarItem(placement: .bottomBar) {
    NavigationLink(
        destination: NoteView(note: Note())
    ) {
        Image(systemName: "square.and.pencil")
    }
}

This code is not working as expected: no action is being performed when I tap on the image.

Any idea why or way around?

pawello2222
  • 46,897
  • 22
  • 145
  • 209
Tulleb
  • 8,919
  • 8
  • 27
  • 55

2 Answers2

4

A possible workaround is to move the NavigationLink outside the toolbar and activate with the isActive parameter:

struct ContentView: View {
    @State var linkActive = false

    var body: some View {
        NavigationView {
            Text("Test")
                .background(
                    NavigationLink(destination: Text("Destination"), isActive: $linkActive) {}
                )
                .toolbar {
                    ToolbarItem(placement: .bottomBar) {
                        Button(action: {
                            linkActive = true
                        }) {
                            Image(systemName: "square.and.pencil")
                        }
                    }
                }
        }
    }
}
pawello2222
  • 46,897
  • 22
  • 145
  • 209
0

We can work with NavigationLink to reach this.

             .toolbar {
                ToolbarItem {
                    NavigationLink {
                        YourSettingsView()
                    } label: {
                        Label("Settings", systemImage: "gear")
                    }
                }
BollMose
  • 3,002
  • 4
  • 32
  • 41