Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ a component already exists before building your own.
| `List1View` | Simple label ↔ value row | [Lists & rows](docs/lists-and-rows.md) |
| `List8View` | Label ↔ value row with an optional avatar | [Lists & rows](docs/lists-and-rows.md) |
| `NavigationBar` | Custom three-slot nav bar + `NavigationBarElement` buttons | [Navigation & containers](docs/navigation-and-containers.md) |
| `NavigationBarCircleButton` / `NavigationBarCircleMenu` | Bar button / menu in the nav circle, for actions with no bundled element | [Navigation & containers](docs/navigation-and-containers.md) |
| `NavigationBarCircleIcon` | The nav bar's 34pt token circle around any icon | [Navigation & containers](docs/navigation-and-containers.md) |
| `BottomSheet` | Sheet chrome (grabber + nav bar) with self-sizing support | [Navigation & containers](docs/navigation-and-containers.md) |
| `MenuViewModifier` | Card chrome — rounded background + shadow | [Navigation & containers](docs/navigation-and-containers.md) |
| `Toast` | Blurred toast — warning/info/error/success/copied/loading | [Feedback](docs/feedback.md) |
Expand Down
1 change: 0 additions & 1 deletion Sources/DashUIKit/Components/BottomSheet/BottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public struct BottomSheet<Content: View>: View {
)
}
.disabled(!isCloseButtonActive)
.opacity(isCloseButtonActive ? 1 : 0.35)
}
}
)
Expand Down
62 changes: 28 additions & 34 deletions Sources/DashUIKit/Components/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,27 @@ public enum NavigationBarElement: String {
case plus = "navigationbar-plus"
case info = "navigationbar-info"

/// The element as drawn in the bar. `back`, `close` and `plus` are a glyph
/// centred in a stroked circle; `info` is a self-contained icon.
/// The element as drawn in the bar. `back`, `close` and `plus` are a
/// `NavigationBarCircleIcon`; `info` is a self-contained icon.
@ViewBuilder
public var icon: some View {
switch self {
case .back, .close, .plus:
glyph
.foregroundColor(.dash.toolbarRoundContent)
.frame(width: 34, height: 34)
.overlay(
Circle()
.strokeBorder(Color.dash.toolbarRoundBorder, lineWidth: 1.5)
)
NavigationBarCircleIconContent(source: source)
case .info:
glyph
Image(dash: source)
.fixedSize()
}
}

private var glyph: some View {
Image(dash: .custom(rawValue, bundle: .module))
.fixedSize()
private var source: DashIconSource {
.custom(rawValue, bundle: .module)
}

public func button(action: @escaping () -> Void) -> some View {
Button(action: action) {
NavigationBarButton(accessibilityLabel: Text(accessibilityLabelText), action: action) {
icon
.frame(height: 44)
.contentShape(Rectangle())
}
.buttonStyle(NavigationBarButtonStyle())
.accessibilityLabel(Text(accessibilityLabelText))
}

var accessibilityLabelText: String {
Expand All @@ -146,22 +136,6 @@ public enum NavigationBarElement: String {
}
}

@available(iOS 14, macOS 11, *)
private struct NavigationBarButtonStyle: ButtonStyle {
@ViewBuilder
func makeBody(configuration: Configuration) -> some View {
let content = configuration.label
.scaleEffect(configuration.isPressed ? 0.88 : 1)
.opacity(configuration.isPressed ? 0.7 : 1)

if #available(iOS 15, macOS 12, *) {
content.animation(.easeInOut(duration: 0.12), value: configuration.isPressed)
} else {
content.animation(.easeInOut(duration: 0.12))
}
}
}

@available(iOS 17, macOS 14, *)
#Preview("NavigationBar Back") {
NavigationBar(
Expand Down Expand Up @@ -216,6 +190,26 @@ private struct NavigationBarButtonStyle: ButtonStyle {
leading: { NavigationBarElement.back.button { } },
trailing: { NavigationBarElement.plus.button { } }
)

NavigationBar(
leading: { NavigationBarElement.back.button { } },
trailing: {
HStack(spacing: 10) {
NavigationBarCircleButton(.system("arrow.clockwise"), accessibilityLabel: Text("Refresh")) { }
NavigationBarCircleMenu(.system("ellipsis"), accessibilityLabel: Text("More")) {
Button("Action") { }
}
}
}
)

NavigationBar(
leading: { NavigationBarElement.back.button { } },
trailing: {
NavigationBarCircleButton(.system("arrow.clockwise"), accessibilityLabel: Text("Refresh")) { }
.disabled(true)
}
)
}
}

Expand Down
105 changes: 105 additions & 0 deletions Sources/DashUIKit/Components/NavigationBarButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// Copyright © 2026 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

/// The one implementation of a navigation bar button: touch area, press and
/// disabled styling, accessibility label. `NavigationBarElement.button(action:)`
/// and `NavigationBarCircleButton` both render through it.
@available(iOS 14, macOS 11, *)
nonisolated struct NavigationBarButton<Label: View>: View {
private let accessibilityLabel: Text
private let action: () -> Void
private let label: Label

init(
accessibilityLabel: Text,
action: @escaping () -> Void,
@ViewBuilder label: () -> Label
) {
self.accessibilityLabel = accessibilityLabel
self.action = action
self.label = label()
}

var body: some View {
Button(action: action) {
label.navigationBarTouchArea()
}
.buttonStyle(NavigationBarButtonStyle())
.accessibilityLabel(accessibilityLabel)
}
}

@available(iOS 14, macOS 11, *)
extension View {
/// The bar's touch area: 44pt tall, and at least 44pt wide for hit
/// testing. The extra width is hit area only — the element keeps its
/// hug width in layout, so a 34pt circle stays aligned to the bar's
/// 20pt inset.
nonisolated func navigationBarTouchArea() -> some View {
frame(height: 44)
.contentShape(NavigationBarHitShape())
}

/// Dims a bar element while it is disabled — the one place the bar's
/// disabled look is defined.
nonisolated func navigationBarDisabledDimming(_ isEnabled: Bool) -> some View {
opacity(isEnabled ? 1 : navigationBarDisabledOpacity)
}
}

/// Opacity of a disabled bar element (button, menu, `BottomSheet` close).
let navigationBarDisabledOpacity: Double = 0.35

/// The element's frame, widened symmetrically to at least 44pt.
@available(iOS 14, macOS 11, *)
private struct NavigationBarHitShape: Shape {
func path(in rect: CGRect) -> Path {
let outset = max(0, (44 - rect.width) / 2)
return Path(rect.insetBy(dx: -outset, dy: 0))
}
}

@available(iOS 14, macOS 11, *)
struct NavigationBarButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
NavigationBarButtonStyleBody(configuration: configuration)
}
}

/// A view, not inline in `makeBody`, so it can read `isEnabled`: a custom
/// `ButtonStyle` gets no automatic disabled dimming.
@available(iOS 14, macOS 11, *)
private struct NavigationBarButtonStyleBody: View {
let configuration: ButtonStyleConfiguration

@Environment(\.isEnabled) private var isEnabled

@ViewBuilder
var body: some View {
let content = configuration.label
.scaleEffect(configuration.isPressed ? 0.88 : 1)
.opacity(configuration.isPressed ? 0.7 : 1)
.navigationBarDisabledDimming(isEnabled)
Comment thread
romchornyi marked this conversation as resolved.

if #available(iOS 15, macOS 12, *) {
content.animation(.easeInOut(duration: 0.12), value: configuration.isPressed)
} else {
content.animation(.easeInOut(duration: 0.12))
}
}
}
59 changes: 59 additions & 0 deletions Sources/DashUIKit/Components/NavigationBarCircleButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Copyright © 2026 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

/// A `NavigationBarCircleIcon` as a bar button, for an action the bar has no
/// bundled element for (refresh, …). Same touch area, press animation and
/// disabled dimming as `NavigationBarElement.button(action:)`.
///
/// `accessibilityLabel` is a `Text`, so `Text("Refresh")` is looked up in the
/// host's string table like a SwiftUI `Button` title; pass
/// `Text(verbatim:)` for an already-localized string.
@available(iOS 14, macOS 11, *)
public struct NavigationBarCircleButton: View {
private let icon: DashIconSource
private let accessibilityLabel: Text
private let action: () -> Void

public init(
_ icon: DashIconSource,
accessibilityLabel: Text,
action: @escaping () -> Void
) {
self.icon = icon
self.accessibilityLabel = accessibilityLabel
self.action = action
}

public var body: some View {
NavigationBarButton(accessibilityLabel: accessibilityLabel, action: action) {
NavigationBarCircleIcon(icon)
}
}
}

#if DEBUG
@available(iOS 17, macOS 14, *)
#Preview("NavigationBarCircleButton") {
HStack(spacing: 10) {
NavigationBarCircleButton(.system("arrow.clockwise"), accessibilityLabel: Text("Refresh")) { }
NavigationBarCircleButton(.system("arrow.clockwise"), accessibilityLabel: Text("Refresh")) { }
.disabled(true)
}
.padding()
}
#endif
84 changes: 84 additions & 0 deletions Sources/DashUIKit/Components/NavigationBarCircleIcon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// Copyright © 2026 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

/// The navigation bar's round element: an icon centred in a 34pt circle with a
/// 1.5pt `toolbarRoundBorder` stroke, tinted `toolbarRoundContent`. The whole
/// circle is its hit-testing shape.
///
/// `NavigationBarElement.back`, `.close` and `.plus` draw through it. Use it
/// directly only to build something the bar doesn't ship — for a button use
/// `NavigationBarCircleButton`, for a menu `NavigationBarCircleMenu`.
///
/// The icon is sized by the component: an SF Symbol (`.system`) is set in
/// `Font.dash.subheadMedium`; a `.custom` / `.uiImage` asset renders at its own
/// size, so it should be drawn for the circle (the bundled nav glyphs are).
@available(iOS 14, macOS 11, *)
public struct NavigationBarCircleIcon: View {
private let source: DashIconSource

public init(_ source: DashIconSource) {
self.source = source
}

public var body: some View {
NavigationBarCircleIconContent(source: source)
}
}

/// The drawing behind `NavigationBarCircleIcon`. `nonisolated` so the
/// nonisolated `NavigationBarElement.icon` can build it without the public
/// type committing to that isolation.
@available(iOS 14, macOS 11, *)
nonisolated struct NavigationBarCircleIconContent: View {
let source: DashIconSource

var body: some View {
glyph
.foregroundColor(.dash.toolbarRoundContent)
.frame(width: 34, height: 34)
.overlay(
Circle()
.strokeBorder(Color.dash.toolbarRoundBorder, lineWidth: 1.5)
)
.contentShape(Circle())
}

@ViewBuilder
private var glyph: some View {
switch source {
case .system:
Image(dash: source)
.font(Font.dash.subheadMedium)
case .custom, .uiImage:
Image(dash: source)
.fixedSize()
}
}
}

#if DEBUG
@available(iOS 17, macOS 14, *)
#Preview("NavigationBarCircleIcon") {
HStack(spacing: 10) {
NavigationBarCircleIcon(.custom(NavigationBarElement.back.rawValue, bundle: .module))
NavigationBarCircleIcon(.system("arrow.clockwise"))
NavigationBarCircleIcon(.system("ellipsis"))
}
.padding()
}
#endif
Loading
Loading