title: SwiftUI: how to present more than one ToolbarItem using semantic placement?
body: <p>The WWDC 2020 SwiftUI talks made mention of a new &quot;.toolbar&quot; modifier. Toolbars vary depending on the device being used and the toolbar modifier should create the proper type of toolbar for the device. Moreover, toolbars vary depending on how a view gets displayed - i.e. did you navigate to the scene or was the scene modally presented?</p>
  <p>In the playground code, below, there are two View structs. The first is called <code>MainToolbarView</code> and gets displayed (I believe) as if the playground had navigated to it. The second is called <code>PresentedView</code> and is presented modally from <code>MainToolbarView</code>.</p>
  <p><a href="https://i.stack.imgur.com/Hurz3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hurz3.png" alt="MainToobarView (non-modal)" /></a></p>
  <p>In the MainToolbarView the toolbar has positional placement for its <code>Save</code> and <code>Cancel</code> buttons (<code>.navigationBarLeading</code> and <code>.navigationBarTrailing</code>). This works fine. Tapping either button causes a text field to display either &quot;Save&quot; or &quot;Cancel&quot;.</p>
  <p><a href="https://i.stack.imgur.com/uNEWf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uNEWf.png" alt="PresentedView (modal)" /></a></p>
  <p>When the <code>Present Sheet</code> button is tapped the second view is modally presented. There is a problem in toolbar for the presented sheet. The toolbar is using semantic placement for its <code>Confirm</code> and <code>Deny</code> buttons (<code>.confirmationAction</code> and <code>.cancellationAction</code>). However, only the <code>Confirm</code> button is displayed.</p>
  <p>Can anyone tell me why both buttons are shown on the <code>MainToolbarView</code> but only one button is on the <code>PresentedView</code>  toolbar? I've tried changing the order of the buttons, making the two buttons into an HStack, or even trying to use positional placement. None of those options have worked for me.</p>
  <pre><code>import SwiftUI
  import PlaygroundSupport
  
  struct MainToolbarView: View {
  
      @State private var buttonIdentifier = &quot;initial state&quot;
      @State private var showSheet = false
  
      var body: some View {
          NavigationView {
              VStack {
                  Spacer()
                  Text( $buttonIdentifier.wrappedValue )
                  Spacer()
                  Button( &quot;Present Sheet&quot; )
                      { showSheet = true }
                  Spacer()
              }
              .toolbar {
                  ToolbarItem( placement: .navigationBarLeading )
                      { Button( &quot;Save&quot;, action: reportSave ) }
                  ToolbarItem( placement: .navigationBarTrailing )
                      { Button( &quot;Cancel&quot;, action: reportCancel ) }
              }
              .navigationBarTitle( &quot;MAIN&quot; )
          }
          .sheet(isPresented: $showSheet )
              { PresentedView(buttonIdentifier: $buttonIdentifier ) }
      }
      private func reportSave()
      {
          buttonIdentifier = &quot;save&quot;
      }
  
      private func reportCancel()
      {
          buttonIdentifier = &quot;cancel&quot;
      }
  }
  
  
  struct PresentedView: View {
  
      // MARK: API
      @Binding var buttonIdentifier: String
  
      // MARK: instance variables
      @Environment( \.presentationMode ) var mode
  
      //.confirmationAction
  
      var body: some View {
          NavigationView {
              Text( &quot;Tap action buttons&quot; )
                  .toolbar {
                      ToolbarItem( placement: .confirmationAction )
                          { Button( &quot;Confirm&quot;, action: reportConfirm ) }
                      ToolbarItem( placement: .cancellationAction )
                          { Button( &quot;Deny&quot;, action: reportDenied ) }
                  }
                  .navigationBarTitle( &quot;SHEET&quot; )
          }
      }
  
      private func reportDenied() {
          buttonIdentifier = &quot;sheet denied&quot;
          self.mode.wrappedValue.dismiss()
      }
  
      private func reportConfirm() {
          buttonIdentifier = &quot;sheet confirmed&quot;
          self.mode.wrappedValue.dismiss()
      }
  }
  
  
   PlaygroundPage.current.setLiveView( MainToolbarView() )
  </code></pre>
  <p>`</p>