79114287

Date: 2024-10-22 13:27:55
Score: 0.5
Natty:
Report link

Use Text(.init(["KEY"]("Click here")) and access "KEY" with .environment(.\openURL, _) to make just that text clickable. iOS 15 is required.

Multiline_text_with_action

enum NavigationKey {
    static let welcome = "CLICK_HERE_KEY"
}

struct ContentView: View {
    let actionKey = "[Click here](\(NavigationKey.welcome))"

    var body: some View {
        VStack {
            Text("`Hello, World!` phrase that is written in a multiline text with some extra description. The description is not clickable, just a button. ") +
            Text(.init(actionKey))
                .underline()
        }
        .tint(.pink)
        .padding()
        .environment(\.openURL, OpenURLAction { url in
            if url.description == NavigationKey.welcome {
                print("`Click here` pressed")
            }
            return .discarded
        })
    }
}
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Valerika