Skip to content

Commit

Permalink
Merge pull request #4 from nmn/master
Browse files Browse the repository at this point in the history
Fix Handling of Updating modifiers
  • Loading branch information
AlexFine authored Jan 6, 2021
2 parents 3993f55 + a14ec36 commit 5c39125
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions Sources/iTextField/iTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,47 @@ public struct iTextField: UIViewRepresentable {
return textField
}

public func updateUIView(_ uiView: UITextField, context: Context) {
uiView.text = text
public func updateUIView(_ textField: UITextField, context: Context) {
textField.text = text
textField.placeholder = placeholder
textField.font = font
textField.textColor = foregroundColor
if let textAlignment = textAlignment {
textField.textAlignment = textAlignment
}

textField.clearsOnBeginEditing = clearsOnBeginEditing
textField.clearsOnInsertion = clearsOnInsertion

// Other settings
if let contentType = contentType {
textField.textContentType = contentType
}
if let accentColor = accentColor {
textField.tintColor = accentColor
}
textField.clearButtonMode = clearButtonMode
textField.autocorrectionType = autocorrection
textField.autocapitalizationType = autocapitalization
textField.keyboardType = keyboardType
textField.returnKeyType = returnKeyType

textField.isSecureTextEntry = isSecure
textField.isUserInteractionEnabled = isUserInteractionEnabled

textField.setContentHuggingPriority(.defaultHigh, for: .vertical)
textField.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)

textField.passwordRules = passwordRules
textField.smartDashesType = smartDashesType
textField.smartInsertDeleteType = smartInsertDeleteType
textField.smartQuotesType = smartQuotesType
textField.spellCheckingType = spellCheckingType

if isEditing.wrappedValue {
uiView.becomeFirstResponder()
textField.becomeFirstResponder()
} else {
uiView.resignFirstResponder()
textField.resignFirstResponder()
}
}

Expand Down

0 comments on commit 5c39125

Please sign in to comment.