https://github.com/anbalagand/carouselview
This library simplifies the implementation of carousel-style interfaces in SwiftUI applications while maintaining smooth, infinite scrolling functionality.
https://github.com/anbalagand/carouselview
carousel carouselview infinite-scroll ios slide slider slideview spm swift swiftui tabvi tabview-swiftui
Last synced: 6 months ago
JSON representation
This library simplifies the implementation of carousel-style interfaces in SwiftUI applications while maintaining smooth, infinite scrolling functionality.
- Host: GitHub
- URL: https://github.com/anbalagand/carouselview
- Owner: AnbalaganD
- License: mit
- Created: 2024-11-24T16:56:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-02T10:23:40.000Z (over 1 year ago)
- Last Synced: 2025-05-08T07:52:28.045Z (about 1 year ago)
- Topics: carousel, carouselview, infinite-scroll, ios, slide, slider, slideview, spm, swift, swiftui, tabvi, tabview-swiftui
- Language: Swift
- Homepage:
- Size: 662 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This library simplifies the implementation of carousel-style interfaces in SwiftUI applications while maintaining smooth, infinite scrolling functionality.

## Features
βΎοΈ Infinite scrolling support
π― Selected item tracking
π Configurable item spacing
π Current index monitoring
π Auto-scroll with customizable interval
βΈοΈ Auto-pause on user interaction
β‘οΈ Native SwiftUI implementation
## Swift Package manager (SPM)
CarouselView is available through [SPM](https://swiftpackageindex.com/AnbalaganD/CarouselView). Use below URL to add as a dependency
```swift
dependencies: [
.package(url: "https://github.com/AnbalaganD/CarouselView", .upToNextMajor(from: "1.1.2"))
]
```
## Usage
### Basic Usage
```swift
import CarouselView
struct ContentView: View {
private let items: [String] = ["One", "Two", "Three", "Four", "Five"]
@State private var selectedIndex: Int = 2
var body: some View {
CarouselView(
items,
spacing: 10.0,
selectedIndex: $selectedIndex
) { item in
Text(item)
.frame(maxWidth: .infinity)
.frame(height: 200)
.background(Color.gray)
.clipShape(RoundedRectangle(cornerSize: .init(width: 5, height: 5)))
}
}
}
```
### Auto-scroll
```swift
struct ContentView: View {
private let items: [String] = ["One", "Two", "Three", "Four", "Five"]
@State private var selectedIndex: Int = 0
@State private var autoScrollEnabled: Bool = true
var body: some View {
CarouselView(
items,
spacing: 10.0,
selectedIndex: $selectedIndex
) { item in
Text(item)
.frame(maxWidth: .infinity)
.frame(height: 200)
.background(Color.blue)
.clipShape(RoundedRectangle(cornerSize: .init(width: 5, height: 5)))
}
.autoscroll($autoScrollEnabled, interval: 3.0)
}
}
```
Auto-scroll automatically pauses when the user interacts with the carousel and resumes when interaction ends.
### Observing User Interaction
```swift
struct ContentView: View {
private let items: [String] = ["One", "Two", "Three", "Four", "Five"]
@State private var selectedIndex: Int = 0
var body: some View {
CarouselView(
items,
spacing: 10.0,
selectedIndex: $selectedIndex
) { item in
Text(item)
.frame(maxWidth: .infinity)
.frame(height: 200)
.background(Color.blue)
.clipShape(RoundedRectangle(cornerSize: .init(width: 5, height: 5)))
}
.onCarouselInteraction { isInteracting in
print("User is interacting: \(isInteracting)")
}
}
}
```
## Author
[Anbalagan D](mailto:anbu94p@gmail.com)
## License
CarouselView is available under the MIT license. See the [LICENSE](LICENSE) file for more info.