A set of SwiftUI custom modifiers to make the ScrollView snappable.
The goal of this library is to provide an easy way to implement Views such as carousels and slideshows.
Demo
Requirements
iOS 14.0+
Swift 5.3+
Note
Snappable includes the copied code from Introspect for SwiftUI (#17) due to detect the behavior of scrolling from UIScrollView.So this library would be fragile on iOS or SwiftUI updates.
Snappable
A set of SwiftUI custom modifiers to make the ScrollView snappable.
The goal of this library is to provide an easy way to implement Views such as carousels and slideshows.
Demo
Requirements
Note
Snappable includes the copied code from Introspect for SwiftUI (#17) due to detect the behavior of scrolling from UIScrollView. So this library would be fragile on iOS or SwiftUI updates.
Installation
Swift Package Manager
CocoaPods
Usage
Basic
.snapID(_:)
modifier to items in ScrollViewsnapID
applies .id(_:) modifier internally.snappable(_:mode:)
modifier to ScrollViewOptions
Alignment
The snap anchor point can be set as an option.
Available alignment parameters are below:
.top
.leading
.center
.trailing
.bottom
SnapMode
You can determine the snap timing after the end of the drag with following parameters.
.afterScrolling
.immediately
Both parameters are set together with scrolling deceleration rate.