Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active June 24, 2019 22:35
Show Gist options
  • Save KentarouKanno/312d5729c903229fc48587730f73d9e9 to your computer and use it in GitHub Desktop.
Save KentarouKanno/312d5729c903229fc48587730f73d9e9 to your computer and use it in GitHub Desktop.

参考URL: SwiftUI: Modal presentation

import SwiftUI

struct PushModal : View {
    @State var isPresented = false
    
    var modalPresentation: some View {
        NavigationView {
            Text("Hello World")
                .font(.caption)
                .navigationBarTitle(Text("Modal Contents"))
                .navigationBarItems(trailing: Button(action: { self.isPresented = false } ) { Text("Done") })
        }
    }
    
    var body: some View {
        NavigationView {
            NavigationButton(destination: Text("Hello World")
                .font(.caption)
                .navigationBarTitle(Text("Detail View Contents"))
            ) {
                Text("Show Detail View")
                }
                .navigationBarTitle(Text("Welcome"))
                .navigationBarItems(trailing:
                    Button(action: { self.isPresented = true }) { Text("Show Modal") })
            }
            .presentation( isPresented ? Modal(modalPresentation, onDismiss: { self.isPresented.toggle() }) : nil )
    }
}

#if DEBUG
struct PushModal_Previews : PreviewProvider {
    static var previews: some View {
        PushModal()
    }
}
#endif
イメージ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment