Procházet zdrojové kódy

Fix navigation between treatment views

Deniz Cengiz před 1 rokem
rodič
revize
db9ddf5e3d

+ 42 - 44
Trio Watch App Extension/Views/BolusInputView.swift

@@ -12,60 +12,58 @@ struct BolusInputView: View {
     let state: WatchState
 
     var body: some View {
-        NavigationStack {
-            if showingConfirmation {
-                BolusConfirmationView(
-                    bolusAmount: bolusAmount,
-                    progress: $confirmationProgress,
-                    state: state,
-                    dismiss: dismiss
-                )
-                .navigationTitle("Confirm")
-                .navigationBarBackButtonHidden(true)
-                .toolbar {
-                    ToolbarItem(placement: .topBarLeading) {
-                        Button {
-                            if state.carbsAmount > 0 {
-                                state.carbsAmount = 0
-                            }
-                            dismiss()
-                        } label: {
-                            Image(systemName: "xmark")
+        if showingConfirmation {
+            BolusConfirmationView(
+                bolusAmount: bolusAmount,
+                progress: $confirmationProgress,
+                state: state,
+                dismiss: dismiss
+            )
+            .navigationTitle("Confirm")
+            .navigationBarBackButtonHidden(true)
+            .toolbar {
+                ToolbarItem(placement: .topBarLeading) {
+                    Button {
+                        if state.carbsAmount > 0 {
+                            state.carbsAmount = 0 // reset carbs in state
                         }
-                        .buttonStyle(.bordered)
-                        .clipShape(Circle())
+                        dismiss()
+                    } label: {
+                        Image(systemName: "xmark")
                     }
+                    .buttonStyle(.bordered)
+                    .clipShape(Circle())
+                }
 
-                    ToolbarItem(placement: .topBarTrailing) {
-                        Image(systemName: "digitalcrown.arrow.counterclockwise.fill")
-                            .foregroundStyle(Color.white)
-                    }
+                ToolbarItem(placement: .topBarTrailing) {
+                    Image(systemName: "digitalcrown.arrow.counterclockwise.fill")
+                        .foregroundStyle(Color.white)
                 }
-            } else {
-                VStack {
-                    if state.carbsAmount > 0 {
-                        HStack {
-                            Text("Carbs: \(state.carbsAmount) g").font(.subheadline).padding(.bottom)
-                            Spacer()
-                        }
+            }
+        } else {
+            VStack {
+                if state.carbsAmount > 0 {
+                    HStack {
+                        Text("Carbs: \(state.carbsAmount) g").font(.subheadline).padding(.bottom)
+                        Spacer()
                     }
+                }
 
-                    // TODO: handle bolus recommendation
-                    Picker("Bolus", selection: $bolusAmount) {
-                        ForEach(0 ... 100, id: \.self) { number in
-                            Text(String(format: "%.1f U", Double(number) / 10))
-                                .tag(Double(number) / 10)
-                        }
+                // TODO: handle bolus recommendation
+                Picker("Bolus", selection: $bolusAmount) {
+                    ForEach(0 ... 100, id: \.self) { number in
+                        Text(String(format: "%.1f U", Double(number) / 10))
+                            .tag(Double(number) / 10)
                     }
+                }
 
-                    Button("Add Bolus") {
-                        showingConfirmation = true
-                    }
-                    .buttonStyle(.bordered)
-                    .tint(.blue)
+                Button("Add Bolus") {
+                    showingConfirmation = true
                 }
-                .navigationTitle("Add Insulin")
+                .buttonStyle(.bordered)
+                .tint(.blue)
             }
+            .navigationTitle("Add Insulin")
         }
     }
 }

+ 19 - 21
Trio Watch App Extension/Views/CarbsInputView.swift

@@ -12,33 +12,31 @@ struct CarbsInputView: View {
     let continueToBolus: Bool
 
     var body: some View {
-        let buttonLabel = continueToBolus ? "Continue to Bolus" : "Add Carbs"
+        let buttonLabel = continueToBolus ? "Proceed" : "Add Carbs"
 
         // TODO: introduce meal setting fpu enablement to conditional handle FPU
-        NavigationStack {
-            VStack {
-                Picker("Carbs", selection: $carbsAmount) {
-                    ForEach(0 ... 100, id: \.self) { amount in
-                        Text("\(amount)g").tag(amount)
-                    }
+        VStack {
+            Picker("Carbs", selection: $carbsAmount) {
+                ForEach(0 ... 100, id: \.self) { amount in
+                    Text("\(amount)g").tag(amount)
                 }
+            }
 
-                Button(buttonLabel) {
-                    if continueToBolus {
-                        state.carbsAmount = carbsAmount
-                        navigateToBolus = true
-                    } else {
-                        state.sendCarbsRequest(carbsAmount)
-                        dismiss()
-                    }
+            Button(buttonLabel) {
+                if continueToBolus {
+                    state.carbsAmount = carbsAmount
+                    navigateToBolus = true
+                } else {
+                    state.sendCarbsRequest(carbsAmount)
+                    dismiss()
                 }
-                .buttonStyle(.bordered)
-                .tint(.orange)
-            }
-            .navigationTitle("Add Carbs")
-            .navigationDestination(isPresented: $navigateToBolus) {
-                BolusInputView(state: state) // Navigate to BolusInputView
             }
+            .buttonStyle(.bordered)
+            .tint(.orange)
+        }
+        .navigationTitle("Add Carbs")
+        .navigationDestination(isPresented: $navigateToBolus) {
+            BolusInputView(state: state) // Navigate to BolusInputView
         }
     }
 }