Просмотр исходного кода

fix for bolus progress overlay

polscm32 aka Marvout 1 год назад
Родитель
Сommit
dda034f66c

+ 5 - 3
Trio Watch App Extension/Views/BolusProgressOverlay.swift

@@ -27,7 +27,6 @@ struct BolusProgressOverlay: View {
 
                         Button(action: {
                             state.sendCancelBolusRequest()
-                            state.activeBolusAmount = 0
                             navigationState.resetToRoot()
                         }) {
                             Image(systemName: "xmark.circle.fill")
@@ -49,8 +48,11 @@ struct BolusProgressOverlay: View {
                 .background(Color.black.opacity(0.7))
                 .cornerRadius(10)
                 .padding()
-            }.onDisappear {
-                state.activeBolusAmount = 0
+            }
+            .onChange(of: state.bolusProgress) { _, newProgress in
+                if newProgress >= 1.0 {
+                    state.activeBolusAmount = 0 // Reset only when bolus is complete
+                }
             }
         }
     }

+ 2 - 2
Trio Watch App Extension/WatchState.swift

@@ -32,7 +32,6 @@ import WatchConnectivity
 
     var bolusProgress: Double = 0.0
     var isBolusCanceled = false
-
     override init() {
         super.init()
         setupSession()
@@ -56,8 +55,9 @@ import WatchConnectivity
     /// - Parameters:
     ///   - amount: The insulin amount to be delivered
     func sendBolusRequest(_ amount: Decimal) {
-        isBolusCanceled = false // Reset canceled state when starting new bolus
         guard let session = session, session.isReachable else { return }
+        isBolusCanceled = false // Reset canceled state when starting new bolus
+        activeBolusAmount = Double(truncating: amount as NSNumber) // Set active bolus amount
 
         let message: [String: Any] = [
             "bolus": amount