Skip to content

How to use SwiftUI .scrollPosition? #371

Discussion options

You must be logged in to vote

Blocks like headings or paragraphs are rendered to SwiftUI views. The ScrollViewProxy scrolls to the first view identified by the given identifier.

Headings are automatically identified by their text:

.id(content.renderPlainText().kebabCased())

I haven't tested this, but it should be possible to add an identifier to each paragraph by overriding the paragraph style in the current theme:

Markdown("...")
   .markdownBlockStyle(\.paragraph) { configuration in
      configuration.label
          .id(/* find some meaningful id here based on configuration.content */)
   }

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@andreivladmatei
Comment options

@gonzalezreal
Comment options

Answer selected by andreivladmatei
@andreivladmatei
Comment options

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