Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ internal class StoredCardInputViewController: UIViewController {
}()

private lazy var securityCodeItemView: FormCardSecurityCodeItemView = {
// TODO: Robert: StoredView: 🐞 There is a bug(COSDK-572) with FormCardSecurityCodeItemView that when i type more than 3 characters only 3 display but validation happens with 4+ characters and then it fails validation. Needs to be debugged separately.
let view = FormCardSecurityCodeItemView(item: viewModel.securityCodeItem, theme: theme)
view.translatesAutoresizingMaskIntoConstraints = false
view.accessibilityIdentifier = ViewIdentifierBuilder.build(scopeInstance: self, postfix: "securityCodeItemView")
view.delegate = self
return view
}()

Expand Down Expand Up @@ -177,6 +177,7 @@ internal class StoredCardInputViewController: UIViewController {
configureContent()
setupBindings()
disableSwipeDownToDismissScreen()
securityCodeItemView.becomeFirstResponder()
}

private func disableSwipeDownToDismissScreen() {
Expand Down Expand Up @@ -205,6 +206,9 @@ internal class StoredCardInputViewController: UIViewController {
}

private func updateLoadingState(_ isLoading: Bool) {
if isLoading {
securityCodeItemView.resignFirstResponder()
}
primaryButton.isEnabled = !isLoading
primaryButton.showsActivityIndicator = isLoading
securityCodeItemView.isUserInteractionEnabled = !isLoading
Expand Down Expand Up @@ -233,3 +237,13 @@ internal class StoredCardInputViewController: UIViewController {
}
}
}

extension StoredCardInputViewController: FormTextItemViewDelegate {
internal func didReachMaximumLength(in itemView: FormTextItemView<some FormTextItem>) {
securityCodeItemView.resignFirstResponder()
}

internal func didSelectReturnKey(in itemView: FormTextItemView<some FormTextItem>) {
securityCodeItemView.resignFirstResponder()
}
}
Comment thread
robertdalmeida marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ struct StoredCardInputViewControllerTests {
#expect(viewModel.viewDidDisappearCallsCount == 1)
}

// MARK: - D: Security code input behavior

@Test
func typingThreeCharactersInSecurityCode_resignsFirstResponder() async throws {
let (proxy, _) = makeSUT()
await proxy.load()

let securityCodeView = try proxy.securityCodeItemView()
#expect(securityCodeView.isFirstResponder)
try proxy.enterCode("123")
#expect(!securityCodeView.isFirstResponder)
}

// MARK: - Helpers

private func makeSUT(
Expand Down Expand Up @@ -216,6 +229,12 @@ struct StoredCardInputViewControllerProxy {
)
}

func enterCode(_ code: String) throws {
let textField = try securityCodeItemView().textField
code.forEach { textField.insertText(String($0)) }
textField.sendActions(for: .editingChanged)
}

func tapPrimaryButton() throws {
try primaryButton().sendActions(for: .touchUpInside)
}
Expand Down
Loading