0

I have some larger text, and it basically should look like this:

enter image description here

This bold part of text should be NavigationLink.

I tried with HStack, and all simple solutions, but it won't work. Is it maybe some library, or anything to make this simple to do. Sure, you can answer me the more complicated solution, there is no problem, but I would prefer some easier way to do this.

burnsi
  • 6,194
  • 13
  • 17
  • 27

1 Answers1

2

You can do this using Markdown Text, a custom url scheme, and .onOpenUrl modifier:

struct ContentView: View {
 
    let text1 = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin imperdiet ipsum purus, sit amet mollis nunc "
    let text2 = "bibendum eget."
    let text3 = " Nulla suscipit mauris non diam varius sagittis. Ut feugiat imperdiet bibendum. Vestibulum dui quam, bibendum sit amet imperdiet sit amet, dapibus sit amet mauris."
    
    @State private var path = NavigationPath()
    
    var body: some View {
        NavigationStack(path: $path) {
            VStack {
                Text(text1) +
                Text("[\(text2)](myappurl://action)").bold() +
                Text(text3)
            }
            .padding()
            .onOpenURL { url in
                path.append(1)
            }
            .navigationTitle("Main")
            .navigationDestination(for: Int.self) { value in
                Text(value, format: .number)
            }
        }
    }
}

See my answer here for full details on how to configure the url scheme.

enter image description here

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160