Files
suixinkan_uikit/suixinkan/UI/Common/LoginTextField.swift
汉秋 699f1ba7c4 Add networking layer and wire up v9 login flow with unit tests.
Introduce APIClient/AuthAPI, complete login with multi-account selection, and polish the login card UI with shadow and keyboard dismiss.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 15:33:34 +08:00

90 lines
2.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// LoginTextField.swift
// suixinkan
//
import SnapKit
import UIKit
/// Android `PhoneInputField`
final class LoginTextField: UIView {
private let textField = UITextField()
var text: String {
get { textField.text ?? "" }
set { textField.text = newValue }
}
var onTextChange: ((String) -> Void)?
var onReturnKey: (() -> Void)?
var onEditingDidEnd: (() -> Void)?
init(placeholder: String) {
super.init(frame: .zero)
setupUI(placeholder: placeholder)
setupConstraints()
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@discardableResult
override func becomeFirstResponder() -> Bool {
textField.becomeFirstResponder()
}
private func setupUI(placeholder: String) {
backgroundColor = AppColor.inputBackground
layer.cornerRadius = 12
clipsToBounds = true
textField.font = .systemFont(ofSize: 14)
textField.textColor = AppColor.text333
textField.autocapitalizationType = .none
textField.autocorrectionType = .no
textField.returnKeyType = .next
textField.clearButtonMode = .whileEditing
textField.delegate = self
let attributes: [NSAttributedString.Key: Any] = [
.foregroundColor: AppColor.placeholder,
.font: UIFont.systemFont(ofSize: 14),
]
textField.attributedPlaceholder = NSAttributedString(string: placeholder, attributes: attributes)
textField.addTarget(self, action: #selector(textDidChange), for: .editingChanged)
textField.addTarget(self, action: #selector(editingDidEnd), for: .editingDidEnd)
addSubview(textField)
}
private func setupConstraints() {
snp.makeConstraints { make in
make.height.equalTo(46)
}
textField.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview().inset(16)
make.centerY.equalToSuperview()
}
}
@objc private func textDidChange() {
onTextChange?(text)
}
@objc private func editingDidEnd() {
onEditingDidEnd?()
}
}
extension LoginTextField: UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
onReturnKey?()
return true
}
}