Skip to content

Instantly share code, notes, and snippets.

@p-larson
Last active May 25, 2020 16:57
Show Gist options
  • Save p-larson/3cc220f916e891946cc53d3df550762c to your computer and use it in GitHub Desktop.
Save p-larson/3cc220f916e891946cc53d3df550762c to your computer and use it in GitHub Desktop.
//
// SwiftUIViewDemo.swift
//
// Created by Peter Larson on 5/25/20.
// Copyright © 2020 Peter Larson. All rights reserved.
//
import SwiftUI
import SwiftUIPager
struct SwiftUIViewDemo: View {
@State var page1 = 0
@State var page2 = 0
var body: some View {
VStack {
GeometryReader { proxy in
Pager(page: self.$page1, data: Array(0..<10), id: \.self) { page in
VStack(spacing: 0) {
Color.orange
.overlay(Text("Parent Pager Page \(page)"))
Pager(page: self.$page2, data: Array(0..<5), id: \.self) { x in
Rectangle()
.foregroundColor(.red)
.padding()
.overlay(Text("SubView Pager Page \(x.description)"))
}
.itemSpacing(16)
.interactive(0.6)
.itemAspectRatio(1.0, alignment: .center)
.highPriorityGesture()
.swipeInteractionArea(.page)
.background(Color.blue)
.frame(width: proxy.size.width, height: proxy.size.width / 2)
Color.orange
}
}
.itemSpacing(16)
.interactive(0.6)
.itemAspectRatio(1.0, alignment: .center)
.swipeInteractionArea(.page)
}
HStack {
ForEach(0 ..< 10, id: \.self) { page in
Circle()
.foregroundColor(page == self.page1 ? .black : .gray)
.frame(width: 15, height: 15)
}
}.opacity(0.5)
}
}
}
struct SwiftUIViewDemo_Previews: PreviewProvider {
static var previews: some View {
SwiftUIViewDemo()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment