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

Fix memory leak and fix crash #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension CardTextField: CardInfoTextFieldDelegate {

// Let the next text field become first responder if one of the contained text fields
// already is first responder.
if isFirstResponder {
if isChildFirstResponder {
nextTextField?.becomeFirstResponder()
}

Expand Down
2 changes: 1 addition & 1 deletion Pod/Classes/UI/CardTextField+PrefillInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension CardTextField {
cvcTextField?.prefill(cvc)
}

moveCardNumberOutAnimated(remainFirstResponder: isFirstResponder)
moveCardNumberOutAnimated(remainFirstResponder: isChildFirstResponder)

notifyDelegate()
}
Expand Down
25 changes: 11 additions & 14 deletions Pod/Classes/UI/CardTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ open class CardTextField: UITextField, NumberInputTextFieldDelegate {
}
}

open override var isFirstResponder: Bool {
open var isChildFirstResponder: Bool {
// Return true if any of `self`'s subviews is the current first responder.
return [numberInputTextField,monthTextField,yearTextField,cvcTextField]
.filter({$0.isFirstResponder})
Expand Down Expand Up @@ -417,7 +417,7 @@ open class CardTextField: UITextField, NumberInputTextFieldDelegate {

/// Function for the swipe gesture recognizer for moving out the card number.
@objc private func swipeHideCardNumber() {
moveCardNumberOutAnimated(remainFirstResponder: isFirstResponder)
moveCardNumberOutAnimated(remainFirstResponder: isChildFirstResponder)
}

/**
Expand Down Expand Up @@ -506,12 +506,12 @@ open class CardTextField: UITextField, NumberInputTextFieldDelegate {

open func numberInputTextFieldDidComplete(_ numberInputTextField: NumberInputTextField) {
// Retain the first responder status if currently first responder.
moveCardNumberOutAnimated(remainFirstResponder: isFirstResponder)
moveCardNumberOutAnimated(remainFirstResponder: isChildFirstResponder)

notifyDelegate()
hideExpiryTextFields = !cardTypeRegister.cardType(for: numberInputTextField.cardNumber).requiresExpiry
hideCVCTextField = !cardTypeRegister.cardType(for: numberInputTextField.cardNumber).requiresCVC
if hideExpiryTextFields && hideCVCTextField || !isFirstResponder {
if hideExpiryTextFields && hideCVCTextField || !isChildFirstResponder {
return
} else if hideExpiryTextFields {
cvcTextField.becomeFirstResponder()
Expand Down Expand Up @@ -605,21 +605,18 @@ open class CardTextField: UITextField, NumberInputTextFieldDelegate {
}

open override func becomeFirstResponder() -> Bool {
// Return false if any of this text field's subviews is already first responder.
// Otherwise let `numberInputTextField` become the first responder.
if [numberInputTextField,monthTextField,yearTextField,cvcTextField]
.map({return $0.isFirstResponder})
.reduce(true, {$0 && $1}) {
return false
}
return numberInputTextField.becomeFirstResponder()
super.becomeFirstResponder()
super.resignFirstResponder()
return false
}

open override func resignFirstResponder() -> Bool {
// If any of `self`'s subviews is first responder, resign first responder status.
return [numberInputTextField,monthTextField,yearTextField,cvcTextField]
[numberInputTextField,monthTextField,yearTextField,cvcTextField]
.filter({$0.isFirstResponder})
.first?
.resignFirstResponder() ?? true
.resignFirstResponder()

return super.resignFirstResponder()
}
}