mirror of
https://github.com/yattee/yattee.git
synced 2026-07-20 14:22:02 +00:00
Use native text Close button for sheet toolbars on macOS
Sheet dismiss buttons rendered as an iOS-style circular glass "X" on macOS 26, which looks foreign on the desktop. Add a shared sheetCloseToolbarItem helper that renders a native text "Close" button on macOS while keeping the compact icon-only xmark on iOS/tvOS, and replace the ~14 duplicated inline close buttons across sheets with it.
This commit is contained in:
50
Yattee/Extensions/ToolbarContent+Close.swift
Normal file
50
Yattee/Extensions/ToolbarContent+Close.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// ToolbarContent+Close.swift
|
||||
// Yattee
|
||||
//
|
||||
// Shared sheet-dismiss toolbar item.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
/// Standard sheet-dismiss toolbar item.
|
||||
///
|
||||
/// On macOS this renders a native text button (e.g. "Close"), which fits the desktop
|
||||
/// convention. On iOS/tvOS it renders the compact icon-only xmark used by the rest of
|
||||
/// the app's sheets.
|
||||
///
|
||||
/// Placement defaults to `.confirmationAction`; only the *label* changes per platform,
|
||||
/// so it can be dropped into existing `.toolbar { }` blocks without changing layout.
|
||||
@ToolbarContentBuilder
|
||||
func sheetCloseToolbarItem(
|
||||
placement: ToolbarItemPlacement = .confirmationAction,
|
||||
titleKey: LocalizedStringResource = "common.close",
|
||||
identifier: String? = nil,
|
||||
action: @escaping () -> Void
|
||||
) -> some ToolbarContent {
|
||||
ToolbarItem(placement: placement) {
|
||||
sheetCloseButton(titleKey: titleKey, identifier: identifier, action: action)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func sheetCloseButton(
|
||||
titleKey: LocalizedStringResource,
|
||||
identifier: String?,
|
||||
action: @escaping () -> Void
|
||||
) -> some View {
|
||||
let button = Button(role: .cancel, action: action) {
|
||||
#if os(macOS)
|
||||
Text(String(localized: titleKey))
|
||||
#else
|
||||
Label(String(localized: titleKey), systemImage: "xmark")
|
||||
.labelStyle(.iconOnly)
|
||||
#endif
|
||||
}
|
||||
|
||||
if let identifier {
|
||||
button.accessibilityIdentifier(identifier)
|
||||
} else {
|
||||
button
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user