InfiniteScrollView
is a customizable SwiftUI component that provides an infinite scrolling interface, enabling users to load more items dynamically. This package is perfect for applications that require pagination or continuous data loading, with built-in support for loading states, empty views, and refresh actions.
- Dynamic Loading: Automatically loads more items as the user scrolls.
- Loading States: Displays a loading indicator when fetching data.
- Empty View Support: Shows a customizable view when no items are available.
- Refresh Functionality: Allows users to refresh the list by pulling down.
- Lightweight & Easy to Use: Simple API and flexible customization options.
You can add InfiniteScrollView
to your project using Swift Package Manager. Add the following dependency to your Package.swift
:
dependencies: [
.package(url: "https://github.com/smbrmoyo/InfiniteScrollView.git", from: "1.0.0")
]
- Open your project in Xcode.
- Navigate to File > Add Packages.
- Enter the URL of the repository: https://github.com//.
- Choose the version you want to install and click Add Package.
Here's a simple example of how to use InfiniteScrollView in your SwiftUI project:
import SwiftUI
import InfiniteScrollViewPackage
struct ContentView: View {
@State private var items: [YourItemType] = []
@State private var canLoadMore: Bool = true
@State private var uiState: UIState = .idle
var body: some View {
InfiniteScrollView(
items: items,
canLoadMore: $canLoadMore,
uiState: uiState,
loadMoreItems: loadMore,
refresh: refresh,
emptyView: {
Text("No items available")
},
row: { item in
Text(item.title)
}
)
}
private func loadMore() async {
// Load more items logic
}
private func refresh() async {
// Refresh items logic
}
}
- items: An array of items to display.
- canLoadMore: A binding that indicates whether more items can be loaded.
- uiState: The current UI state (idle, loading, etc.).
- loadMoreItems: A closure that loads more items asynchronously.
- refresh: A closure that refreshes the item list asynchronously.
- emptyView: A view displayed when there are no items.
- row: A closure to define how each item should be displayed.
Contributions are welcome! Please feel free to submit a pull request or open an issue.
Fork the repository. Create your feature branch: git checkout -b feature/MyFeature. Commit your changes: git commit -m 'Add some feature'. Push to the branch: git push origin feature/MyFeature. Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.