diff --git a/ApplicationLibrary/Views/Dashboard/Cards/ClashModeCard.swift b/ApplicationLibrary/Views/Dashboard/Cards/ClashModeCard.swift index f1c1c69..979e82e 100644 --- a/ApplicationLibrary/Views/Dashboard/Cards/ClashModeCard.swift +++ b/ApplicationLibrary/Views/Dashboard/Cards/ClashModeCard.swift @@ -14,19 +14,7 @@ public struct ClashModeCard: View { DashboardCardView(title: "", isHalfWidth: false) { VStack(alignment: .leading, spacing: 12) { DashboardCardHeader(icon: "circle.grid.2x2.fill", title: "Mode") - Picker("", selection: Binding(get: { - clashMode - }, set: { newMode in - clashMode = newMode - Task { - await setClashMode(newMode) - } - })) { - ForEach(commandClient.clashModeList, id: \.self) { mode in - Text(mode) - } - } - .pickerStyle(.segmented) + modeMenu } } .onAppear { @@ -39,6 +27,69 @@ public struct ClashModeCard: View { } } + private var modeMenu: some View { + Menu { + ForEach(commandClient.clashModeList, id: \.self) { mode in + Button { + clashMode = mode + Task { + await setClashMode(mode) + } + } label: { + if mode == clashMode { + Label(mode, systemImage: "checkmark") + } else { + Text(mode) + } + } + } + } label: { + HStack { + Text(clashMode) + .font(.system(size: buttonFontSize, weight: .medium)) + .foregroundStyle(.primary) + .lineLimit(1) + + Spacer() + + Image(systemName: "chevron.up.chevron.down") + .font(.system(size: chevronSize, weight: .semibold)) + .foregroundStyle(.secondary) + } + .padding(.horizontal, 14) + .frame(height: buttonHeight) + .contentShape(Rectangle()) + } + .buttonStyle(.plain) + .selectorBackground() + } + + private var buttonHeight: CGFloat { + #if os(tvOS) + 60 + #elseif os(macOS) + 32 + #else + 44 + #endif + } + + private var buttonFontSize: CGFloat { + #if os(macOS) + 13 + #else + 17 + #endif + } + + private var chevronSize: CGFloat { + #if os(macOS) + 10 + #else + 12 + #endif + } + private var shouldShowPicker: Bool { commandClient.clashModeList.count > 1 } diff --git a/ApplicationLibrary/Views/Dashboard/Cards/ProfileSelectorButton.swift b/ApplicationLibrary/Views/Dashboard/Cards/ProfileSelectorButton.swift index e92bb77..c2d5ac2 100644 --- a/ApplicationLibrary/Views/Dashboard/Cards/ProfileSelectorButton.swift +++ b/ApplicationLibrary/Views/Dashboard/Cards/ProfileSelectorButton.swift @@ -77,7 +77,7 @@ struct ProfileSelectorButton: View { // MARK: - View Extension -private extension View { +extension View { @ViewBuilder func selectorBackground() -> some View { if #available(iOS 26.0, macOS 26.0, tvOS 26.0, *) {