Swiftpack.co - Package - crelies/AdvancedList


Swift5 Platform License

This package provides a wrapper view around the SwiftUI List view which adds pagination (through my ListPagination package) and an empty, error and loading state including a corresponding view.


Add this Swift package in Xcode using its Github repository url. (File > Swift Packages > Add Package Dependency...)

How to use

You control the view through an instance of ListService. The service manages the current state and the items of the list. Use it to append, update or remove items and to modify the state of the list. The view listens to the service and updates itself if needed.


The Pagination is implemented as a class (conforming to ObservableObject) so the AdvancedList can observe it. It has three different states: error, idle and loading. If the state of the Pagination changes the AdvancedList updates itself to show or hide the state related view (ErrorView for state .error(Error) or LoadingView for state .loading, .idle will display nothing). Update the state if you start loading (.loading), stop loading ( .idle) or if an error occurred (.error(Error)) so the AdvancedList can render the appropriate view.

If you want to use pagination you can choose between the lastItemPagination and the thresholdItemPagination. Both concepts are described here. Just pass .lastItemPagination or .thresholdItemPagination including the required parameters to the AdvancedList initializer.

Both pagination types require

  • an ErrorView and a LoadingView (ViewBuilder)
  • a block (shouldLoadNextPage) which is called if the last or threshold item appeared and
  • the initial state (AdvancedListPaginationState) of the pagination which determines the visibility of the pagination state related view.

The thresholdItemPagination expects an offset parameter (number of items before the last item) to determine the threshold item.

The ErrorView or LoadingView will only be visible below the List if the last item of the List appeared! That way the user is only interrupted if needed.

Skip pagination setup by using .noPagination.


The following code shows how easy-to-use the view is:

let listService = ListService()

AdvancedList(listService: listService, emptyStateView: {
    Text("No data")
}, errorStateView: { error in
    VStack {
        Button(action: {
            // do something
        }) {
}, loadingStateView: {
    Text("Loading ...")
}, pagination: .noPagination)


Stars: 6
Help us keep the lights on


Used By

Total: 0