summaryrefslogtreecommitdiff
path: root/Sora/Views/PlatformSpecificToolbarItem.swift
blob: 578affee3ff39c096f4a59d9a989bbf159fade25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import SwiftUI

struct PlatformSpecificToolbarItem<Content: View>: ToolbarContent {
  let placement: ToolbarItemPlacement
  let content: () -> Content

  init(
    placement: ToolbarItemPlacement? = nil,
    @ViewBuilder content: @escaping () -> Content
  ) {
    #if os(macOS)
      self.placement = .automatic
    #else
      if #available(iOS 26, *) {
        self.placement = placement ?? .secondaryAction
      } else {
        self.placement = placement ?? .bottomBar
      }
    #endif

    self.content = content
  }

  var body: some ToolbarContent {
    #if os(macOS)
      ToolbarItem {
        content()
      }
    #else
      ToolbarItem(placement: placement) {
        content()
      }
    #endif
  }
}