Files
damus/damus/Shared/Modifiers/ToolbarItemModifier.swift
T
ericholguinandDaniel D’Aquino d99443be6d ui: Fixes for iOS 26 toolbars
Note: This will only become user-facing once we switch to liquid glass
mode, therefore no changelog entry is needed now.

Changelog-None
Closes: https://github.com/damus-io/damus/issues/3702
Co-Authored-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: ericholguin <ericholguin@apache.org>
2026-03-18 17:07:25 -07:00

36 lines
1.0 KiB
Swift

//
// ToolbarItemModifier.swift
// damus
//
import SwiftUI
/// Extension that adds the `.hideToolbarBackground()` modifier to toolbar content.
///
/// This modifier conditionally applies `.sharedBackgroundVisibility(.hidden)` on iOS 26+,
/// eliminating the need for duplicated `if #available(iOS 26.0, *)` checks throughout the codebase.
///
/// - Usage:
/// ```swift
/// .toolbar {
/// ToolbarItem(placement: .navigationBarLeading) {
/// Button("Action") { }
/// }
/// .hideToolbarBackground()
/// }
/// ```
@available(iOS 15.0, *)
extension ToolbarContent {
/// Hides the toolbar background on iOS 26+, leaving it unchanged on earlier versions.
///
/// Apply this modifier to `ToolbarItem` views to suppress the shared background
/// visibility introduced in iOS 26 without duplicating version checks.
func hideToolbarBackground() -> some ToolbarContent {
if #available(iOS 26.0, *) {
return self.sharedBackgroundVisibility(.hidden)
} else {
return self
}
}
}