From 73106f3f9763a063f7021642c0cf531bfd4c2aad Mon Sep 17 00:00:00 2001 From: acevif Date: Thu, 6 Dec 2018 19:39:55 +0900 Subject: [PATCH 1/3] Add UITextInputTraits conformance --- Pod/PinCodeTextField.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pod/PinCodeTextField.swift b/Pod/PinCodeTextField.swift index f9a360d..793f36f 100644 --- a/Pod/PinCodeTextField.swift +++ b/Pod/PinCodeTextField.swift @@ -9,7 +9,7 @@ import Foundation import UIKit -@IBDesignable open class PinCodeTextField: UIView { +@IBDesignable open class PinCodeTextField: UIView, UITextInputTraits { public weak var delegate: PinCodeTextFieldDelegate? //MARK: Customizable from Interface Builder From 92e358b0328ede6a4cfaad15a2921e9515bb285b Mon Sep 17 00:00:00 2001 From: acevif Date: Thu, 6 Dec 2018 19:44:07 +0900 Subject: [PATCH 2/3] Set default textContentType to .oneTimeCode after iOS12 - Set default textContentType to .oneTimeCode to get the most out of iOS12's Security Code AutoFill See also: * https://developer.apple.com/videos/play/wwdc2018/204/ * https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_a_text_input_view --- Pod/PinCodeTextField.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Pod/PinCodeTextField.swift b/Pod/PinCodeTextField.swift index 793f36f..ceeac32 100644 --- a/Pod/PinCodeTextField.swift +++ b/Pod/PinCodeTextField.swift @@ -52,7 +52,14 @@ import UIKit public var autocorrectionType: UITextAutocorrectionType = UITextAutocorrectionType.no public var font: UIFont = UIFont.systemFont(ofSize: 14) public var allowedCharacterSet: CharacterSet = CharacterSet.alphanumerics - public var textContentType: UITextContentType! = nil + + public lazy var textContentType: UITextContentType! = { + guard #available(iOS 12.0, *) else { + return nil + } + + return UITextContentType.oneTimeCode + }() private var _inputView: UIView? open override var inputView: UIView? { From 4af74777a12de49f0f9205d4a3c3c779b3e78c21 Mon Sep 17 00:00:00 2001 From: acevif Date: Thu, 6 Dec 2018 20:30:28 +0900 Subject: [PATCH 3/3] [WIP] Conform UITextInput protocol --- Pod/PinCodeTextField.swift | 88 +++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/Pod/PinCodeTextField.swift b/Pod/PinCodeTextField.swift index ceeac32..9131318 100644 --- a/Pod/PinCodeTextField.swift +++ b/Pod/PinCodeTextField.swift @@ -9,7 +9,93 @@ import Foundation import UIKit -@IBDesignable open class PinCodeTextField: UIView, UITextInputTraits { +@IBDesignable open class PinCodeTextField: UIView, UITextInput { + public func replace(_ range: UITextRange, withText text: String) { + } + + public var selectedTextRange: UITextRange? = nil + + public var markedTextRange: UITextRange? = nil + + public var markedTextStyle: [AnyHashable : Any]? = nil + + public func setMarkedText(_ markedText: String?, selectedRange: NSRange) { + } + + public func unmarkText() { + } + + public var beginningOfDocument: UITextPosition = UITextPosition() + + public var endOfDocument: UITextPosition = UITextPosition() + + public func textRange(from fromPosition: UITextPosition, to toPosition: UITextPosition) -> UITextRange? { + return nil + } + + public func position(from position: UITextPosition, offset: Int) -> UITextPosition? { + return nil + } + + public func position(from position: UITextPosition, in direction: UITextLayoutDirection, offset: Int) -> UITextPosition? { + return nil + } + + public func compare(_ position: UITextPosition, to other: UITextPosition) -> ComparisonResult { + return ComparisonResult.orderedSame + } + + public func offset(from: UITextPosition, to toPosition: UITextPosition) -> Int { + return 0 + } + + public var inputDelegate: UITextInputDelegate? + + public var tokenizer: UITextInputTokenizer = UITextInputStringTokenizer() + + public func position(within range: UITextRange, farthestIn direction: UITextLayoutDirection) -> UITextPosition? { + return nil + } + + public func characterRange(byExtending position: UITextPosition, in direction: UITextLayoutDirection) -> UITextRange? { + return nil + } + + public func baseWritingDirection(for position: UITextPosition, in direction: UITextStorageDirection) -> UITextWritingDirection { + return UITextWritingDirection.natural + } + + public func setBaseWritingDirection(_ writingDirection: UITextWritingDirection, for range: UITextRange) { + } + + public func firstRect(for range: UITextRange) -> CGRect { + return CGRect.zero + } + + public func caretRect(for position: UITextPosition) -> CGRect { + return CGRect.zero + } + + public func selectionRects(for range: UITextRange) -> [Any] { + return [] + } + + public func closestPosition(to point: CGPoint) -> UITextPosition? { + return nil + } + + public func closestPosition(to point: CGPoint, within range: UITextRange) -> UITextPosition? { + return nil + } + + public func characterRange(at point: CGPoint) -> UITextRange? { + return nil + } + + public func text(in range: UITextRange) -> String? { + return nil + } + public weak var delegate: PinCodeTextFieldDelegate? //MARK: Customizable from Interface Builder