Guest User

Untitled

a guest
Oct 28th, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.62 KB | None | 0 0
  1. // KeyboardReturnMod.swift
  2.  
  3. import SwiftUI
  4.  
  5. struct KeyboardReturnMod: ViewModifier {
  6.     let returnAction: () -> ()
  7.    
  8.     func body(content: Content) -> some View {
  9.         content
  10.             .toolbar {
  11.                 ToolbarItemGroup(placement: .keyboard) {
  12.                     Button {
  13.                         returnAction()
  14.                     } label: {
  15.                         Image(systemName: "keyboard.chevron.compact.down")
  16.                         Text("Return")
  17.                     }
  18.                 }
  19.             }
  20.     }
  21. }
  22.  
  23. // SettingsTab.swift
  24.  
  25. enum STField {
  26.     case dailyGoal
  27. }
  28.  
  29. struct SettingsTab: View {
  30.     // ...
  31.  
  32.     @FocusState var focusedField: STField?
  33.    
  34.     var body: some View {
  35.         // ...
  36.        
  37.         NavigationStack {
  38.             Form {
  39.                 // ...
  40.  
  41.                 Section("Options") {
  42.                     // ...
  43.                    
  44.                     HStack {
  45.                         Text("Daily goal (Intake)")
  46.                         Spacer()
  47.                         TextField(mainVM.selectedSystem.volume.n, value: $mainVM.dailyGoal, format: .number)
  48.                             .keyboardType(.decimalPad)
  49.                             .focused($focusedField, equals: .dailyGoal)
  50.                             .foregroundStyle(Color(.secondaryLabel))
  51.                             .multilineTextAlignment(.trailing)
  52.                             .frame(width: 75)
  53.                     }
  54.                 }
  55.             }
  56.             .modifier(KeyboardReturnMod(returnAction: { focusedField = nil }))
  57.            
  58.             // ...
  59.         }
  60.     }
  61. }
Add Comment
Please, Sign In to add comment