Skip to content

Commit

Permalink
refactor NavigationView
Browse files Browse the repository at this point in the history
  • Loading branch information
ezraberch committed Sep 10, 2021
1 parent 3d9558f commit b5f9588
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions Sources/TokamakStaticHTML/Views/Navigation/NavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@
import TokamakCore

extension NavigationView: _HTMLPrimitive {
private struct NavBody: View {
let toolbarContent: [AnyToolbarItem]
let title: AnyView?
let view: NavigationView

init(_ toolbarContent: [AnyToolbarItem], _ title: AnyView?, _ view: NavigationView) {
self.toolbarContent = toolbarContent
self.title = title
self.view = view
}

var body: some View {
HTML("div", ["class": "_tokamak-toolbar-content _tokamak-toolbar-leading"]) {
view.items(from: toolbarContent, at: .navigationBarLeading)
view.items(from: toolbarContent, at: .navigation)
title
.font(.headline)
view.items(from: toolbarContent, at: .navigationBarTrailing)
view.items(from: toolbarContent, at: .automatic, .primaryAction)
view.items(from: toolbarContent, at: .destructiveAction)
.foregroundColor(.red)
}
HTML("div", ["class": "_tokamak-toolbar-content _tokamak-toolbar-center"]) {
view.items(from: toolbarContent, at: .principal, .status)
}
HTML("div", ["class": "_tokamak-toolbar-content _tokamak-toolbar-trailing"]) {
view.items(from: toolbarContent, at: .cancellationAction)
view.items(from: toolbarContent, at: .confirmationAction)
.foregroundColor(.accentColor)
}
}
}

@_spi(TokamakStaticHTML)
public var renderedBody: AnyView {
let proxy = _NavigationViewProxy(self)
Expand All @@ -32,24 +65,7 @@ extension NavigationView: _HTMLPrimitive {
title.font(.headline)
}
} else {
HTML("div", ["class": "_tokamak-toolbar-content _tokamak-toolbar-leading"]) {
items(from: toolbarContent, at: .navigationBarLeading)
items(from: toolbarContent, at: .navigation)
title
.font(.headline)
items(from: toolbarContent, at: .navigationBarTrailing)
items(from: toolbarContent, at: .automatic, .primaryAction)
items(from: toolbarContent, at: .destructiveAction)
.foregroundColor(.red)
}
HTML("div", ["class": "_tokamak-toolbar-content _tokamak-toolbar-center"]) {
items(from: toolbarContent, at: .principal, .status)
}
HTML("div", ["class": "_tokamak-toolbar-content _tokamak-toolbar-trailing"]) {
items(from: toolbarContent, at: .cancellationAction)
items(from: toolbarContent, at: .confirmationAction)
.foregroundColor(.accentColor)
}
NavBody(toolbarContent, title, self)
}
}
.font(.caption)
Expand Down

0 comments on commit b5f9588

Please sign in to comment.