Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Open
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
54 changes: 38 additions & 16 deletions AnimatedTextInput/Classes/AnimatedTextInputFieldConfigurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ public struct AnimatedTextInputFieldConfigurator {

public enum AnimatedTextInputType {
case standard
case password
case passwordWithDisclosure
case passwordWithoutDisclosure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to have the passwordWithoutDisclosure case, but leave password as it was so we do not modify existing api

case email
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update your branch, there is an email case already in 0.4

case numeric
case selection
case multiline
Expand All @@ -15,8 +17,12 @@ public struct AnimatedTextInputFieldConfigurator {
switch type {
case .standard:
return AnimatedTextInputTextConfigurator.generate()
case .password:
return AnimatedTextInputPasswordConfigurator.generate()
case .passwordWithDisclosure:
return AnimatedTextInputPasswordConfigurator.generateWithDisclosure(true)
case .passwordWithoutDisclosure:
return AnimatedTextInputPasswordConfigurator.generateWithDisclosure(false)
case .email:
return AnimatedTextInputEmailConfigurator.generate()
case .numeric:
return AnimatedTextInputNumericConfigurator.generate()
case .selection:
Expand All @@ -38,25 +44,41 @@ private struct AnimatedTextInputTextConfigurator {
}
}

private struct AnimatedTextInputEmailConfigurator {

static func generate() -> TextInput {
let textField = AnimatedTextField()
textField.keyboardType = .EmailAddress
textField.clearButtonMode = .WhileEditing
textField.autocapitalizationType = .None
textField.spellCheckingType = .No
textField.autocorrectionType = .No

return textField
}
}

private struct AnimatedTextInputPasswordConfigurator {

static func generate() -> TextInput {
static func generateWithDisclosure(visible: Bool = false) -> TextInput {
let textField = AnimatedTextField()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default for visibility is false, you could call this as generateWithDisclosure() and not get a disclosure button, which is confusing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but this configurator is private, so i don't think it's a big problem. Whatever it was this types was helpful in my product, suddenly someone else come in handy.

textField.rightViewMode = .WhileEditing
textField.secureTextEntry = true
let disclosureButton = UIButton(type: .Custom)
disclosureButton.frame = CGRect(origin: CGPoint.zero, size: CGSize(width: 20, height: 20))
let bundle = NSBundle(path: NSBundle(forClass: AnimatedTextInput.self).pathForResource("AnimatedTextInput", ofType: "bundle")!)
let normalImage = UIImage(named: "cm_icon_input_eye_normal", inBundle: bundle, compatibleWithTraitCollection: nil)
let selectedImage = UIImage(named: "cm_icon_input_eye_selected", inBundle: bundle, compatibleWithTraitCollection: nil)
disclosureButton.setImage(normalImage, forState: .Normal)
disclosureButton.setImage(selectedImage, forState: .Selected)
textField.add(disclosureButton: disclosureButton) {
disclosureButton.selected = !disclosureButton.selected
textField.resignFirstResponder()
textField.secureTextEntry = !textField.secureTextEntry
textField.becomeFirstResponder()
if visible {
let disclosureButton = UIButton(type: .Custom)
disclosureButton.frame = CGRect(origin: CGPoint.zero, size: CGSize(width: 20, height: 20))
let normalImage = UIImage(named: "cm_icon_input_eye_normal")
let selectedImage = UIImage(named: "cm_icon_input_eye_selected")
disclosureButton.setImage(normalImage, forState: .Normal)
disclosureButton.setImage(selectedImage, forState: .Selected)
textField.add(disclosureButton: disclosureButton) {
disclosureButton.selected = !disclosureButton.selected
textField.resignFirstResponder()
textField.secureTextEntry = !textField.secureTextEntry
textField.becomeFirstResponder()
}
}

return textField
}
}
Expand Down