0

I would like to know if there's any easy way to detect which image or struct of a carousel is actually visible on screen. I tried something like this but it seems to consider that my struct actually appears on the screen even when it's not visible:

ScrollView(.horizontal, showsIndicators: false) {
    HStack {
        myFirstStruct().onAppear {
            print("Struct 1 shown")
        }.frame(width: UIScreen.main.bounds.width)

        mySecondStruct().onAppear {
            print("Struct 2 shown")
        }.frame(width: UIScreen.main.bounds.width)
    }
}
pawello2222
  • 46,897
  • 22
  • 145
  • 209
Hugo R
  • 25
  • 1
  • 9
  • 1
    Next can be helpful https://stackoverflow.com/a/60643762/12299030 and https://stackoverflow.com/a/62588295/12299030. – Asperi Jan 05 '21 at 14:48
  • Thanks @Asperi! I didn't find the LazyHStack solution during my previous researches. It works very well. – Hugo R Jan 05 '21 at 15:12

0 Answers0