Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/timer-monospaced-digit-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'voltra': patch
---

Fix timer digits shifting during countdown and stopwatch in relative mode.
21 changes: 10 additions & 11 deletions ios/ui/Views/VoltraTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public struct VoltraTimer: VoltraView {
)
}

private func resolvedEndDate(params: TimerParameters) -> Date? { progressRange(params: params)?.upperBound }
private func resolvedEndDate(params: TimerParameters) -> Date? {
progressRange(params: params)?.upperBound
}

private func countsDown(params: TimerParameters) -> Bool {
(params.direction.lowercased()) != "up"
Expand All @@ -45,7 +47,8 @@ public struct VoltraTimer: VoltraView {

private func textTemplates(params: TimerParameters) -> TextTemplates? {
guard let raw = params.textTemplates,
let data = raw.data(using: .utf8) else { return nil }
let data = raw.data(using: .utf8)
else { return nil }
return try? JSONDecoder().decode(TextTemplates.self, from: data)
}

Expand Down Expand Up @@ -87,7 +90,7 @@ public struct VoltraTimer: VoltraView {

if style == "relative" {
let targetDate = isCountDown ? range.upperBound : range.lowerBound
Text(targetDate, style: .relative)
Text(targetDate, style: .relative).monospacedDigit()
} else {
// Live Activities require Text(timerInterval:...) for automatic updates
Text(timerInterval: range, countsDown: isCountDown, showsHours: showHours)
Expand All @@ -98,15 +101,17 @@ public struct VoltraTimer: VoltraView {
@ViewBuilder
private func staticZeroText(style: String, showHours: Bool) -> some View {
if style == "relative" {
Text("0s")
Text("0s").monospacedDigit()
} else {
Text(showHours ? "0:00:00" : "0:00")
.monospacedDigit()
}
}

@ViewBuilder
private func renderTemplate<T: View>(template: String, @ViewBuilder timeView: @escaping () -> T) -> some View {
private func renderTemplate<T: View>(template: String, @ViewBuilder timeView: @escaping () -> T)
-> some View
{
let placeholder = "{time}"
let segments = template.components(separatedBy: placeholder)

Expand All @@ -124,9 +129,3 @@ public struct VoltraTimer: VoltraView {
}
}
}

// MARK: - Formatters

extension VoltraTimer {
// Formatters are no longer needed for live updates but kept if we need static fallbacks.
}
Loading