-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from fermoya/fix/pager-swiping
Fix/pager swiping
- Loading branch information
Showing
12 changed files
with
343 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Example/SwiftUIPagerExample/Examples/BizarreExampleView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// VerticalExampleView.swift | ||
// SwiftUIPagerExample | ||
// | ||
// Created by Fernando Moya de Rivas on 02/03/2020. | ||
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct BizarreExampleView: View { | ||
@State var page1: Int = 0 | ||
@State var page2: Int = 0 | ||
@State var data = Array(0..<10) | ||
|
||
var body: some View { | ||
GeometryReader { proxy in | ||
VStack(spacing: 10) { | ||
Text("Vertical").bold() | ||
Pager(page: self.$page1, | ||
data: self.data, | ||
id: \.self) { | ||
self.pageView($0) | ||
} | ||
.vertical() | ||
.itemSpacing(10) | ||
.itemAspectRatio(1.3) | ||
.background(Color.gray.opacity(0.2)) | ||
|
||
Spacer() | ||
|
||
Text("Right to left").bold() | ||
Pager(page: self.$page2, | ||
data: self.data, | ||
id: \.self) { | ||
self.pageView($0) | ||
} | ||
.itemSpacing(10) | ||
.horizontal(.rightToLeft) | ||
.interactive(0.8) | ||
.itemAspectRatio(0.7) | ||
.background(Color.gray.opacity(0.5)) | ||
} | ||
} | ||
} | ||
|
||
func pageView(_ page: Int) -> some View { | ||
ZStack { | ||
Rectangle() | ||
.fill(Color.yellow) | ||
Text("Page: \(page)") | ||
.bold() | ||
} | ||
.cornerRadius(5) | ||
.shadow(radius: 5) | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
Example/SwiftUIPagerExample/Examples/ColorsExampleView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// ColorsExampleView.swift | ||
// SwiftUIPagerExample | ||
// | ||
// Created by Fernando Moya de Rivas on 02/03/2020. | ||
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ColorsExampleView: View { | ||
|
||
@State var pageIndex = 0 | ||
|
||
var colors: [Color] = [ | ||
.red, .blue, .black, .gray, .purple, .green, .orange, .pink, .yellow, .white | ||
] | ||
|
||
var body: some View { | ||
NavigationView { | ||
GeometryReader { proxy in | ||
VStack { | ||
Pager(page: self.$pageIndex, | ||
data: self.colors, | ||
id: \.self) { | ||
self.pageView($0) | ||
} | ||
.itemSpacing(10) | ||
.padding(20) | ||
.onPageChanged({ page in | ||
withAnimation { | ||
self.pageIndex = page | ||
} | ||
}) | ||
.frame(width: min(proxy.size.height, proxy.size.width), | ||
height: min(proxy.size.height, proxy.size.width)) | ||
.background(Color.gray.opacity(0.3)) | ||
.navigationBarTitle("Color Picker", displayMode: .inline) | ||
|
||
Spacer() | ||
|
||
HStack { | ||
Spacer() | ||
Circle() | ||
.fill(self.colors[self.pageIndex]) | ||
.frame(width: 80) | ||
.overlay(Circle().stroke(self.pageIndex < 4 ? Color.gray.opacity(0.5) : Color.black, lineWidth: 5)) | ||
Spacer() | ||
Text("\(self.colors[self.pageIndex].rgb)") | ||
Spacer() | ||
} | ||
|
||
Spacer() | ||
|
||
HStack { | ||
Spacer() | ||
Button(action: { | ||
withAnimation { | ||
self.pageIndex = max(0, self.pageIndex - 1) | ||
} | ||
}, label: { | ||
HStack(spacing: 10) { | ||
Image(systemName: "backward.fill") | ||
.padding() | ||
Text("Previous") | ||
} | ||
}).disabled(self.pageIndex <= 0) | ||
Spacer() | ||
Button(action: { | ||
withAnimation { | ||
self.pageIndex = min(self.colors.count - 1, self.pageIndex + 1) | ||
} | ||
}, label: { | ||
HStack(spacing: 10) { | ||
Text("Next") | ||
Image(systemName: "forward.fill") | ||
.padding() | ||
} | ||
}).disabled(self.pageIndex >= self.colors.count - 1) | ||
Spacer() | ||
} | ||
|
||
Spacer() | ||
} | ||
} | ||
} | ||
} | ||
|
||
func pageView(_ color: Color) -> some View { | ||
Rectangle() | ||
.fill(color) | ||
.cornerRadius(5) | ||
.shadow(radius: 5) | ||
} | ||
|
||
} |
Oops, something went wrong.