Skip to content

Handle link taps #241

Answered by gonzalezreal
fishcharlie asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @fishcharlie,

You can set a custom action to handle links in the openURL environment value.

Markdown {
  """
  Visit the [terms](https://www.example.com) and [conditions](https://apple.com).
  """
}
.environment(\.openURL, OpenURLAction { url in
  // Modify a state, execute an action, etc., based on 'url'
  return .handled
})

The example Demo application uses this technique in the Repository README section to scroll to the corresponding heading when the user taps an anchor link instead of opening it in Safari:

func scrollToMarkdownHeadings(using scrollViewProxy: ScrollViewProxy) -> some

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gonzalezreal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants