Skip to content

Commit

Permalink
Forcing LTR on phone number field
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Guretzki committed Sep 4, 2024
1 parent 2ac077c commit d554e9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Adyen/UI/Form/Items/Phone Number/FormPhoneNumberItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ internal final class FormPhoneNumberItemView: FormTextItemView<FormPhoneNumberIt
}()

private func applyTextFieldLeftAccessoryView(textField: UITextField) {
textField.leftViewMode = .always
textField.leftView = phoneExtensionView
if UIView.userInterfaceLayoutDirection(for: textField.semanticContentAttribute) == .rightToLeft {
// If the interface direction is right to left we set the `rightView` so it shows up on the left side
// as in RTL languages the phone number still gets read from left to right
textField.rightViewMode = .always
textField.rightView = phoneExtensionView
} else {
textField.leftViewMode = .always
textField.leftView = phoneExtensionView
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public final class FormPhoneExtensionPickerItemView: FormItemView<FormPhoneExten
stackView.distribution = .fillProportionally
stackView.spacing = 6
stackView.isUserInteractionEnabled = false
// Phone numbers in RTL languages are still read left to right
// so we force it into this mode so the StackView order is consistent
stackView.semanticContentAttribute = .forceLeftToRight

let button = UIButton(type: .custom)
button.addTarget(self, action: #selector(handleSelection), for: .touchUpInside)
Expand Down

0 comments on commit d554e9f

Please sign in to comment.