Skip to content

Instantly share code, notes, and snippets.

@eldaroid
Last active July 4, 2024 20:25
Show Gist options
  • Save eldaroid/5d62f3eaa063db52294812368f340d99 to your computer and use it in GitHub Desktop.
Save eldaroid/5d62f3eaa063db52294812368f340d99 to your computer and use it in GitHub Desktop.
struct DefaultPopUps: View {
@State var onSheet = false
@State var onFullScreenCover = false
@State var onPopover = false
@State var onAlert = false
@State var onActionSheet = false
var body: some View {
VStack {
Button(action: {
self.onActionSheet = true
}, label: {
Text(".actionSheet")
})
.font(.largeTitle)
.padding(8.0)
.actionSheet(isPresented: self.$onActionSheet, content: {
ActionSheet(title: Text("Action Sheet"), message: Text("Action Sheet Message"), buttons: [
.default(Text("Default"), action: {}),
.destructive(Text("Desturctive"), action: {}),
.cancel(Text("Cancel"), action: {})
])
})
Button(action: {
self.onAlert = true
}, label: {
Text(".alert")
})
.font(.largeTitle)
.padding(8.0)
.alert(isPresented: self.$onAlert, content: {
Alert(
title: Text("Alerts in SwiftUI"),
message: Text("A Tutorial of using XCode and SwiftUI to create simple alerts."),
primaryButton: .destructive(Text("Read")) {
print("Read button tapped")
},
secondaryButton: .cancel(Text("Cancel")) {
print("Cancel button tapped")
}
)
})
Button(action: {
self.onSheet = true
}, label: {
Text(".sheet")
})
.font(.largeTitle)
.padding(8.0)
.sheet(isPresented: self.$onSheet, onDismiss: {}, content: {
AdditionalView()
.edgesIgnoringSafeArea(.all)
})
Button(action: {
self.onFullScreenCover = true
}, label: {
Text(".fullScreenCover")
})
.font(.largeTitle)
.padding(8.0)
.fullScreenCover(isPresented: self.$onFullScreenCover, onDismiss: {}, content: {
AdditionalView()
.edgesIgnoringSafeArea(.all)
})
Button(action: {
self.onPopover = true
}, label: {
Text(".popover")
})
.font(.largeTitle)
.padding(8.0)
.popover(isPresented: self.$onPopover, attachmentAnchor: .point(UnitPoint.bottomLeading), arrowEdge: .top, content: {
EmojiSelectorView()
.presentationCompactAdaptation(.popover)
})
}
}
}
struct AdditionalView: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
GeometryReader() { geometry in
ZStack {
Rectangle()
.foregroundColor(.red)
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}, label: {
Image(systemName: "xmark.circle")
.font(.custom("system", size: 96))
})
}
}
}
}
struct EmojiSelectorView: View {
private struct Emoji: Identifiable, Equatable {
let id = UUID()
let emojiString: String
static func examples() -> [Emoji] {
return [
Emoji(emojiString: "😀"),
Emoji(emojiString: "😂"),
Emoji(emojiString: "🥳"),
Emoji(emojiString: "😎"),
Emoji(emojiString: "😍")
]
}
}
@Environment(\.dismiss) var dismiss
private let columns = [GridItem(.adaptive(minimum: 44), spacing: 10)]
private let emojis: [Emoji] = Emoji.examples()
var body: some View {
HStack {
Text("BottomLeading VStack Popover")
.font(.title3)
Divider()
LazyVGrid(columns: columns) {
ForEach(emojis) { emoji in
ZStack {
Text(emoji.emojiString)
.font(.title)
.onTapGesture {
dismiss()
}
}
}
}
}
}
}
@eldaroid
Copy link
Author

eldaroid commented Jul 4, 2024

DefaultPopUps.mp4

@eldaroid
Copy link
Author

eldaroid commented Jul 4, 2024

DesignHumanInterfaceGuidelines:

DesignHumanInterfaceGuidelines

@eldaroid
Copy link
Author

eldaroid commented Jul 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment