I am developing a Quran application using SwiftUI and have a ScrollView with a nested structure like this:
ScrollViewReader > ScrollView > LazyVStack > VStack > AttributedText(View) > TextViewWrapper(UIViewRepresentable) > TextView(UITextView)
I need to determine the first visible Ayah relative to the window as the user scrolls. Currently, I can determine the first Ayah of the first visible page, but I’m having trouble identifying the first visible Ayah within the page itself.
Here’s an example of how I am using GeometryReader:
private func determineVisibleAyahOnPage(on page: Page, in geometry: GeometryProxy) -> AyahDetails? {
let visibleRect = geometry.frame(in: .global)
let ayahs = page.ayahs
if let firstVisibleAyah = ayahs.first {
return AyahDetails(
id: firstVisibleAyah.id,
pageNumber: page.index
)
}
return nil
}
How can I accurately determine the first visible Ayah relative to the window, instead of just the first Ayah of the first visible page? What adjustments can I make to effectively get this information within my SwiftUI view?
Arsen Sh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.