From fc30a2e9c71da277153f7a5f8edfd43dc4fe421e Mon Sep 17 00:00:00 2001 From: Graeme Arthur <2030310+graeme@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:06:27 +0100 Subject: [PATCH] Fix uninstall button selection state --- .../SubscriptionExpiredView.swift | 2 +- .../SwiftUIExtensions/ButtonStyles.swift | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/SubscriptionExpiredView/SubscriptionExpiredView.swift b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/SubscriptionExpiredView/SubscriptionExpiredView.swift index a4fe590b8e..666aed9e4f 100644 --- a/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/SubscriptionExpiredView/SubscriptionExpiredView.swift +++ b/LocalPackages/NetworkProtectionMac/Sources/NetworkProtectionUI/Views/SubscriptionExpiredView/SubscriptionExpiredView.swift @@ -49,7 +49,7 @@ struct SubscriptionExpiredView: View { .padding(.bottom, 3) Button(UserText.networkProtectionSubscriptionExpiredUninstallButton, action: uninstallButtonHandler) - .buttonStyle(.borderless) + .buttonStyle(TransparentActionButtonStyle(enabled: true)) .foregroundColor(.accentColor) .padding(.top, 3) } diff --git a/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/ButtonStyles.swift b/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/ButtonStyles.swift index 718f9b029d..e5c7c83424 100644 --- a/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/ButtonStyles.swift +++ b/LocalPackages/SwiftUIExtensions/Sources/SwiftUIExtensions/ButtonStyles.swift @@ -69,6 +69,34 @@ public struct DefaultActionButtonStyle: ButtonStyle { } } +public struct TransparentActionButtonStyle: ButtonStyle { + + public let enabled: Bool + + public init(enabled: Bool) { + self.enabled = enabled + } + + public func makeBody(configuration: Self.Configuration) -> some View { + + let enabledForegroundColor = configuration.isPressed ? Color(NSColor.controlAccentColor).opacity(0.5) : Color(NSColor.controlAccentColor) + let disabledForegroundColor = Color.gray.opacity(0.1) + + configuration.label + .font(.system(size: 13)) + .multilineTextAlignment(.center) + .fixedSize(horizontal: false, vertical: true) + .frame(minWidth: 44) // OK buttons will match the width of "Cancel" at least in English + .padding(.top, 2.5) + .padding(.bottom, 3) + .padding(.horizontal, 0) + .background(Color.clear) + .foregroundColor(enabled ? enabledForegroundColor : disabledForegroundColor) + .cornerRadius(5) + + } +} + public struct DismissActionButtonStyle: ButtonStyle { @Environment(\.colorScheme) var colorScheme