ScrollUI
is a Swift package that provides a powerful way to observe and respond to scroll state changes in SwiftUI. It enables developers to track scrolling behavior and geometry updates efficiently.
- Observe scroll state changes (e.g.,
idle
,interacting
,decelerating
,animating
). - Respond to scroll geometry updates (e.g., content offset changes).
- Provides a modular and reusable way to enhance scroll behavior.
To integrate ScrollUI
into your project, add it as a dependency using Swift Package Manager:
- Open Xcode and go to File > Add Packages...
- Enter the repository URL:
https://github.com/relativejoe/ScrollUI.git
- Choose the latest version and add the package.
You can track the state of a ScrollView
using the onScrollStateChange
modifier:
import ScrollUI
struct ContentView: View {
@State private var isScrolling = false
var body: some View {
ScrollView {
VStack(spacing: 20) {
ForEach(0..<50) { index in
Text("Item \(index)")<
9225
/span>
.frame(maxWidth: .infinity)
.padding()
.background(Color.gray.opacity(0.2))
.cornerRadius(8)
}
}
.padding()
}
.onScrollStateChange { _, newState, _ in
isScrolling = newState.isScrolling
}.scrollViewStyle(.default)
}
}
To track changes in ScrollGeometry
, use onScrollGeometryChange
:
ScrollView {
VStack(spacing: 20) {
ForEach(0..<50) { index in
Text("Item \(index)")
.frame(maxWidth: .infinity)
.padding()
.background(Color.blue.opacity(0.2))
.cornerRadius(8)
}
}
.padding()
}
.onScrollGeometryChange(of: { $0.contentOffset.y > 100 }) { wasBeyond, isBeyond in
print("Scrolled beyond 100: \(isBeyond)")
}.scrollViewStyle(.default)
ScrollUI
provides the following scroll states:
.idle
: The scroll view is not moving..interacting
: The user is actively scrolling..decelerating
: The scroll view is slowing down after user interaction..animating
: The scroll view is in an animated transition.
The documentation is provided by swiftpackageindex.
ScrollUI relies on other packages for specific functionalities:
Contributions are welcome! If you’d like to improve this package, feel free to open an issue or submit a pull request.
For questions or support, reach out via GitHub issues.