mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 16:26:04 +00:00
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
//
|
||
// View+Extras.swift
|
||
// NetNewsWire-iOS
|
||
//
|
||
// Created by Brent Simmons on 10/8/26.
|
||
//
|
||
|
||
import SwiftUI
|
||
|
||
extension View {
|
||
|
||
/// Shows an Error alert with an OK button while `message` is non-nil. Dismissing the alert sets `message` to nil.
|
||
func errorAlert(message: Binding<String?>) -> some View {
|
||
let isPresented = Binding {
|
||
message.wrappedValue != nil
|
||
} set: { isShowing in
|
||
if !isShowing {
|
||
message.wrappedValue = nil
|
||
}
|
||
}
|
||
|
||
return alert(NSLocalizedString("Error", comment: "Error"), isPresented: isPresented) {
|
||
Button(NSLocalizedString("OK", comment: "OK button")) {
|
||
message.wrappedValue = nil
|
||
}
|
||
} message: {
|
||
Text(verbatim: message.wrappedValue ?? "")
|
||
}
|
||
}
|
||
|
||
/// Gives Settings switches the app’s accent color, matching the rest of the app’s switches.
|
||
func settingsToggleTint() -> some View {
|
||
tint(Color(uiColor: Assets.Colors.primaryAccent))
|
||
}
|
||
|
||
/// A pop-up menu showing the current choice in secondary text, rather than in the accent color.
|
||
func settingsMenuPickerStyle() -> some View {
|
||
pickerStyle(.menu)
|
||
.tint(Color(uiColor: .secondaryLabel))
|
||
}
|
||
}
|