polscm32 2 лет назад
Родитель
Сommit
f8cf8082b2
1 измененных файлов с 54 добавлено и 51 удалено
  1. 54 51
      FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

+ 54 - 51
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -447,57 +447,7 @@ extension Bolus {
                         }
                     }
                 }.safeAreaInset(edge: .bottom, spacing: 0) {
-                    Section {
-                        Button {
-                            if state.amount > 0 {
-                                if !state.externalInsulin {
-                                    Task {
-                                        await state.add()
-                                        state.waitForSuggestion = true
-                                    }
-                                } else {
-                                    Task {
-                                        do {
-                                            await state.addExternalInsulin()
-                                            state.waitForSuggestion = true
-                                        }
-                                    }
-                                }
-                                state.addCarbs()
-                                state.addButtonPressed = true
-                            } else {
-                                // show loading bar only when carbs are actually added
-                                if state.carbs > 0 {
-                                    state.addCarbs()
-                                    state.waitForSuggestion = true
-                                } else {
-                                    // hide modal because its otherwise only hidden after a suggestion update, see StateModal
-                                    state.hideModal()
-                                }
-                                state.addButtonPressed = true
-                            }
-                        } label: {
-                            if state.amount > 0 {
-                                Text(
-                                    !state
-                                        .externalInsulin ? (exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus") :
-                                        (exceededMaxBolus ? "Max Bolus exceeded!" : "Log external insulin")
-                                ).font(.system(size: 17, design: .rounded))
-                            } else {
-                                Text("Continue without bolus").font(.system(size: 17, design: .rounded))
-                            }
-                        }
-                        .frame(maxWidth: .infinity, alignment: .center)
-                        .frame(minHeight: 50)
-                        .disabled(state.amount > 0 ? (state.externalInsulin ? limitManualBolus : limitPumpBolus) : false)
-                        .background(state.amount > 0 ? logExternalInsulinBackground : Color(.systemBlue))
-                        .shadow(radius: 3)
-                        .clipShape(RoundedRectangle(cornerRadius: 8))
-                        .foregroundStyle(state.amount > 0 ? logExternalInsulinForeground : .white)
-                        .padding()
-                    }
-                    .listRowBackground(Color.chart)
-
+                    stickyButton
                 }.blur(radius: state.waitForSuggestion ? 5 : 0)
 
                 if state.waitForSuggestion {
@@ -547,6 +497,59 @@ extension Bolus {
             }
         }
 
+        var stickyButton: some View {
+            Section {
+                Button {
+                    if state.amount > 0 {
+                        if !state.externalInsulin {
+                            Task {
+                                await state.add()
+                                state.waitForSuggestion = true
+                            }
+                        } else {
+                            Task {
+                                do {
+                                    await state.addExternalInsulin()
+                                    state.waitForSuggestion = true
+                                }
+                            }
+                        }
+                        state.addCarbs()
+                        state.addButtonPressed = true
+                    } else {
+                        // show loading bar only when carbs are actually added
+                        if state.carbs > 0 {
+                            state.addCarbs()
+                            state.waitForSuggestion = true
+                        } else {
+                            // hide modal because its otherwise only hidden after a suggestion update, see StateModal
+                            state.hideModal()
+                        }
+                        state.addButtonPressed = true
+                    }
+                } label: {
+                    if state.amount > 0 {
+                        Text(
+                            !state
+                                .externalInsulin ? (exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus") :
+                                (exceededMaxBolus ? "Max Bolus exceeded!" : "Log external insulin")
+                        ).font(.system(size: 17, design: .rounded))
+                    } else {
+                        Text("Continue without bolus").font(.system(size: 17, design: .rounded))
+                    }
+                }
+                .frame(maxWidth: .infinity, alignment: .center)
+                .frame(minHeight: 50)
+                .disabled(state.amount > 0 ? (state.externalInsulin ? limitManualBolus : limitPumpBolus) : false)
+                .background(state.amount > 0 ? logExternalInsulinBackground : Color(.systemBlue))
+                .shadow(radius: 3)
+                .clipShape(RoundedRectangle(cornerRadius: 8))
+                .foregroundStyle(state.amount > 0 ? logExternalInsulinForeground : .white)
+                .padding()
+            }
+            .listRowBackground(Color.chart)
+        }
+
         var calcSettingsFirstRow: some View {
             GridRow {
                 Group {