commit cd431bb6b21ca2118b19835fbd02cb7acea03807 parent 76e35da9d180d018b6f99fdcfc0ce6182e636316 Author: Marc Stibane <marc@taler.net> Date: Fri, 13 Mar 2026 11:18:39 +0100 FeedbackButton Diffstat:
| M | TalerWallet1/Views/HelperViews/CopyShare.swift | | | 52 | ++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 52 insertions(+), 0 deletions(-)
diff --git a/TalerWallet1/Views/HelperViews/CopyShare.swift b/TalerWallet1/Views/HelperViews/CopyShare.swift @@ -9,6 +9,58 @@ import UniformTypeIdentifiers import SwiftUI import SymLog +@MainActor +struct FeedbackButton: View { + private let symLog = SymLogV(0) + let title: String? + let image: UIImage? + let isDisabled: Bool + let action: () -> Void + + @EnvironmentObject private var controller: Controller + @State private var scale: CGFloat = 1.0 + + public init(_ title: String? = nil, + image: UIImage? = nil, + disabled: Bool = false, + action: @escaping @MainActor () -> Void) { + self.title = title + self.image = image + self.isDisabled = disabled + self.action = action + } + + private func triggerPulse() { + // First scale down quickly + withAnimation(.easeIn(duration: 0.1)) { + scale = 0.8 + } + // Then bounce back bigger + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + withAnimation(.easeOut(duration: 0.25)) { + scale = 1.15 + } + } + // Finally settle to normal + DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) { + withAnimation(.easeInOut(duration: 0.25)) { + scale = 1.0 + } + } + } + + var body: some View { + Button(title ?? EMPTYSTRING) { + symLog.log(title ?? EMPTYSTRING) + controller.hapticFeedback(.medium) + action() + triggerPulse() + } + .buttonStyle(TalerButtonStyle(type: .bordered, disabled: isDisabled)) + } +} +// MARK: - +@MainActor struct CopyButton: View { private let symLog = SymLogV(0) let textToCopy: String