How to use SwiftUI .scrollPosition? #371
Answered
by
gonzalezreal
andreivladmatei
asked this question in
Q&A
-
Hello! Is there a way to use the ScrollView's scrollPosition modifier to jump to a certain paragraph (or element)? Let's say I have a string composed from 10 paragraphs in a scrollview, rendered by MarkdownUI and I want to scroll directly to paragraph 4 (for which I can determine start character index). |
Beta Was this translation helpful? Give feedback.
Answered by
gonzalezreal
Dec 9, 2024
Replies: 1 comment 3 replies
-
I am not sure if this is what you are looking for, but the Demo project shows how to implement heading anchors (ie. links that scroll to a specific heading in a document). |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
swift-markdown-ui/Sources/MarkdownUI/Views/Blocks/HeadingView.swift
Line 21 in a9c7615
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: