Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // KeyboardReturnMod.swift
- import SwiftUI
- struct KeyboardReturnMod: ViewModifier {
- let returnAction: () -> ()
- func body(content: Content) -> some View {
- content
- .toolbar {
- ToolbarItemGroup(placement: .keyboard) {
- Button {
- returnAction()
- } label: {
- Image(systemName: "keyboard.chevron.compact.down")
- Text("Return")
- }
- }
- }
- }
- }
- // SettingsTab.swift
- enum STField {
- case dailyGoal
- }
- struct SettingsTab: View {
- // ...
- @FocusState var focusedField: STField?
- var body: some View {
- // ...
- NavigationStack {
- Form {
- // ...
- Section("Options") {
- // ...
- HStack {
- Text("Daily goal (Intake)")
- Spacer()
- TextField(mainVM.selectedSystem.volume.n, value: $mainVM.dailyGoal, format: .number)
- .keyboardType(.decimalPad)
- .focused($focusedField, equals: .dailyGoal)
- .foregroundStyle(Color(.secondaryLabel))
- .multilineTextAlignment(.trailing)
- .frame(width: 75)
- }
- }
- }
- .modifier(KeyboardReturnMod(returnAction: { focusedField = nil }))
- // ...
- }
- }
- }
Add Comment
Please, Sign In to add comment