Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Brett-Best/e1719d573d5be65ecdc553eb1d702af0 to your computer and use it in GitHub Desktop.
Save Brett-Best/e1719d573d5be65ecdc553eb1d702af0 to your computer and use it in GitHub Desktop.
// Third Example
import PureSwiftUI
struct PrimaryButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
}
}
struct ContentView: View {
var body: some View {
Button("Okay") {
}
.buttonStyle(PrimaryButtonStyle())
.hPadding(16)
.padding(.bottom, 16)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice(.iPhone_11_Pro)
}
}
// Second Example
import PureSwiftUI
struct ValidationError: Identifiable {
let id = UUID()
let title: LocalizedStringKey
let subtitle: LocalizedStringKey
}
struct ContentView: View {
var isPresented: Binding<Bool> = .constant(false)
var validationErrors: [ValidationError] = []
@Environment(\.sizeCategory) var contentSize
var imageLength: CGFloat { contentSize.isAccessibilityCategory ? 24 : 16 }
var hStackSpacing: CGFloat { contentSize.isAccessibilityCategory ? 24 : 16 }
var sheetContentsMaxWidth: CGFloat { contentSize.isAccessibilityCategory ? .infinity : 414}
var body: some View {
ZStack {
if isPresented.wrappedValue {
Group {
sheetContents()
}.onDisappear {
self.isPresented.wrappedValue = false
}
}
}
}
func sheetContents() -> some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 16) {
ForEach(validationErrors, content: validationErrorView)
}
.hPadding(16)
.vPadding(24)
Button("Okay") {
self.isPresented.wrappedValue = false
}
.buttonStyle(DefaultButtonStyle())
.hPadding(16)
.padding(.bottom, 16)
}
.frame(maxWidth: sheetContentsMaxWidth, maxHeight: .infinity)
.padding(48)
.transition(.move(edge: .bottom))
}
func validationErrorView(validationError: ValidationError) -> some View {
EmptyView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice(.iPhone_11_Pro)
}
}
// First example
import PureSwiftUI
struct ContentView: View {
var body: some View {
Text("TEST")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewDevice(.iPhone_11_Pro)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment