Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Get current item in LazyVstack inside scrollview when scroll ends

$
0
0

I want to print the currently displayed item in LazyVStack which is inside scrollview with paging enabled.

i have tried printing in onAppear of VerseViewThe 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


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>