From 7c8863b53a754726f8c698484b41c62e3be3010b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 3 Dec 2025 19:54:32 +0800 Subject: [PATCH] Unify card background styles --- .../Views/Abstract/ViewModifiers.swift | 39 +++++++++++++++++++ .../Views/Connections/ConnectionView.swift | 15 +------ .../Dashboard/Cards/DashboardCardView.swift | 38 +----------------- .../Dashboard/Cards/ProfilePickerSheet.swift | 10 +++++ .../Views/Groups/GroupItemView.swift | 19 +-------- 5 files changed, 55 insertions(+), 66 deletions(-) diff --git a/ApplicationLibrary/Views/Abstract/ViewModifiers.swift b/ApplicationLibrary/Views/Abstract/ViewModifiers.swift index 217bac9..ed59fb9 100644 --- a/ApplicationLibrary/Views/Abstract/ViewModifiers.swift +++ b/ApplicationLibrary/Views/Abstract/ViewModifiers.swift @@ -56,3 +56,42 @@ public extension View { } } #endif + +public extension View { + @ViewBuilder + func cardStyle() -> some View { + modifier(CardStyleModifier()) + } +} + +private struct CardStyleModifier: ViewModifier { + @Environment(\.colorScheme) private var colorScheme + + func body(content: Content) -> some View { + if #available(iOS 26.0, macOS 26.0, tvOS 26.0, *) { + content + .glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16)) + } else { + content + .background(backgroundColor) + .cornerRadius(16) + } + } + + private var backgroundColor: Color { + #if os(iOS) + return Color(uiColor: .secondarySystemGroupedBackground) + #elseif os(macOS) + return Color(nsColor: .textBackgroundColor) + #elseif os(tvOS) + switch colorScheme { + case .dark: + return Color(uiColor: .black) + default: + return Color(uiColor: .white) + } + #else + return Color.clear + #endif + } +} diff --git a/ApplicationLibrary/Views/Connections/ConnectionView.swift b/ApplicationLibrary/Views/Connections/ConnectionView.swift index d799894..cc93c52 100644 --- a/ApplicationLibrary/Views/Connections/ConnectionView.swift +++ b/ApplicationLibrary/Views/Connections/ConnectionView.swift @@ -76,9 +76,8 @@ public struct ConnectionView: View { } .foregroundColor(.textColor) #if !os(tvOS) - .padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13)) - .background(backgroundColor) - .cornerRadius(10) + .padding(16) + .cardStyle() #endif } .background(.clear) @@ -99,16 +98,6 @@ public struct ConnectionView: View { } } - private var backgroundColor: Color { - #if os(iOS) - return Color(uiColor: .secondarySystemGroupedBackground) - #elseif os(macOS) - return Color(nsColor: .textBackgroundColor) - #elseif os(tvOS) - return Color.black - #endif - } - private nonisolated func closeConnection() async { do { try await LibboxNewStandaloneCommandClient()!.closeConnection(connection.id) diff --git a/ApplicationLibrary/Views/Dashboard/Cards/DashboardCardView.swift b/ApplicationLibrary/Views/Dashboard/Cards/DashboardCardView.swift index 7da35e5..d4b7608 100644 --- a/ApplicationLibrary/Views/Dashboard/Cards/DashboardCardView.swift +++ b/ApplicationLibrary/Views/Dashboard/Cards/DashboardCardView.swift @@ -1,8 +1,6 @@ import SwiftUI public struct DashboardCardView: View { - @Environment(\.colorScheme) private var colorScheme - private let title: String private let isHalfWidth: Bool @ViewBuilder private let content: () -> Content @@ -26,40 +24,8 @@ public struct DashboardCardView: View { #if os(tvOS) .padding(EdgeInsets(top: 20, leading: 26, bottom: 20, trailing: 26)) #else - .padding(EdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)) - #endif - .modifier(CardStyleModifier(colorScheme: colorScheme)) - } -} - -private struct CardStyleModifier: ViewModifier { - let colorScheme: ColorScheme - - func body(content: Content) -> some View { - if #available(iOS 26.0, macOS 26.0, tvOS 26.0, *) { - content - .glassEffect(.regular.interactive(), in: .rect(cornerRadius: 16)) - } else { - content - .background(backgroundColor) - .cornerRadius(16) - } - } - - private var backgroundColor: Color { - #if os(iOS) - return Color(uiColor: .secondarySystemGroupedBackground) - #elseif os(macOS) - return Color(nsColor: .textBackgroundColor) - #elseif os(tvOS) - switch colorScheme { - case .dark: - return Color(uiColor: .black) - default: - return Color(uiColor: .white) - } - #else - return Color.clear + .padding(16) #endif + .cardStyle() } } diff --git a/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift b/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift index a3e9b08..da1d89d 100644 --- a/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift +++ b/ApplicationLibrary/Views/Dashboard/Cards/ProfilePickerSheet.swift @@ -183,8 +183,12 @@ struct ProfilePickerSheet: View { List { ForEach(profileList, id: \.id) { profile in macOSProfileRow(profile) + .listRowBackground(Color.clear) + .listRowSeparator(.hidden) + .listRowInsets(EdgeInsets(top: 6, leading: 16, bottom: 6, trailing: 16)) } } + .listStyle(.plain) #else List { ForEach(profileList, id: \.id) { profile in @@ -204,10 +208,14 @@ struct ProfilePickerSheet: View { } ) .environmentObject(environments) + .listRowBackground(Color.clear) + .listRowSeparator(.hidden) + .listRowInsets(EdgeInsets(top: 6, leading: 16, bottom: 6, trailing: 16)) } .onMove(perform: moveProfile) .onDelete(perform: deleteProfile) } + .listStyle(.plain) #endif } @@ -623,6 +631,8 @@ private struct ProfilePickerRow: View { } } .contentShape(Rectangle()) + .padding(16) + .cardStyle() } #endif diff --git a/ApplicationLibrary/Views/Groups/GroupItemView.swift b/ApplicationLibrary/Views/Groups/GroupItemView.swift index 2bc9ea6..f27b7b1 100644 --- a/ApplicationLibrary/Views/Groups/GroupItemView.swift +++ b/ApplicationLibrary/Views/Groups/GroupItemView.swift @@ -57,23 +57,8 @@ public struct GroupItemView: View { } #if !os(tvOS) .buttonStyle(.borderless) - .padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13)) - .background(backgroundColor) - .cornerRadius(10) - .overlay( - RoundedRectangle(cornerRadius: 10) - .stroke(Color.gray.opacity(0.3), lineWidth: 1) - ) - #endif - } - - private var backgroundColor: Color { - #if os(iOS) - return Color(uiColor: .secondarySystemGroupedBackground) - #elseif os(macOS) - return Color(nsColor: .textBackgroundColor) - #elseif os(tvOS) - return Color.black + .padding(16) + .cardStyle() #endif } }