修复任务提交与弹窗交互问题

This commit is contained in:
2026-07-10 14:51:34 +08:00
parent df547a16dc
commit f88a85a807
48 changed files with 1065 additions and 254 deletions

View File

@ -630,7 +630,7 @@ final class CooperationAcquirerCell: UITableViewCell {
}
/// Android `CommissionRateEditDialog`
final class CooperationCommissionRateDialogView: UIView {
final class CooperationCommissionRateDialogView: KeyboardAvoidingDialogView {
var onCommissionRateChange: ((String) -> Void)?
var onSmsCodeChange: ((String) -> Void)?
@ -654,8 +654,6 @@ final class CooperationCommissionRateDialogView: UIView {
private let buttonStack = UIStackView()
private let cancelButton = UIButton(type: .system)
private let confirmButton = UIButton(type: .system)
private var cardCenterYConstraint: Constraint?
private var keyboardObservers: [NSObjectProtocol] = []
override init(frame: CGRect) {
super.init(frame: frame)
@ -667,10 +665,6 @@ final class CooperationCommissionRateDialogView: UIView {
fatalError("init(coder:) has not been implemented")
}
deinit {
unregisterKeyboardObservers()
}
func apply(commissionRate: String, smsCode: String, phone: String, countdown: Int) {
rateField.text = commissionRate
smsCodeField.text = smsCode
@ -690,7 +684,6 @@ final class CooperationCommissionRateDialogView: UIView {
alpha = 0
parent.addSubview(self)
layoutIfNeeded()
registerKeyboardObservers()
rateField.focus()
UIView.animate(withDuration: 0.2) {
self.alpha = 1
@ -699,7 +692,6 @@ final class CooperationCommissionRateDialogView: UIView {
func dismiss() {
endEditing(true)
unregisterKeyboardObservers()
UIView.animate(withDuration: 0.2, animations: {
self.alpha = 0
}, completion: { _ in
@ -708,6 +700,8 @@ final class CooperationCommissionRateDialogView: UIView {
}
private func setupUI() {
keyboardAvoidingContentView = cardView
dimView.backgroundColor = AppColor.overlayScrim
dimView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cancelTapped)))
@ -780,7 +774,7 @@ final class CooperationCommissionRateDialogView: UIView {
}
cardView.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview().inset(AppSpacing.md)
cardCenterYConstraint = make.centerY.equalToSuperview().constraint
keyboardAvoidingCenterYConstraint = make.centerY.equalToSuperview().constraint
}
titleLabel.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview().inset(AppSpacing.md)
@ -815,67 +809,6 @@ final class CooperationCommissionRateDialogView: UIView {
return row
}
private func registerKeyboardObservers() {
unregisterKeyboardObservers()
let center = NotificationCenter.default
keyboardObservers = [
center.addObserver(
forName: UIResponder.keyboardWillChangeFrameNotification,
object: nil,
queue: .main
) { [weak self] notification in
self?.handleKeyboardNotification(notification)
},
center.addObserver(
forName: UIResponder.keyboardWillHideNotification,
object: nil,
queue: .main
) { [weak self] notification in
self?.handleKeyboardNotification(notification)
}
]
}
private func unregisterKeyboardObservers() {
keyboardObservers.forEach(NotificationCenter.default.removeObserver)
keyboardObservers.removeAll()
}
private func handleKeyboardNotification(_ notification: Notification) {
layoutIfNeeded()
guard let userInfo = notification.userInfo else { return }
let duration = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0.25
let curveRaw = (userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue
?? UInt(UIView.AnimationCurve.easeInOut.rawValue)
let options = UIView.AnimationOptions(rawValue: curveRaw << 16)
let offset = keyboardAvoidanceOffset(from: userInfo)
cardCenterYConstraint?.update(offset: offset)
UIView.animate(withDuration: duration, delay: 0, options: options) {
self.layoutIfNeeded()
}
}
private func keyboardAvoidanceOffset(from userInfo: [AnyHashable: Any]) -> CGFloat {
guard
let keyboardFrameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
else {
return 0
}
let keyboardFrame = convert(keyboardFrameValue.cgRectValue, from: nil)
guard keyboardFrame.minY < bounds.height else { return 0 }
let cardHeight = cardView.bounds.height
let baseMinY = bounds.midY - cardHeight / 2
let baseMaxY = bounds.midY + cardHeight / 2
let desiredBottom = keyboardFrame.minY - AppSpacing.md
let neededShift = max(0, baseMaxY - desiredBottom)
let maxShift = max(0, baseMinY - AppSpacing.md)
return -min(neededShift, maxShift)
}
@objc private func sendCodeTapped() {
onSendSmsCode?()
}