commit 931076b600d7b9fa30ab24c3fa2e55011760912e
parent fc7dea230b0971163c5c511a1f17c6cbf4719f9b
Author: Marc Stibane <marc@taler.net>
Date: Thu, 16 Jul 2026 09:19:01 +0200
TimeView
Diffstat:
1 file changed, 43 insertions(+), 0 deletions(-)
diff --git a/TalerWallet1/Views/HelperViews/TimeView.swift b/TalerWallet1/Views/HelperViews/TimeView.swift
@@ -0,0 +1,43 @@
+/*
+ * This file is part of GNU Taler, ©2022-26 Taler Systems S.A.
+ * See LICENSE.md
+ */
+/**
+ * @author Marc Stibane
+ */
+import SwiftUI
+
+struct TimeView: View {
+ let title: String
+ let seconds: Int
+ let trailer: String
+
+ init(_ title: String, seconds: Int,_ trailer: String? = nil) {
+ self.title = title
+ self.seconds = seconds
+ self.trailer = trailer ?? String(localized: "seconds")
+ }
+
+ var body: some View {
+ let startDate = Date()
+ HStack {
+ Text(title)
+ TimelineView(.animation) { context in
+ let elapsed = Int(context.date.timeIntervalSince(startDate))
+ let remaining = seconds - elapsed
+ let text = Text(verbatim: "\(remaining)")
+ if #available(iOS 17.0, *) {
+ text
+ .contentTransition(.numericText(countsDown: true))
+ .animation(.default, value: elapsed)
+ } else if #available(iOS 16.4, *) {
+ text
+ .animation(.default, value: elapsed)
+ } else {
+ text
+ }
+ }.monospacedDigit()
+ Text(trailer)
+ }.accessibilityElement(children: .combine)
+ }
+}