Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for toolbar modifier and related types #316

Closed
MaxDesiatov opened this issue Dec 4, 2020 · 1 comment · Fixed by #169
Closed

Add support for toolbar modifier and related types #316

MaxDesiatov opened this issue Dec 4, 2020 · 1 comment · Fixed by #169
Assignees
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI

Comments

@MaxDesiatov
Copy link
Collaborator

Relevant APIs:

public protocol ToolbarContent {
  associatedtype Body : ToolbarContent
  @ToolbarContentBuilder var body: Self.Body { get }
}

@_functionBuilder public struct ToolbarContentBuilder {
  public static func buildBlock<Content>(
    _ content: Content
  ) -> some ToolbarContent where Content : ToolbarContent
  
  public static func buildBlock<Content>(
    _ content: Content
  ) -> some CustomizableToolbarContent where Content : CustomizableToolbarContent
}

extension View {
  public func toolbar<Content>(
    @ViewBuilder content: () -> Content
  ) -> some View where Content : View
  
  public func toolbar<Content>(
    @ToolbarContentBuilder content: () -> Content
  ) -> some View where Content : ToolbarContent
  
  public func toolbar<Content>(
    id: Swift.String,
    @ToolbarContentBuilder content: () -> Content
  ) -> some View where Content : CustomizableToolbarContent
}

public struct ToolbarItem<ID, Content> : ToolbarContent where Content : View {
  public typealias Body = Never
}

extension ToolbarItem where ID == Void {
  public init(
    placement: ToolbarItemPlacement = .automatic,
    @ViewBuilder content: () -> Content
  )
}

extension ToolbarItem : CustomizableToolbarContent where ID == String {
  public init(
    id: String,
    placement: ToolbarItemPlacement = .automatic,
    showsByDefault: Swift.Bool = true,
    @ViewBuilder content: () -> Content
  )
}

extension ToolbarItem : Identifiable where ID : Hashable {
  public var id: ID { get }
}

public struct ToolbarItemGroup<Content> : ToolbarContent where Content : View {
  public init(
    placement: ToolbarItemPlacement = .automatic,
    @ViewBuilder content: () -> Content
  )
  public typealias Body = Never
}

public struct ToolbarItemPlacement {
  public static let automatic: Self
  public static let primaryAction: Self
  public static let confirmationAction: Self
  public static let cancellationAction: Self
  public static let destructiveAction: Self
  public static let navigationBarLeading: Self
  public static let navigationBarTrailing: Self
  public static let bottomBar: Self
}

extension View {
  public func toolbar<Content>(
    @ViewBuilder content: () -> Content
  ) -> some View where Content : View
  
  public func toolbar<Content>(
    @ToolbarContentBuilder content: () -> Content
  ) -> some View where Content : ToolbarContent
  
  public func toolbar<Content>(
    id: Swift.String,
    @ToolbarContentBuilder content: () -> Content
  ) -> some View where Content : CustomizableToolbarContent
}
@MaxDesiatov MaxDesiatov added the SwiftUI compatibility Tokamak API differences with SwiftUI label Dec 4, 2020
@carson-katri
Copy link
Member

I have a draft PR already open for this, just started rewriting it with the new preference key implementation.

@carson-katri carson-katri self-assigned this Dec 4, 2020
MaxDesiatov pushed a commit that referenced this issue Aug 5, 2021
`Toolbar` is new in SwiftUI. It is coupled fairly closely with `NavigationView`, so this should be integrated with that somehow (#130). It was made similar to macOS which allows more than a leading/trailing `ToolbarItem`.

Resolves #316.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftUI compatibility Tokamak API differences with SwiftUI
Development

Successfully merging a pull request may close this issue.

2 participants