title: UIToolbar in iOS 13 SwiftUI?
body: <p>I'm attempting to adapt <code>UIToolbar</code> to <code>UIViewRepresentable</code> to use it within SwiftUI. I'm required to support iOS 13, otherwise I would be using Apple's new toolbar in iOS 14.</p>
  <p>So far I have code that displays the toolbar on the screen, however it doesn't extend to the safe area at the bottom of the screen for devices with no home button.</p>
  <p>Does anyone have any suggestions or references for complete <code>UIToolbar</code> implementations in SwiftUI?</p>
  <p>Image:</p>
  <p><a href="https://i.stack.imgur.com/Weutp.png" rel="nofollow noreferrer">https://i.stack.imgur.com/Weutp.png</a></p>
  <p>My code:</p>
  <pre><code>// TestView.swift
  var body: some View {
    VStack {
      Toolbar(items: [
        UIBarButtonItem(
           title: &quot;Done&quot;,
           style: .plain,
           target: nil,
           action: nil
      ])
    }
  }
  
  // Toolbar.swift
  import SwiftUI
  import UIKit
  import Foundation
  
  struct Toolbar: UIViewRepresentable {
      typealias UIViewType = UIToolbar
      var items: [UIBarButtonItem]
      var toolbar: UIToolbar
      
      init(items: [UIBarButtonItem]) {
          self.toolbar = UIToolbar()
          self.items = items
      }
  
      func makeUIView(context: UIViewRepresentableContext&lt;Toolbar&gt;) -&gt; UIToolbar {
          toolbar.setItems(self.items, animated: true)
          toolbar.barStyle = UIBarStyle.default
          toolbar.sizeToFit()
          return toolbar
      }
      
      func updateUIView(_ uiView: UIToolbar, context: UIViewRepresentableContext&lt;Toolbar&gt;) {
      }
      
      func makeCoordinator() -&gt; Toolbar.Coordinator {
          Coordinator(self)
      }
      
      final class Coordinator: NSObject, UIToolbarDelegate, UIBarPositioning {
          var toolbar: Toolbar
          var barPosition: UIBarPosition
          
          init(_ toolbar: Toolbar) {
              self.toolbar = toolbar
              self.barPosition = .bottom
          }
          
          private func position(for: UIToolbar) -&gt; UIBarPosition {
              return .bottom
          }
      }
  }
  </code></pre>