MailAddressInput.swift (1778B)
1 /* 2 * This file is part of GNU Taler, ©2022-26 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * @author Marc Stibane 7 */ 8 import SwiftUI 9 10 struct MailAddressInput: View { 11 let stack: CallStack 12 @Binding var text: String 13 // @FocusState.Binding 14 var isFocused: Bool 15 let focusAction: () -> Void 16 17 var body: some View { 18 let label = String(localized: "Address:", comment: "TextEdit purpose, a11y") 19 let placeHolder = EMPTYSTRING 20 VStack(alignment: .leading, spacing: 6) { 21 Text(label) 22 .talerFont(.title3) 23 if #available(iOS 16.4, *) { 24 TextField(placeHolder, text: $text, axis: .vertical) 25 .lineLimit(2...6) 26 .textFieldStyle(.roundedBorder) 27 .textInputAutocapitalization(.never) 28 .onChange(of: text) { newValue in 29 // .onSubmit {} doesn't work with multiple lines, so we need to check for "\n" 30 guard isFocused else { return } 31 guard newValue.contains(LINEFEED) else { return } 32 focusAction() 33 text = newValue.replacing(LINEFEED, with: EMPTYSTRING) 34 } 35 .talerFont(.title3) 36 // .accessibilityLabel(label) 37 } else { 38 TextField(placeHolder, text: $text) 39 .textFieldStyle(.roundedBorder) 40 .textInputAutocapitalization(.never) 41 // .focused($isFocused) 42 .onSubmit { 43 guard isFocused else { return } 44 focusAction() 45 } 46 .talerFont(.title2) 47 } 48 } 49 } 50 }