I want to print the currently displayed item in LazyVStack which is inside scrollview with paging enabled.
i have tried printing in onAppear of VerseView The issues with printing inside onAppear are-
- onAppear gets called twice or more sometimes.
- onAppear doesnt get triggered when i just begin to scroll and cancels the scroll.
I SIMPLY WANT TO PRINT THE CURRENT ITEM WHICH IS DISPLAYED IN SCREEN WHENEVER I RELEASES THE SCROLL.
CODE IS :
struct SwippableView: View {
var data: [VerseModel]
var body: some View {
ScrollView(.vertical) {
LazyVStack(spacing: 0) {
ForEach(data, id: \.id) { verse in
VerseView(verse: verse)
.padding(0)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}.scrollTargetLayout()
}
.ignoresSafeArea()
.scrollTargetBehavior(.paging)
.scrollIndicators(.never)
}
}
Additional info: Each view inside LazyVStack fills the entire screen
.scrollPosition(id....), see: developer.apple.com/documentation/swiftui/view/…