diff --git a/Sources/MisticaSwiftUI/Components/Inputfield/InputField.swift b/Sources/MisticaSwiftUI/Components/Inputfield/InputField.swift index 640fe950..b61368b5 100644 --- a/Sources/MisticaSwiftUI/Components/Inputfield/InputField.swift +++ b/Sources/MisticaSwiftUI/Components/Inputfield/InputField.swift @@ -26,6 +26,7 @@ public struct InputField: View { public enum Style: Equatable { case text + case numeric case email case secure case phone(code: String) @@ -175,7 +176,8 @@ private extension InputField { isResponder: $editing, isSecured: secure, keyboard: keyboard, - inputStyle: inputStyle + inputStyle: inputStyle, + textContentType: textContentType ) } @@ -185,6 +187,7 @@ private extension InputField { return secureActivated case .phone, .text, + .numeric, .email, .dropdown, .date, @@ -202,6 +205,7 @@ private extension InputField { case .phone, .secure, .text, + .numeric, .email, .search: return .text @@ -220,6 +224,24 @@ private extension InputField { return .phonePad case .email: return .emailAddress + case .numeric: + return .numberPad + } + } + + var textContentType: UITextContentType? { + switch style { + case .secure, + .text, + .dropdown, + .search, + .numeric, + .date: + return nil + case .phone: + return .telephoneNumber + case .email: + return .emailAddress } } @@ -261,6 +283,12 @@ public extension InputField { view.style = style return view } + + func textContentType(_ textContentType: UITextContentType?) -> InputField { + var view = self + view.textField.textContentType(textContentType) + return view + } } // MARK: Previews @@ -276,6 +304,10 @@ struct InputField_Previews: PreviewProvider { .style(.email) .padding() + InputField(placeholder: "Numeric", text: $text1) + .style(.numeric) + .padding() + InputField(placeholder: "Normal", text: $text1, assistiveText: $assistiveText) .style(.email) .padding() diff --git a/Sources/MisticaSwiftUI/Components/Inputfield/LegacyTextField.swift b/Sources/MisticaSwiftUI/Components/Inputfield/LegacyTextField.swift index da9f5306..4181be8d 100644 --- a/Sources/MisticaSwiftUI/Components/Inputfield/LegacyTextField.swift +++ b/Sources/MisticaSwiftUI/Components/Inputfield/LegacyTextField.swift @@ -25,6 +25,7 @@ struct LegacyTextField: UIViewRepresentable { var isSecured: Bool var keyboard: UIKeyboardType var inputStyle: LegacyTextFieldInputStyle + var textContentType: UITextContentType? func makeUIView(context: UIViewRepresentableContext) -> UITextField { let textField = ActionsTextField(frame: .zero) @@ -70,6 +71,7 @@ struct LegacyTextField: UIViewRepresentable { textField.autocapitalizationType = .none textField.autocorrectionType = .no textField.keyboardType = keyboard + textField.textContentType = textContentType textField.delegate = context.coordinator textField.textColor = Color.textPrimary.uiColor @@ -89,6 +91,10 @@ struct LegacyTextField: UIViewRepresentable { toolbar.sizeToFit() textField.inputAccessoryView = toolbar } + + mutating func textContentType(_ contentType: UITextContentType?) { + textContentType = contentType + } } // MARK: Coordinator