Skip to content

SwiftUI ScrollView Modifier to handle willBeginDragging, etc.

Notifications You must be signed in to change notification settings

quentinfasquel/ScrollViewEvents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUI ScrollView Events

SwiftUI ScrollView Modifier to handle the following scroll events:

  • willBeginDragging
  • willEndDragging (velocity: CGPoint, contentOffset: inout CGPoint)
  • didEndDragging (decelerate: Bool)
  • willBeginDecelerating
  • didEndDecelerating
  • didEndScrollingAnimation

This is compatible with ScrollViewReader, any custom-reading of the scrollView's contentOffset will work as well.

See example below:

struct ContentView: View {
   var body: some View {
      ScrollView {
            VStack {
                ForEach(0..<10) { _ in
                    RoundedRectangle(cornerRadius: 20)
                        .frame(height: 200)
                        .foregroundColor(Color.gray)
                }
            }
            .padding()
      }
      .scrollWillBeginDragging {

      } willEndDragging: { velocity, contentOffset in

          // contentOffset is 'inout' therefore it can be modified

      } didEndDragging: { decelerate in

      } willBeginDecelerating: {

      } didEndDecelerating: {

      } didEndScrollingAnimation: {

      }
      .edgesIgnoringSafeArea(.all)
   }
}

About

SwiftUI ScrollView Modifier to handle willBeginDragging, etc.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages