SwiftUI: Adding a Share Button to Navigation title menu using ShareLink and the toolbarTitleMenu modifier

167 Views Asked by At

If you select a file in the Files app on iOS you can tap on the title and get some extra actions, similar to a context menu. I want this in one of my apps and learned about the toolbarTitleMenu modifier. However if I add a ShareLink and tap on it, nothing happens.

Here's an example:

struct ContentView: View {
    var body: some View {
        NavigationStack {
            Text("Example Content")
                .toolbarTitleMenu {
                    ShareLink(item: "test share content") // Here, nothing happens
                }
                .navigationTitle("Test Title")
                .navigationBarTitleDisplayMode(.inline)
            ShareLink(item: "test share content") // Here it works
        }
    }
}

enter image description here

What am I doing wrong?

iOS 17.2.1

0

There are 0 best solutions below