In addition to scroll related view modifiers covered in the previous blog post, there is another one for detecting scroll view phases aka the state of the scrolling. The new view modifier is called onScrollPhaseChange(_:) and has three arguments in the change closure: old phase, new phase and a context.
ScrollPhase is an enum with the following values:
- animating – animating the content offset
- decelerating – user interaction stopped and scroll velocity is decelerating
- idle – no scrolling
- interacting – user is interacting
- tracking – potential user initiated scroll event is going to happen
The enum has a convenience property of isScrolling which is true when the phase is not idle.
ScrollPhaseChangeContext captures additional information about the scroll state, and it is the third argument of the closure. The type gives access to the current ScrollGeometry and the velocity of the scroll view.
Here is an example of a scroll view which has the new view modifier attached.
If this was helpful, please let me know on Mastodon@toomasvahter or Twitter @toomasvahter. Feel free to subscribe to RSS feed. Thank you for reading.