Newer Older
31 lines | 0.926kb
Bogdan Timofte authored a month ago
1
//
2
//  SidebarToggleToolbar.swift
3
//  USB Meter
4
//
5

            
6
import SwiftUI
7

            
8
extension View {
9
    /// Adds a sidebar toggle button to the leading toolbar on Mac Catalyst.
10
    /// No-op on other platforms. Apply to any top-level detail view reachable
11
    /// from the sidebar so users can restore the sidebar if it was hidden.
12
    func sidebarToggleToolbarItem() -> some View {
13
        #if targetEnvironment(macCatalyst)
14
        return self.toolbar {
15
            ToolbarItem(placement: .navigationBarLeading) {
16
                Button {
17
                    UIApplication.shared.sendAction(
18
                        Selector(("toggleSidebar:")),
19
                        to: nil, from: nil, for: nil
20
                    )
21
                } label: {
22
                    Image(systemName: "sidebar.left")
23
                }
24
                .help("Show Sidebar")
25
            }
26
        }
27
        #else
28
        return self
29
        #endif
30
    }
31
}