I'm using SwiftUI on macOS. The idea is to create a sheet, which has two buttons. One for cancellation and one for done actions. They are placed with their .confirmationAction and .confirmationAction placement options inside ToolbarItems.
When I now open the sheet, the container also adds this buttons to it's toolbar.
Is there something wrong with my code or is this considered an issue with SwiftUI?
Thank you for your assistance.
Tobias
When I now open the sheet, the container also adds this buttons to it's toolbar.
Is there something wrong with my code or is this considered an issue with SwiftUI?
Thank you for your assistance.
Tobias
Code Block // // ContentView.swift // Toolbar // // Created by Tobias on 16.12.20. // import SwiftUI struct ContentView: View { enum Selection: String { case First } @State private var selection: Selection? = .First var body: some View { NavigationView { List { NavigationLink( destination: DetailsView(), tag: Selection.First, selection: $selection ) { Text("First") } } .listStyle(SidebarListStyle()) } } } struct DetailsView: View { @State private var displayAdd = false @State private var message = "Initial Message" var body: some View { Text(message) .toolbar { ToolbarItem(placement: .primaryAction) { Button("Add") { self.displayAdd = true } } } .sheet(isPresented: $displayAdd) { SheetView(completion: didFinish) } } func didFinish(_ result: SheetView.Result) { displayAdd = false switch result { case .Success: message = "Success" default: message = "Cancelled" } } } struct SheetView: View { typealias Completion = (Result) -> Void enum Result { case Cancel case Success } private var completion: Completion init(completion: @escaping Completion) { self.completion = completion } var body: some View { Text("Modal Sheet") .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { completion(.Success) } } ToolbarItem(placement: .destructiveAction) { Button("Cancel") { completion(.Cancel) } } } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }