Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(InputField): add option to set textContentType #385

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion Sources/MisticaSwiftUI/Components/Inputfield/InputField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public struct InputField: View {

public enum Style: Equatable {
case text
case numeric
case email
case secure
case phone(code: String)
Expand Down Expand Up @@ -175,7 +176,8 @@ private extension InputField {
isResponder: $editing,
isSecured: secure,
keyboard: keyboard,
inputStyle: inputStyle
inputStyle: inputStyle,
textContentType: textContentType
)
}

Expand All @@ -185,6 +187,7 @@ private extension InputField {
return secureActivated
case .phone,
.text,
.numeric,
.email,
.dropdown,
.date,
Expand All @@ -202,6 +205,7 @@ private extension InputField {
case .phone,
.secure,
.text,
.numeric,
.email,
.search:
return .text
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct LegacyTextField: UIViewRepresentable {
var isSecured: Bool
var keyboard: UIKeyboardType
var inputStyle: LegacyTextFieldInputStyle
var textContentType: UITextContentType?

func makeUIView(context: UIViewRepresentableContext<LegacyTextField>) -> UITextField {
let textField = ActionsTextField(frame: .zero)
Expand Down Expand Up @@ -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

Expand All @@ -89,6 +91,10 @@ struct LegacyTextField: UIViewRepresentable {
toolbar.sizeToFit()
textField.inputAccessoryView = toolbar
}

mutating func textContentType(_ contentType: UITextContentType?) {
textContentType = contentType
}
}

// MARK: Coordinator
Expand Down