This provides infinite carousel-like paging view in SwiftUI.
- Development with Xcode 16.2+
- Written in Swift 6.0
- Compatible with iOS 17.0+
- Define a structure conforming to Pageable.
import Foundation
import InfinitePaging
structPage:Pageable{varid=UUID()varnumber:Int}- Use InfinitePagingView
import SwiftUI
import InfinitePaging
structContentView:View{
// Prepare three elements to display at first.
@Statevarpages:[Page]=[Page(number:-1),Page(number:0),Page(number:1)]varbody:someView{InfinitePagingView(
objects: $pages,
pageAlignment:.horizontal,
pagingHandler:{paging($0)},
content:{pageView($0)})}
// Define the View that makes up one page.
privatefunc pageView(_ page:Page)->someView{Text(String(page.number)).font(.largeTitle).fontWeight(.bold).frame(maxWidth:.infinity, maxHeight:.infinity).background(Color.gray).clipShape(RoundedRectangle(cornerRadius:32)).padding()}
// Shifts the array element by one when a paging request comes.
privatefunc paging(_ pageDirection:PageDirection){switch pageDirection {case.backward:iflet number = pages.first?.number {
pages.insert(Page(number: number -1), at:0)
pages.removeLast()}case.forward:iflet number = pages.last?.number {
pages.append(Page(number: number +1))
pages.removeFirst()}}}}This library does not collect or track user information, so it does not include a PrivacyInfo.xcprivacy file.
