BolusRootView.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import SwiftUI
  2. import Swinject
  3. extension Bolus {
  4. struct RootView: View {
  5. let resolver: Resolver
  6. let waitForSuggestion: Bool
  7. let fetch: Bool
  8. let editMode: Bool
  9. let override: Bool
  10. @StateObject var state = StateModel()
  11. @ObservedObject var appState = AppState()
  12. var body: some View {
  13. if state.useCalc {
  14. // show alternative bolus calc based on toggle in bolus calc settings
  15. AlternativeBolusCalcRootView(
  16. resolver: resolver,
  17. waitForSuggestion: waitForSuggestion,
  18. fetch: fetch,
  19. editMode: editMode,
  20. override: override,
  21. state: state,
  22. appState: appState
  23. )
  24. } else {
  25. // show iAPS standard bolus calc
  26. DefaultBolusCalcRootView(
  27. resolver: resolver,
  28. waitForSuggestion: waitForSuggestion,
  29. fetch: fetch,
  30. state: state,
  31. appState: appState
  32. )
  33. }
  34. }
  35. }
  36. }
  37. // fix iOS 15 bug
  38. struct ActivityIndicator: UIViewRepresentable {
  39. @Binding var isAnimating: Bool
  40. let style: UIActivityIndicatorView.Style
  41. func makeUIView(context _: UIViewRepresentableContext<ActivityIndicator>) -> UIActivityIndicatorView {
  42. UIActivityIndicatorView(style: style)
  43. }
  44. func updateUIView(_ uiView: UIActivityIndicatorView, context _: UIViewRepresentableContext<ActivityIndicator>) {
  45. isAnimating ? uiView.startAnimating() : uiView.stopAnimating()
  46. }
  47. }