Skip to content

Instantly share code, notes, and snippets.

@creaaa
Last active September 9, 2019 09:39
Show Gist options
  • Save creaaa/d0e68ff18ce0a20a5692989a1424e17e to your computer and use it in GitHub Desktop.
Save creaaa/d0e68ff18ce0a20a5692989a1424e17e to your computer and use it in GitHub Desktop.
SwiftUI × Presentation
//
// ContentView.swift
// NaviGomi
//
// Created by crea on 2019/09/09.
// Copyright © 2019 crea. All rights reserved.
//
import SwiftUI
struct ContentView: View {
@State var openSheet: Bool {
didSet {
print("opensheet!\(openSheet)")
}
}
@State var openAlert: Bool
@State var openActionSheet: Bool
var body: some View {
VStack(spacing: 8) {
Button("Sheet") { self.openSheet.toggle() }
.sheet(isPresented: $openSheet) {
Text("Sheet!!!")
}
Button("Alert") { self.openAlert.toggle() }
.alert(isPresented: $openAlert) {
Alert(title: .init("このアカウント消したい?"),
message: .init("それは取り消せないけど..."),
primaryButton: Alert.Button.cancel(.init("やっぱやめた...")),
secondaryButton: Alert.Button.destructive(.init("けす!")))
}
Button("ActionSheet") { self.openActionSheet.toggle() }
.actionSheet(isPresented: $openActionSheet) {
ActionSheet(
title: .init("beef or chicken?"),
buttons: [
.default(.init("Beef")) { print("beef!") },
.default(.init("Chicken")) { print("chicken!") },
.cancel()
]
)
}
}
}
}
struct DestinationView: View {
var body: some View {
Text("goal!")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(openSheet: false,
openAlert: false,
openActionSheet: false
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment