how to know when a scrollview in SwiftUI is being scrolled?

I am trying to add arrows to a scrollView in SwiftUI. When the app is open or all the way to the left side there is an arrow pointing to the right:

and the opposite when it reaches the right side:

What I am struggling with is how to have both arrows to appear when the person is scrolling.

I am able to get the arrows to appear when I am between point A and B, but when I reach either end the double arrows remains, instead of the single arrow I want when it reaches either end of the scrollView. So what I want is and arrow showing which direction the scroll can do, so when it can't scroll to anyone side anymore, like when it reaches the far left or right, there is only one arrow, but when the scrolling can be either direction there are two arrows, that disappear when it reaches either end. I am able to get the arrows working when they reach either side, but I was hoping for the double arrows when it is needed. I think there must be something to determine when scrolling is being done. I have looked at a few sources to get to where I am now, and things I have tried before, to no avail:

Video: https://www.youtube.com/watch?v=h47UkS8pLA8

https://developer.apple.com/forums/thread/650312

Interaction of DragGesture and ScrollView in SwiftUI

In SwiftUI, where are the control events, i.e. scrollViewDidScroll to detect the bottom of list data

This is the main View:

This is the view for the arrows:

If there is anything else I can answer please ask, thank you.

Replies

You could measure the offset of the ScrollView content and store it using Preference Keys. Then if offset > 0, it means the user scrolled. So, if offset > 0 && leadingBool == false means the ScrollView is partially scrolled. So you can do whatever you need. PS in reality I guess you will scroll x to the negative, so it will be < 0.

@Cardu6lis I am not sure if that will work, because when you want to scroll to the left after reaching the far right side, the bool will still be true, so it will just show one arrow.