mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Improved Timer UI, removed the Tab
This commit is contained in:
parent
d7c8b1ef61
commit
a9f9ac3aa8
14 changed files with 1079 additions and 241 deletions
|
|
@ -34,26 +34,36 @@ struct InlineHUD: View {
|
|||
|
||||
let baseInfoWidth: CGFloat = {
|
||||
if type == .bluetoothAudio {
|
||||
return showBluetoothDeviceNameMarquee ? 100 : 52
|
||||
return showBluetoothDeviceNameMarquee ? 140 : 88
|
||||
}
|
||||
return 100
|
||||
}()
|
||||
let infoWidth = baseInfoWidth - (hoverAnimation ? 0 : 12) + gestureProgress / 2
|
||||
let infoWidth: CGFloat = {
|
||||
var width = baseInfoWidth + gestureProgress / 2
|
||||
if !hoverAnimation { width -= 8 }
|
||||
let minimum: CGFloat = type == .bluetoothAudio ? (showBluetoothDeviceNameMarquee ? 120 : 82) : 88
|
||||
return max(width, minimum)
|
||||
}()
|
||||
let baseTrailingWidth: CGFloat = {
|
||||
if type == .bluetoothAudio {
|
||||
if !hasBatteryLevel {
|
||||
return showBluetoothDeviceNameMarquee ? 100 : 70
|
||||
return showBluetoothDeviceNameMarquee ? 118 : 88
|
||||
}
|
||||
|
||||
if useCircularIndicator {
|
||||
return showBluetoothBatteryPercentageText ? 100 : 70
|
||||
return showBluetoothBatteryPercentageText ? 120 : 96
|
||||
} else {
|
||||
return showBluetoothBatteryPercentageText ? 112 : 82
|
||||
return showBluetoothBatteryPercentageText ? 136 : 108
|
||||
}
|
||||
}
|
||||
return 100
|
||||
}()
|
||||
let trailingWidth = baseTrailingWidth - (hoverAnimation ? 0 : 12) + gestureProgress / 2
|
||||
let trailingWidth: CGFloat = {
|
||||
var width = baseTrailingWidth + gestureProgress / 2
|
||||
if !hoverAnimation { width -= 8 }
|
||||
let minimum: CGFloat = type == .bluetoothAudio ? (showBluetoothBatteryPercentageText ? 110 : 92) : 90
|
||||
return max(width, minimum)
|
||||
}()
|
||||
|
||||
return HStack {
|
||||
HStack(spacing: 5) {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,11 @@ struct DynamicIslandHeader: View {
|
|||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@ObservedObject var clipboardManager = ClipboardManager.shared
|
||||
@ObservedObject var tvm = TrayDrop.shared
|
||||
@ObservedObject var timerManager = TimerManager.shared
|
||||
@State private var showClipboardPopover = false
|
||||
@State private var showColorPickerPopover = false
|
||||
@State private var showTimerPopover = false
|
||||
@Default(.enableTimerFeature) var enableTimerFeature
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
|
|
@ -141,6 +144,36 @@ struct DynamicIslandHeader: View {
|
|||
}
|
||||
}
|
||||
|
||||
if Defaults[.enableTimerFeature] {
|
||||
Button(action: {
|
||||
withAnimation(.smooth) {
|
||||
showTimerPopover.toggle()
|
||||
}
|
||||
}) {
|
||||
Capsule()
|
||||
.fill(.black)
|
||||
.frame(width: 30, height: 30)
|
||||
.overlay {
|
||||
Image(systemName: "timer")
|
||||
.foregroundColor(.white)
|
||||
.padding()
|
||||
.imageScale(.medium)
|
||||
}
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
.popover(isPresented: $showTimerPopover, arrowEdge: .bottom) {
|
||||
TimerPopover()
|
||||
}
|
||||
.onChange(of: showTimerPopover) { isActive in
|
||||
vm.isTimerPopoverActive = isActive
|
||||
if !isActive {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
||||
vm.shouldRecheckHover.toggle()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if Defaults[.settingsIconInNotch] {
|
||||
Button(action: {
|
||||
SettingsWindowController.shared.showWindow()
|
||||
|
|
@ -204,6 +237,12 @@ struct DynamicIslandHeader: View {
|
|||
showClipboardPopover.toggle()
|
||||
}
|
||||
}
|
||||
.onChange(of: enableTimerFeature) { _, newValue in
|
||||
if !newValue {
|
||||
showTimerPopover = false
|
||||
vm.isTimerPopoverActive = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1709,9 +1709,17 @@ func warningBadge(_ text: String, _ description: String) -> some View {
|
|||
struct TimerSettings: View {
|
||||
@ObservedObject private var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@Default(.enableTimerFeature) var enableTimerFeature
|
||||
@AppStorage("customTimerDuration") private var customTimerDuration: Double = 600 // 10 minutes default
|
||||
@Default(.timerPresets) private var timerPresets
|
||||
@Default(.timerIconColorMode) private var colorMode
|
||||
@Default(.timerSolidColor) private var solidColor
|
||||
@Default(.timerShowsCountdown) private var showsCountdown
|
||||
@Default(.timerShowsProgress) private var showsProgress
|
||||
@Default(.timerProgressStyle) private var progressStyle
|
||||
@AppStorage("customTimerDuration") private var customTimerDuration: Double = 600
|
||||
@State private var customHours: Int = 0
|
||||
@State private var customMinutes: Int = 10
|
||||
@State private var customSeconds: Int = 0
|
||||
@State private var showingResetConfirmation = false
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
|
|
@ -1719,92 +1727,121 @@ struct TimerSettings: View {
|
|||
Defaults.Toggle("Enable timer feature", key: .enableTimerFeature)
|
||||
|
||||
if enableTimerFeature {
|
||||
Toggle(
|
||||
"Enable timer live activity",
|
||||
isOn: $coordinator.timerLiveActivityEnabled
|
||||
)
|
||||
.animation(.easeInOut, value: coordinator.timerLiveActivityEnabled)
|
||||
Toggle("Enable timer live activity", isOn: $coordinator.timerLiveActivityEnabled)
|
||||
.animation(.easeInOut, value: coordinator.timerLiveActivityEnabled)
|
||||
}
|
||||
} header: {
|
||||
Text("Timer Feature")
|
||||
} footer: {
|
||||
Text("Enable or disable the timer functionality in the Dynamic Island. The live activity toggle controls whether timer progress is shown in the expanded view.")
|
||||
Text("Control timer availability and whether progress appears as a live activity while the notch is closed.")
|
||||
}
|
||||
|
||||
if enableTimerFeature {
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
Text("Custom Timer Duration")
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Default Custom Timer")
|
||||
.font(.headline)
|
||||
|
||||
HStack(spacing: 20) {
|
||||
VStack(alignment: .center, spacing: 8) {
|
||||
Text("Minutes")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Picker(selection: $customMinutes, label: Text("Minutes")) {
|
||||
ForEach(0...59, id: \.self) { minute in
|
||||
Text("\(minute)").tag(minute)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.frame(width: 100)
|
||||
}
|
||||
|
||||
VStack(alignment: .center, spacing: 8) {
|
||||
Text("Seconds")
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Picker(selection: $customSeconds, label: Text("Seconds")) {
|
||||
ForEach(0...59, id: \.self) { second in
|
||||
Text("\(second)").tag(second)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.menu)
|
||||
.frame(width: 100)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
TimerDurationStepperRow(title: "Hours", value: $customHours, range: 0...23)
|
||||
TimerDurationStepperRow(title: "Minutes", value: $customMinutes, range: 0...59)
|
||||
TimerDurationStepperRow(title: "Seconds", value: $customSeconds, range: 0...59)
|
||||
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Text("Current custom timer:")
|
||||
.foregroundStyle(.secondary)
|
||||
Text(customTimerDisplayText)
|
||||
.foregroundStyle(.primary)
|
||||
.fontWeight(.medium)
|
||||
Spacer()
|
||||
}
|
||||
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Update Timer") {
|
||||
customTimerDuration = Double(customMinutes * 60 + customSeconds)
|
||||
}
|
||||
.disabled(customMinutes == 0 && customSeconds == 0)
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
HStack {
|
||||
Text("Current default:")
|
||||
.foregroundStyle(.secondary)
|
||||
Text(customDurationDisplay)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.fontWeight(.medium)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
.padding(.vertical, 4)
|
||||
.onChange(of: customHours) { _, _ in updateCustomDuration() }
|
||||
.onChange(of: customMinutes) { _, _ in updateCustomDuration() }
|
||||
.onChange(of: customSeconds) { _, _ in updateCustomDuration() }
|
||||
} header: {
|
||||
Text("Custom Timer")
|
||||
} footer: {
|
||||
Text("Set a custom duration for the timer. This will be used when you press the 'Custom' button in the timer interface.")
|
||||
Text("This duration powers the \"Custom\" option inside the timer popover for quick access.")
|
||||
}
|
||||
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Picker("Timer tint", selection: $colorMode) {
|
||||
ForEach(TimerIconColorMode.allCases) { mode in
|
||||
Text(mode.displayName).tag(mode)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
|
||||
if colorMode == .solid {
|
||||
ColorPicker("Solid colour", selection: $solidColor, supportsOpacity: false)
|
||||
}
|
||||
|
||||
Toggle("Show countdown", isOn: $showsCountdown)
|
||||
Toggle("Show progress", isOn: $showsProgress)
|
||||
|
||||
Picker("Progress style", selection: $progressStyle) {
|
||||
ForEach(TimerProgressStyle.allCases) { style in
|
||||
Text(style.rawValue).tag(style)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.disabled(!showsProgress)
|
||||
} header: {
|
||||
Text("Appearance")
|
||||
} footer: {
|
||||
Text("Configure how the timer looks inside the closed notch. Progress can render as a ring around the icon or as horizontal bars.")
|
||||
}
|
||||
|
||||
Section {
|
||||
if timerPresets.isEmpty {
|
||||
Text("No presets configured. Add a preset to make it appear in the timer popover.")
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(.secondary)
|
||||
.padding(.vertical, 4)
|
||||
} else {
|
||||
ForEach(timerPresets.indices, id: \.self) { index in
|
||||
TimerPresetEditorRow(
|
||||
preset: $timerPresets[index],
|
||||
isFirst: index == timerPresets.startIndex,
|
||||
isLast: index == timerPresets.index(before: timerPresets.endIndex),
|
||||
moveUp: { movePresetUp(index) },
|
||||
moveDown: { movePresetDown(index) },
|
||||
remove: { removePreset(index) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
HStack {
|
||||
Button(action: addPreset) {
|
||||
Label("Add Preset", systemImage: "plus")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(role: .destructive, action: { showingResetConfirmation = true }) {
|
||||
Label("Restore Defaults", systemImage: "arrow.counterclockwise")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.confirmationDialog("Restore default timer presets?", isPresented: $showingResetConfirmation, titleVisibility: .visible) {
|
||||
Button("Restore", role: .destructive, action: resetPresets)
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
Text("Timer Presets")
|
||||
} footer: {
|
||||
Text("Presets show up inside the timer popover with the configured name, duration, and accent colour. Reorder them to change the display order.")
|
||||
}
|
||||
|
||||
Section {
|
||||
VStack(alignment: .leading, spacing: 10) {
|
||||
HStack {
|
||||
Text("Timer Sound")
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
Spacer()
|
||||
Button("Choose File") {
|
||||
selectCustomTimerSound()
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
Button("Choose File", action: selectCustomTimerSound)
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
|
||||
if let customTimerSoundPath = UserDefaults.standard.string(forKey: "customTimerSoundPath") {
|
||||
|
|
@ -1826,30 +1863,68 @@ struct TimerSettings: View {
|
|||
} header: {
|
||||
Text("Timer Sound")
|
||||
} footer: {
|
||||
Text("Choose a custom sound file that will play when the timer completes. Supported formats: MP3, M4A, WAV, AIFF.")
|
||||
Text("Select a custom sound to play when a timer ends. Supported formats include MP3, M4A, WAV, and AIFF.")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Timer")
|
||||
.onAppear {
|
||||
let totalMinutes = Int(customTimerDuration) / 60
|
||||
customMinutes = totalMinutes
|
||||
customSeconds = Int(customTimerDuration) % 60
|
||||
.onAppear { syncCustomDuration() }
|
||||
.onChange(of: customTimerDuration) { _, newValue in syncCustomDuration(newValue) }
|
||||
}
|
||||
|
||||
private var customDurationDisplay: String {
|
||||
let formatter = DateComponentsFormatter()
|
||||
formatter.allowedUnits = customTimerDuration >= 3600 ? [.hour, .minute, .second] : [.minute, .second]
|
||||
formatter.zeroFormattingBehavior = [.pad]
|
||||
return formatter.string(from: customTimerDuration) ?? "0:00"
|
||||
}
|
||||
|
||||
private func syncCustomDuration(_ value: Double? = nil) {
|
||||
let baseValue = value ?? customTimerDuration
|
||||
let components = TimerPreset.components(for: baseValue)
|
||||
customHours = components.hours
|
||||
customMinutes = components.minutes
|
||||
customSeconds = components.seconds
|
||||
}
|
||||
|
||||
private func updateCustomDuration() {
|
||||
let duration = TimeInterval(customHours * 3600 + customMinutes * 60 + customSeconds)
|
||||
customTimerDuration = duration
|
||||
}
|
||||
|
||||
private func addPreset() {
|
||||
let nextIndex = timerPresets.count + 1
|
||||
let defaultColor = Defaults[.accentColor]
|
||||
let newPreset = TimerPreset(name: "Preset \(nextIndex)", duration: 5 * 60, color: defaultColor)
|
||||
withAnimation(.smooth) {
|
||||
timerPresets.append(newPreset)
|
||||
}
|
||||
}
|
||||
|
||||
private var customTimerDisplayText: String {
|
||||
let totalMinutes = Int(customTimerDuration) / 60
|
||||
let seconds = Int(customTimerDuration) % 60
|
||||
let hours = totalMinutes / 60
|
||||
let minutes = totalMinutes % 60
|
||||
|
||||
if hours > 0 {
|
||||
return "\(hours):\(String(format: "%02d", minutes)):\(String(format: "%02d", seconds))"
|
||||
} else if minutes > 0 {
|
||||
return "\(minutes):\(String(format: "%02d", seconds))"
|
||||
} else {
|
||||
return "\(seconds)s"
|
||||
private func movePresetUp(_ index: Int) {
|
||||
guard index > timerPresets.startIndex else { return }
|
||||
withAnimation(.smooth) {
|
||||
timerPresets.swapAt(index, index - 1)
|
||||
}
|
||||
}
|
||||
|
||||
private func movePresetDown(_ index: Int) {
|
||||
guard index < timerPresets.index(before: timerPresets.endIndex) else { return }
|
||||
withAnimation(.smooth) {
|
||||
timerPresets.swapAt(index, index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
private func removePreset(_ index: Int) {
|
||||
guard timerPresets.indices.contains(index) else { return }
|
||||
withAnimation(.smooth) {
|
||||
timerPresets.remove(at: index)
|
||||
}
|
||||
}
|
||||
|
||||
private func resetPresets() {
|
||||
withAnimation(.smooth) {
|
||||
timerPresets = TimerPreset.defaultPresets
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1869,6 +1944,146 @@ struct TimerSettings: View {
|
|||
}
|
||||
}
|
||||
|
||||
private struct TimerDurationStepperRow: View {
|
||||
let title: String
|
||||
@Binding var value: Int
|
||||
let range: ClosedRange<Int>
|
||||
|
||||
var body: some View {
|
||||
Stepper(value: $value, in: range) {
|
||||
HStack {
|
||||
Text(title)
|
||||
Spacer()
|
||||
Text("\(value)")
|
||||
.font(.system(size: 12, weight: .semibold, design: .monospaced))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct TimerPresetEditorRow: View {
|
||||
@Binding var preset: TimerPreset
|
||||
let isFirst: Bool
|
||||
let isLast: Bool
|
||||
let moveUp: () -> Void
|
||||
let moveDown: () -> Void
|
||||
let remove: () -> Void
|
||||
|
||||
private var components: TimerPreset.DurationComponents {
|
||||
TimerPreset.components(for: preset.duration)
|
||||
}
|
||||
|
||||
private var hoursBinding: Binding<Int> {
|
||||
Binding(
|
||||
get: { components.hours },
|
||||
set: { updateDuration(hours: $0) }
|
||||
)
|
||||
}
|
||||
|
||||
private var minutesBinding: Binding<Int> {
|
||||
Binding(
|
||||
get: { components.minutes },
|
||||
set: { updateDuration(minutes: $0) }
|
||||
)
|
||||
}
|
||||
|
||||
private var secondsBinding: Binding<Int> {
|
||||
Binding(
|
||||
get: { components.seconds },
|
||||
set: { updateDuration(seconds: $0) }
|
||||
)
|
||||
}
|
||||
|
||||
private var colorBinding: Binding<Color> {
|
||||
Binding(
|
||||
get: { preset.color },
|
||||
set: { preset.updateColor($0) }
|
||||
)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
HStack(spacing: 10) {
|
||||
Circle()
|
||||
.fill(preset.color.gradient)
|
||||
.frame(width: 20, height: 20)
|
||||
.overlay(
|
||||
Circle()
|
||||
.stroke(Color.white.opacity(0.3), lineWidth: 1)
|
||||
)
|
||||
|
||||
TextField("Preset name", text: $preset.name)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
|
||||
Spacer()
|
||||
|
||||
Text(preset.formattedDuration)
|
||||
.font(.system(size: 12, weight: .medium, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
HStack(spacing: 16) {
|
||||
TimerPresetComponentControl(title: "Hours", value: hoursBinding, range: 0...23)
|
||||
TimerPresetComponentControl(title: "Minutes", value: minutesBinding, range: 0...59)
|
||||
TimerPresetComponentControl(title: "Seconds", value: secondsBinding, range: 0...59)
|
||||
}
|
||||
|
||||
ColorPicker("Accent colour", selection: colorBinding, supportsOpacity: false)
|
||||
.frame(maxWidth: 240, alignment: .leading)
|
||||
|
||||
HStack(spacing: 12) {
|
||||
Button(action: moveUp) {
|
||||
Label("Move Up", systemImage: "chevron.up")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.disabled(isFirst)
|
||||
|
||||
Button(action: moveDown) {
|
||||
Label("Move Down", systemImage: "chevron.down")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.disabled(isLast)
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(role: .destructive, action: remove) {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
}
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
}
|
||||
.padding(.vertical, 6)
|
||||
}
|
||||
|
||||
private func updateDuration(hours: Int? = nil, minutes: Int? = nil, seconds: Int? = nil) {
|
||||
var values = components
|
||||
if let hours { values.hours = hours }
|
||||
if let minutes { values.minutes = minutes }
|
||||
if let seconds { values.seconds = seconds }
|
||||
preset.duration = TimerPreset.duration(from: values)
|
||||
}
|
||||
}
|
||||
|
||||
private struct TimerPresetComponentControl: View {
|
||||
let title: String
|
||||
@Binding var value: Int
|
||||
let range: ClosedRange<Int>
|
||||
|
||||
var body: some View {
|
||||
Stepper(value: $value, in: range) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(title)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
Text("\(value)")
|
||||
.font(.system(size: 13, weight: .semibold, design: .monospaced))
|
||||
}
|
||||
}
|
||||
.frame(width: 110, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
struct StatsSettings: View {
|
||||
@ObservedObject var statsManager = StatsManager.shared
|
||||
@Default(.enableStatsFeature) var enableStatsFeature
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ struct TabModel: Identifiable {
|
|||
|
||||
struct TabSelectionView: View {
|
||||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@Default(.enableTimerFeature) var enableTimerFeature
|
||||
@Default(.enableStatsFeature) var enableStatsFeature
|
||||
@Default(.enableColorPickerFeature) var enableColorPickerFeature
|
||||
@Namespace var animation
|
||||
|
|
@ -29,11 +28,6 @@ struct TabSelectionView: View {
|
|||
|
||||
tabsArray.append(TabModel(label: "Shelf", icon: "tray.fill", view: .shelf))
|
||||
|
||||
// Timer tab only shown when timer feature is enabled
|
||||
if Defaults[.enableTimerFeature] {
|
||||
tabsArray.append(TabModel(label: "Timer", icon: "timer", view: .timer))
|
||||
}
|
||||
|
||||
// Stats tab only shown when stats feature is enabled
|
||||
if Defaults[.enableStatsFeature] {
|
||||
tabsArray.append(TabModel(label: "Stats", icon: "chart.xyaxis.line", view: .stats))
|
||||
|
|
|
|||
|
|
@ -6,95 +6,25 @@
|
|||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import Defaults
|
||||
|
||||
struct TimerIconAnimation: View {
|
||||
@ObservedObject var timerManager = TimerManager.shared
|
||||
@State private var pulseScale: CGFloat = 1.0
|
||||
@State private var rotationAngle: Double = 0
|
||||
@Default(.accentColor) private var accentColor
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// Background circle with timer color
|
||||
Circle()
|
||||
.fill(timerManager.timerColor.gradient)
|
||||
.fill(accentColor.gradient)
|
||||
.frame(width: 24, height: 24)
|
||||
.scaleEffect(pulseScale)
|
||||
.animation(
|
||||
timerManager.isTimerActive && !timerManager.isPaused
|
||||
? .easeInOut(duration: 1.0).repeatForever(autoreverses: true)
|
||||
: .easeInOut(duration: 0.3),
|
||||
value: pulseScale
|
||||
)
|
||||
|
||||
// Timer icon
|
||||
Image(systemName: "timer")
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundColor(.white)
|
||||
.rotationEffect(.degrees(rotationAngle))
|
||||
.animation(
|
||||
timerManager.isTimerActive && !timerManager.isPaused
|
||||
? .linear(duration: 2.0).repeatForever(autoreverses: false)
|
||||
: .easeInOut(duration: 0.3),
|
||||
value: rotationAngle
|
||||
)
|
||||
|
||||
// Progress ring
|
||||
Circle()
|
||||
.trim(from: 0, to: timerManager.progress)
|
||||
.stroke(
|
||||
Color.white.opacity(0.8),
|
||||
style: StrokeStyle(lineWidth: 2, lineCap: .round)
|
||||
)
|
||||
.frame(width: 26, height: 26)
|
||||
.rotationEffect(.degrees(-90)) // Start from top
|
||||
.animation(.easeInOut(duration: 0.5), value: timerManager.progress)
|
||||
}
|
||||
.onAppear {
|
||||
startAnimations()
|
||||
}
|
||||
.onChange(of: timerManager.isTimerActive) { _, isActive in
|
||||
if isActive {
|
||||
startAnimations()
|
||||
} else {
|
||||
stopAnimations()
|
||||
}
|
||||
}
|
||||
.onChange(of: timerManager.isPaused) { _, isPaused in
|
||||
if isPaused {
|
||||
stopAnimations()
|
||||
} else if timerManager.isTimerActive {
|
||||
startAnimations()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func startAnimations() {
|
||||
guard timerManager.isTimerActive && !timerManager.isPaused else { return }
|
||||
|
||||
// Start pulsing
|
||||
pulseScale = 1.1
|
||||
|
||||
// Start rotation
|
||||
withAnimation(.linear(duration: 2.0).repeatForever(autoreverses: false)) {
|
||||
rotationAngle = 360
|
||||
}
|
||||
}
|
||||
|
||||
private func stopAnimations() {
|
||||
// Stop pulsing
|
||||
pulseScale = 1.0
|
||||
|
||||
// Stop rotation
|
||||
withAnimation(.easeInOut(duration: 0.3)) {
|
||||
rotationAngle = 0
|
||||
.foregroundStyle(.white)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct TimerIconView: NSViewRepresentable {
|
||||
@ObservedObject var timerManager = TimerManager.shared
|
||||
|
||||
func makeNSView(context: Context) -> NSView {
|
||||
let hostingView = NSHostingView(rootView: TimerIconAnimation())
|
||||
hostingView.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
|
|
|||
|
|
@ -10,63 +10,147 @@ import Defaults
|
|||
|
||||
struct TimerLiveActivity: View {
|
||||
@EnvironmentObject var vm: DynamicIslandViewModel
|
||||
@ObservedObject var coordinator = DynamicIslandViewCoordinator.shared
|
||||
@ObservedObject var timerManager = TimerManager.shared
|
||||
@State private var isHovering: Bool = false
|
||||
@State private var gestureProgress: CGFloat = 0
|
||||
@Default(.timerShowsCountdown) private var showsCountdown
|
||||
@Default(.timerShowsProgress) private var showsProgress
|
||||
@Default(.timerProgressStyle) private var progressStyle
|
||||
@Default(.timerIconColorMode) private var colorMode
|
||||
@Default(.timerSolidColor) private var solidColor
|
||||
@Default(.timerPresets) private var timerPresets
|
||||
|
||||
private var iconAreaWidth: CGFloat {
|
||||
max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12))
|
||||
}
|
||||
|
||||
private var countdownWidth: CGFloat {
|
||||
guard showsCountdown else { return 0 }
|
||||
let characters = max(timerManager.formattedRemainingTime().count, 4)
|
||||
let base = CGFloat(characters) * 9.5 + 24
|
||||
return max(base, 72)
|
||||
}
|
||||
|
||||
private var clampedProgress: Double {
|
||||
min(max(timerManager.progress, 0), 1)
|
||||
}
|
||||
|
||||
private var glyphColor: Color {
|
||||
switch colorMode {
|
||||
case .adaptive:
|
||||
return activePresetColor ?? timerManager.timerColor
|
||||
case .solid:
|
||||
return solidColor
|
||||
}
|
||||
}
|
||||
|
||||
private var showsRingProgress: Bool {
|
||||
showsProgress && progressStyle == .ring
|
||||
}
|
||||
|
||||
private var showsBarProgress: Bool {
|
||||
showsProgress && progressStyle == .bar
|
||||
}
|
||||
|
||||
private var activePresetColor: Color? {
|
||||
guard let presetId = timerManager.activePresetId else { return nil }
|
||||
return timerPresets.first { $0.id == presetId }?.color
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
// Left side - Timer icon animation
|
||||
timerIconSection
|
||||
|
||||
// Center - Expandable timer info (similar to music banner)
|
||||
timerInfoSection
|
||||
|
||||
// Right side - Timer countdown text
|
||||
timerCountdownSection
|
||||
HStack(spacing: 10) {
|
||||
iconSection
|
||||
infoSection
|
||||
if showsRingProgress {
|
||||
ringSection
|
||||
}
|
||||
if showsCountdown {
|
||||
countdownSection
|
||||
}
|
||||
}
|
||||
.frame(height: vm.effectiveClosedNotchHeight + (isHovering ? 8 : 0), alignment: .center)
|
||||
}
|
||||
|
||||
private var timerIconSection: some View {
|
||||
HStack {
|
||||
// Simple timer icon with color, no background circle or animations
|
||||
Image(systemName: "timer")
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.foregroundStyle(timerManager.timerColor)
|
||||
.frame(width: 24, height: 24)
|
||||
.frame(width: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12) + gestureProgress / 2),
|
||||
height: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12)), alignment: .center)
|
||||
.contentShape(Rectangle())
|
||||
.onHover { hovering in
|
||||
withAnimation(.smooth(duration: 0.18)) {
|
||||
isHovering = hovering
|
||||
}
|
||||
}
|
||||
.frame(width: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12) + gestureProgress / 2),
|
||||
height: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12)))
|
||||
}
|
||||
|
||||
private var timerInfoSection: some View {
|
||||
private var iconSection: some View {
|
||||
let iconSize = max(20, iconAreaWidth - 4)
|
||||
return Image(systemName: "timer")
|
||||
.font(.system(size: 16, weight: .semibold))
|
||||
.foregroundStyle(glyphColor)
|
||||
.frame(width: iconSize, height: iconSize)
|
||||
.frame(width: iconAreaWidth, height: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12)), alignment: .center)
|
||||
}
|
||||
|
||||
private var infoSection: some View {
|
||||
Rectangle()
|
||||
.fill(.black)
|
||||
.overlay(
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
if timerManager.isFinished || timerManager.isOvertime {
|
||||
GeometryReader { geo in
|
||||
MarqueeText(
|
||||
.constant(timerManager.timerName),
|
||||
textColor: .white,
|
||||
minDuration: 0.25,
|
||||
frameWidth: geo.size.width - 12
|
||||
)
|
||||
}
|
||||
.frame(height: 16)
|
||||
} else {
|
||||
Text(timerManager.timerName)
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.lineLimit(1)
|
||||
.foregroundStyle(.white)
|
||||
.transition(.opacity.combined(with: .move(edge: .top)))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 6)
|
||||
.animation(.smooth, value: timerManager.isFinished)
|
||||
)
|
||||
.frame(width: vm.closedNotchSize.width + (isHovering ? 8 : 0))
|
||||
}
|
||||
|
||||
private var timerCountdownSection: some View {
|
||||
HStack {
|
||||
VStack(spacing: 2) {
|
||||
// Remaining time
|
||||
Text(timerManager.formattedRemainingTime())
|
||||
.font(.system(size: 11, weight: .medium, design: .monospaced))
|
||||
.foregroundColor(timerManager.isOvertime ? .red : .white)
|
||||
|
||||
// Progress indicator
|
||||
if timerManager.totalDuration > 0 {
|
||||
ProgressView(value: timerManager.progress)
|
||||
.progressViewStyle(LinearProgressViewStyle(tint: timerManager.timerColor))
|
||||
.frame(width: 30, height: 2)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
private var ringSection: some View {
|
||||
ZStack {
|
||||
Circle()
|
||||
.stroke(Color.white.opacity(0.15), lineWidth: 3)
|
||||
Circle()
|
||||
.trim(from: 0, to: clampedProgress)
|
||||
.stroke(glyphColor, style: StrokeStyle(lineWidth: 3, lineCap: .round))
|
||||
.rotationEffect(.degrees(-90))
|
||||
.animation(.smooth(duration: 0.25), value: clampedProgress)
|
||||
}
|
||||
.frame(width: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12) + gestureProgress / 2),
|
||||
.frame(width: 26, height: 26)
|
||||
}
|
||||
|
||||
private var countdownSection: some View {
|
||||
VStack(spacing: 4) {
|
||||
Text(timerManager.formattedRemainingTime())
|
||||
.font(.system(size: 13, weight: .semibold, design: .monospaced))
|
||||
.foregroundColor(timerManager.isOvertime ? .red : .white)
|
||||
.contentTransition(.numericText())
|
||||
.animation(.smooth(duration: 0.25), value: timerManager.remainingTime)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
|
||||
if showsBarProgress {
|
||||
Capsule()
|
||||
.fill(Color.white.opacity(0.12))
|
||||
.frame(height: 3)
|
||||
.overlay(alignment: .leading) {
|
||||
Capsule()
|
||||
.fill(glyphColor)
|
||||
.frame(width: max(0, countdownWidth - 20) * max(0, CGFloat(clampedProgress)))
|
||||
.animation(.smooth(duration: 0.25), value: clampedProgress)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.trailing, 8)
|
||||
.frame(width: countdownWidth,
|
||||
height: max(0, vm.effectiveClosedNotchHeight - (isHovering ? 0 : 12)), alignment: .center)
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +161,6 @@ struct TimerLiveActivity: View {
|
|||
.frame(width: 300, height: 32)
|
||||
.background(.black)
|
||||
.onAppear {
|
||||
// Start a demo timer for preview
|
||||
TimerManager.shared.startDemoTimer(duration: 300)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
362
DynamicIsland/components/Timer/TimerPopover.swift
Normal file
362
DynamicIsland/components/Timer/TimerPopover.swift
Normal file
|
|
@ -0,0 +1,362 @@
|
|||
//
|
||||
// TimerPopover.swift
|
||||
// DynamicIsland
|
||||
//
|
||||
// Created by GitHub Copilot on 2025-11-01.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Defaults
|
||||
|
||||
struct TimerPopover: View {
|
||||
@ObservedObject var timerManager = TimerManager.shared
|
||||
@Default(.timerPresets) private var timerPresets
|
||||
@Default(.timerShowsCountdown) private var showsCountdown
|
||||
@Default(.timerShowsProgress) private var showsProgress
|
||||
@Default(.timerProgressStyle) private var progressStyle
|
||||
@Default(.timerIconColorMode) private var colorMode
|
||||
@Default(.timerSolidColor) private var solidColor
|
||||
@AppStorage("customTimerDuration") private var customTimerDuration: Double = 600
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@State private var customHours: Int = 0
|
||||
@State private var customMinutes: Int = 10
|
||||
@State private var customSeconds: Int = 0
|
||||
|
||||
private var customDurationInSeconds: TimeInterval {
|
||||
TimeInterval(customHours * 3600 + customMinutes * 60 + customSeconds)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
HeaderView(statusText: statusText)
|
||||
|
||||
if timerManager.isTimerActive {
|
||||
ActiveTimerSection(timerManager: timerManager)
|
||||
} else {
|
||||
CustomTimerSection(hours: $customHours, minutes: $customMinutes, seconds: $customSeconds, startAction: startCustomTimer)
|
||||
.onChange(of: customHours) { _, _ in updateStoredCustomDuration() }
|
||||
.onChange(of: customMinutes) { _, _ in updateStoredCustomDuration() }
|
||||
.onChange(of: customSeconds) { _, _ in updateStoredCustomDuration() }
|
||||
}
|
||||
|
||||
Divider()
|
||||
.padding(.horizontal, -8)
|
||||
|
||||
PresetList(presets: timerPresets, activePresetId: timerManager.activePresetId, startAction: startPreset)
|
||||
.animation(.smooth, value: timerManager.activePresetId)
|
||||
.frame(maxHeight: 200)
|
||||
}
|
||||
.padding(16)
|
||||
.frame(width: 300)
|
||||
.background(
|
||||
VisualEffectView(material: .hudWindow, blendingMode: .behindWindow)
|
||||
.cornerRadius(12)
|
||||
)
|
||||
.onAppear {
|
||||
syncCustomDuration(with: customTimerDuration)
|
||||
}
|
||||
.onChange(of: customTimerDuration) { _, newValue in
|
||||
syncCustomDuration(with: newValue)
|
||||
}
|
||||
}
|
||||
|
||||
private var statusText: String {
|
||||
if timerManager.isOvertime {
|
||||
return "Overtime"
|
||||
} else if timerManager.isPaused {
|
||||
return "Paused"
|
||||
} else if timerManager.isTimerActive {
|
||||
return "Running"
|
||||
} else {
|
||||
return "Ready"
|
||||
}
|
||||
}
|
||||
|
||||
private func syncCustomDuration(with value: Double) {
|
||||
let components = TimerPreset.components(for: value)
|
||||
customHours = components.hours
|
||||
customMinutes = components.minutes
|
||||
customSeconds = components.seconds
|
||||
}
|
||||
|
||||
private func updateStoredCustomDuration() {
|
||||
let newValue = customDurationInSeconds
|
||||
customTimerDuration = newValue
|
||||
}
|
||||
|
||||
private func startCustomTimer() {
|
||||
let duration = customDurationInSeconds
|
||||
guard duration > 0 else { return }
|
||||
withAnimation(.smooth) {
|
||||
timerManager.startTimer(duration: duration, name: "Custom Timer")
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
|
||||
private func startPreset(_ preset: TimerPreset) {
|
||||
withAnimation(.smooth) {
|
||||
timerManager.startTimer(duration: preset.duration, name: preset.name, preset: preset)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private struct HeaderView: View {
|
||||
let statusText: String
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 12) {
|
||||
TimerIconAnimation()
|
||||
.frame(width: 32, height: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Timer")
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
Text(statusText)
|
||||
.font(.system(size: 11, weight: .medium))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct ActiveTimerSection: View {
|
||||
@ObservedObject var timerManager: TimerManager
|
||||
@Default(.timerShowsProgress) private var showsProgress
|
||||
@Default(.timerProgressStyle) private var progressStyle
|
||||
@Default(.timerIconColorMode) private var colorMode
|
||||
@Default(.timerSolidColor) private var solidColor
|
||||
@Default(.timerPresets) private var timerPresets
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(timerManager.timerName)
|
||||
.font(.system(size: 15, weight: .semibold))
|
||||
.lineLimit(1)
|
||||
.foregroundColor(.primary)
|
||||
|
||||
Text(timerManager.formattedRemainingTime())
|
||||
.font(.system(size: 28, weight: .bold, design: .monospaced))
|
||||
.foregroundStyle(timerManager.isOvertime ? Color.red : Color.primary)
|
||||
.contentTransition(.numericText())
|
||||
}
|
||||
|
||||
if showsProgress && progressStyle == .bar {
|
||||
ProgressView(value: min(timerManager.progress, 1.0))
|
||||
.progressViewStyle(LinearProgressViewStyle(tint: progressTint))
|
||||
.animation(.smooth(duration: 0.2), value: timerManager.progress)
|
||||
}
|
||||
|
||||
HStack(spacing: 8) {
|
||||
Button(action: togglePause) {
|
||||
Label(timerManager.isPaused ? "Resume" : "Pause", systemImage: timerManager.isPaused ? "play.fill" : "pause.fill")
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
|
||||
Button(role: .destructive, action: stopTimer) {
|
||||
Label("Stop", systemImage: "stop.fill")
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(12)
|
||||
.background(Color.white.opacity(0.08))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
|
||||
.animation(.smooth, value: timerManager.isPaused)
|
||||
}
|
||||
|
||||
private func togglePause() {
|
||||
withAnimation(.smooth) {
|
||||
if timerManager.isPaused {
|
||||
timerManager.resumeTimer()
|
||||
} else {
|
||||
timerManager.pauseTimer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func stopTimer() {
|
||||
withAnimation(.smooth) {
|
||||
timerManager.stopTimer()
|
||||
}
|
||||
}
|
||||
|
||||
private var progressTint: Color {
|
||||
switch colorMode {
|
||||
case .adaptive:
|
||||
return activePresetColor ?? timerManager.timerColor
|
||||
case .solid:
|
||||
return solidColor
|
||||
}
|
||||
}
|
||||
|
||||
private var activePresetColor: Color? {
|
||||
guard let presetId = timerManager.activePresetId else { return nil }
|
||||
return timerPresets.first { $0.id == presetId }?.color
|
||||
}
|
||||
}
|
||||
|
||||
private struct CustomTimerSection: View {
|
||||
@Binding var hours: Int
|
||||
@Binding var minutes: Int
|
||||
@Binding var seconds: Int
|
||||
let startAction: () -> Void
|
||||
|
||||
private var totalSeconds: Int {
|
||||
hours * 3600 + minutes * 60 + seconds
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Custom Timer")
|
||||
.font(.system(size: 14, weight: .semibold))
|
||||
|
||||
Grid(alignment: .leading, horizontalSpacing: 12, verticalSpacing: 8) {
|
||||
GridRow {
|
||||
DurationStepper(title: "Hours", value: $hours, range: 0...23)
|
||||
DurationStepper(title: "Minutes", value: $minutes, range: 0...59)
|
||||
DurationStepper(title: "Seconds", value: $seconds, range: 0...59)
|
||||
}
|
||||
}
|
||||
|
||||
Text(formattedDuration)
|
||||
.font(.system(size: 12, weight: .medium, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
|
||||
Button(action: startAction) {
|
||||
Label("Start Custom Timer", systemImage: "play.fill")
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(totalSeconds == 0)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(12)
|
||||
.background(Color.white.opacity(0.05))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
|
||||
}
|
||||
|
||||
private var formattedDuration: String {
|
||||
let components = TimerPreset.DurationComponents(hours: hours, minutes: minutes, seconds: seconds)
|
||||
let interval = TimerPreset.duration(from: components)
|
||||
return TimerPreset(name: "", duration: interval, color: .clear).formattedDuration
|
||||
}
|
||||
}
|
||||
|
||||
private struct DurationStepper: View {
|
||||
let title: String
|
||||
@Binding var value: Int
|
||||
let range: ClosedRange<Int>
|
||||
|
||||
var body: some View {
|
||||
Stepper(value: $value, in: range) {
|
||||
HStack {
|
||||
Text(title)
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
Spacer()
|
||||
Text("\(value)")
|
||||
.font(.system(size: 12, weight: .semibold, design: .monospaced))
|
||||
}
|
||||
}
|
||||
.frame(width: 88)
|
||||
}
|
||||
}
|
||||
|
||||
private struct PresetList: View {
|
||||
let presets: [TimerPreset]
|
||||
let activePresetId: UUID?
|
||||
let startAction: (TimerPreset) -> Void
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("Presets")
|
||||
.font(.system(size: 13, weight: .semibold))
|
||||
.padding(.leading, 4)
|
||||
|
||||
if presets.isEmpty {
|
||||
Text("Configure presets in Settings")
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(.secondary)
|
||||
.padding(12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(Color.white.opacity(0.05))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
|
||||
} else {
|
||||
ScrollView {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(presets) { preset in
|
||||
TimerPresetRow(preset: preset, isActive: activePresetId == preset.id) {
|
||||
startAction(preset)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct TimerPresetRow: View {
|
||||
let preset: TimerPreset
|
||||
let isActive: Bool
|
||||
let action: () -> Void
|
||||
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
HStack(spacing: 12) {
|
||||
Circle()
|
||||
.fill(preset.color.gradient)
|
||||
.frame(width: 20, height: 20)
|
||||
.overlay(
|
||||
Circle()
|
||||
.stroke(Color.white.opacity(0.5), lineWidth: 1)
|
||||
)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(preset.name)
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
.foregroundStyle(.primary)
|
||||
.lineLimit(1)
|
||||
Text(preset.formattedDuration)
|
||||
.font(.system(size: 11, weight: .medium, design: .monospaced))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: isActive ? "checkmark" : "play.fill")
|
||||
.font(.system(size: 11, weight: .semibold))
|
||||
.foregroundStyle(isActive ? preset.color : Color.secondary)
|
||||
.padding(6)
|
||||
.background(isActive ? preset.color.opacity(0.2) : Color.clear)
|
||||
.clipShape(Circle())
|
||||
}
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 10)
|
||||
.contentShape(RoundedRectangle(cornerRadius: 10, style: .continuous))
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10, style: .continuous)
|
||||
.fill(isActive ? preset.color.opacity(0.18) : Color.white.opacity(0.05))
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
TimerPopover()
|
||||
.frame(width: 300)
|
||||
.padding()
|
||||
.background(Color.black)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue