Sfoglia il codice sorgente

Add copy-to-clipboard for version info

Allow long-pressing the version info row to copy the app version/build details to the clipboard and show a temporary confirmation toast. Adds UIKit import for UIPasteboard and haptic feedback, a showCopiedToast @State flag, contentShape to expand the gesture area, a 1.5s auto-dismiss animation for the toast, and a small UI label overlay with transition. This improves UX for sharing diagnostic/version information.
Mike Plante 3 settimane fa
parent
commit
e87265efd0
1 ha cambiato i file con 24 aggiunte e 0 eliminazioni
  1. 24 0
      Trio/Sources/Modules/Settings/View/SettingsRootView.swift

+ 24 - 0
Trio/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -3,6 +3,7 @@ import LoopKit
 import LoopKitUI
 import LoopKitUI
 import SwiftUI
 import SwiftUI
 import Swinject
 import Swinject
+import UIKit
 
 
 extension Settings {
 extension Settings {
     struct VersionInfo: Equatable {
     struct VersionInfo: Equatable {
@@ -34,6 +35,7 @@ extension Settings {
             isDevUpdateAvailable: false
             isDevUpdateAvailable: false
         )
         )
         @State private var closedLoopDisabled = true
         @State private var closedLoopDisabled = true
+        @State private var showCopiedToast = false
 
 
         @Environment(\.colorScheme) var colorScheme
         @Environment(\.colorScheme) var colorScheme
         @EnvironmentObject var appIcons: Icons
         @EnvironmentObject var appIcons: Icons
@@ -151,6 +153,16 @@ extension Settings {
                                         versionInfoView
                                         versionInfoView
                                     }
                                     }
                                 }
                                 }
+                                .contentShape(Rectangle())
+                                .onLongPressGesture {
+                                    UIPasteboard.general.string =
+                                        "Trio v\(devVersion) (\(buildNumber)) \(buildDetails.branchAndSha)"
+                                    UINotificationFeedbackGenerator().notificationOccurred(.success)
+                                    withAnimation { showCopiedToast = true }
+                                    DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
+                                        withAnimation { showCopiedToast = false }
+                                    }
+                                }
                             }
                             }
                         }
                         }
                     ).listRowBackground(Color.chart)
                     ).listRowBackground(Color.chart)
@@ -310,6 +322,18 @@ extension Settings {
                     ).listRowBackground(Color.chart)
                     ).listRowBackground(Color.chart)
                 }
                 }
             }
             }
+            .overlay(alignment: .bottom) {
+                if showCopiedToast {
+                    Label("Copied", systemImage: "checkmark.circle.fill")
+                        .font(.footnote.weight(.semibold))
+                        .foregroundColor(.white)
+                        .padding(.horizontal, 16)
+                        .padding(.vertical, 10)
+                        .background(.ultraThinMaterial, in: Capsule())
+                        .padding(.bottom, 32)
+                        .transition(.move(edge: .bottom).combined(with: .opacity))
+                }
+            }
             .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
             .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
             .sheet(isPresented: $shouldDisplayHint) {
             .sheet(isPresented: $shouldDisplayHint) {
                 SettingInputHintView(
                 SettingInputHintView(