@@ -18,17 +18,21 @@ struct BolusEntryView: View {
1818 @EnvironmentObject private var displayGlucosePreference : DisplayGlucosePreference
1919 @Environment ( \. dismissAction) var dismiss
2020 @Environment ( \. appName) var appName
21-
21+ @Environment ( \. dynamicTypeSize) private var dynamicTypeSize
22+
2223 @ObservedObject var viewModel : BolusEntryViewModel
2324
2425 @State private var enteredBolusString = " "
25- @State private var shouldBolusEntryBecomeFirstResponder = false
2626
2727 @State private var isInteractingWithChart = false
28- @State private var isKeyboardVisible = false
29- @State private var pickerShouldExpand = false
3028 @State private var editedBolusAmount = false
3129
30+ @FocusState private var bolusFieldFocused : Bool
31+
32+ private var accessoryClearance : CGFloat {
33+ dynamicTypeSize. isAccessibilitySize ? 72 : 52
34+ }
35+
3236 var body : some View {
3337 VStack ( spacing: 0 ) {
3438 List {
@@ -37,21 +41,11 @@ struct BolusEntryView: View {
3741 }
3842 . padding ( . top, - 28 )
3943 . insetGroupedListStyle ( )
40-
41- self . actionArea
42- . frame ( height: self . isKeyboardVisible || shouldBolusEntryBecomeFirstResponder ? 0 : nil )
43- . opacity ( self . isKeyboardVisible || shouldBolusEntryBecomeFirstResponder ? 0 : 1 )
44- }
45- . onKeyboardStateChange { state in
46- self . isKeyboardVisible = state. height > 0
47-
48- if state. height == 0 {
49- // Ensure tapping 'Enter Bolus' can make the text field the first responder again
50- self . shouldBolusEntryBecomeFirstResponder = false
44+ if !bolusFieldFocused {
45+ actionArea
5146 }
47+
5248 }
53- . keyboardAware ( )
54- . edgesIgnoringSafeArea ( self . isKeyboardVisible ? [ ] : . bottom)
5549 . navigationBarTitle ( self . title)
5650 . supportedInterfaceOrientations ( . portrait)
5751 . alert ( item: self . $viewModel. activeAlert, content: self . alert ( for: ) )
@@ -71,6 +65,7 @@ struct BolusEntryView: View {
7165 enteredBolusStringBinding. wrappedValue = " 0 "
7266 }
7367 }
68+ . edgesIgnoringSafeArea ( self . bolusFieldFocused ? [ ] : . bottom)
7469 . task {
7570 await self . viewModel. generateRecommendationAndStartObserving ( )
7671 }
@@ -283,18 +278,31 @@ struct BolusEntryView: View {
283278 Text ( " Bolus " , comment: " Label for bolus entry row on bolus screen " )
284279 Spacer ( )
285280 HStack ( alignment: . firstTextBaseline) {
286- DismissibleKeyboardTextField (
287- text: enteredBolusStringBinding,
288- placeholder: viewModel. formatBolusAmount ( 0.0 ) ,
289- font: . preferredFont( forTextStyle: . title1) ,
290- textColor: . loopAccent,
291- textAlignment: . right,
292- keyboardType: . decimalPad,
293- shouldBecomeFirstResponder: shouldBolusEntryBecomeFirstResponder,
294- maxLength: 5 ,
295- doneButtonColor: . loopAccent,
296- textFieldDidBeginEditing: didBeginEditing
297- )
281+ TextField ( viewModel. formatBolusAmount ( 0.0 ) , text: enteredBolusStringBinding)
282+ . keyboardType ( . decimalPad)
283+ . textInputAutocapitalization ( . never)
284+ . disableAutocorrection ( true )
285+ . font ( . title)
286+ . multilineTextAlignment ( . trailing)
287+ . foregroundColor ( . loopAccent)
288+ . focused ( $bolusFieldFocused)
289+ . onChange ( of: bolusFieldFocused) { oldValue, focused in
290+ if focused {
291+ didBeginEditing ( )
292+ }
293+ }
294+ . onChange ( of: enteredBolusString) { oldValue, newValue in
295+ if newValue. count > 5 {
296+ enteredBolusString = String ( newValue. prefix ( 5 ) )
297+ viewModel. updateEnteredBolus ( enteredBolusString)
298+ }
299+ }
300+ . toolbar {
301+ ToolbarItemGroup ( placement: . keyboard) {
302+ Spacer ( )
303+ Button ( " Done " ) { bolusFieldFocused = false }
304+ }
305+ }
298306 bolusUnitsLabel
299307 }
300308 . accessibilityIdentifier ( " textField_Bolus " )
@@ -328,7 +336,6 @@ struct BolusEntryView: View {
328336 enterManualGlucoseButton
329337 . transition ( AnyTransition . opacity. combined ( with: . move( edge: . bottom) ) )
330338 }
331-
332339 actionButton
333340 }
334341 . padding ( . bottom) // FIXME: unnecessary on iPhone 8 size devices
@@ -385,7 +392,7 @@ struct BolusEntryView: View {
385392 Button < Text > (
386393 action: {
387394 if self . viewModel. actionButtonAction == . enterBolus {
388- self . shouldBolusEntryBecomeFirstResponder = true
395+ self . bolusFieldFocused = true
389396 } else {
390397 Task {
391398 if await self . viewModel. didPressActionButton ( ) {
0 commit comments