Skip to content

Instantly share code, notes, and snippets.

@edudnyk
Last active October 20, 2021 20:59
Show Gist options
  • Save edudnyk/71be52aa3d02557df0ecb920b9c54b9d to your computer and use it in GitHub Desktop.
Save edudnyk/71be52aa3d02557df0ecb920b9c54b9d to your computer and use it in GitHub Desktop.
An example of usage of the PagingView in SwiftUI
struct PagingContentView: View {
@State var currentPage: Int = 0
let config: PagingViewConfig
init() {
var config = PagingViewConfig()
config.direction = .horizontal
config.size = 100
config.margin = 0
config.spacing = 0
self.config = config
}
var body: some View {
PagingView(config: config, page: $currentPage, views: Array(0...30).map { page(at: $0) })
}
@ViewBuilder
func page(at index: Int) -> some View {
Text("Page \(index)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(backgroundColor(at: index))
}
func backgroundColor(at index: Int) -> Color {
let indexMod = (index % 3)
switch indexMod {
case 0: return Color.red
case 1: return Color.green
case 2: return Color.blue
default: return Color.clear
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment