fix: update keyboard notification handling for Swift concurrency #7

Merged
daniel-loverde merged 2 commits from bugfix/snackbar_for_iOS26 into main 2026-04-07 11:22:03 -03:00
Showing only changes of commit 40581d791a - Show all commits

View File

@@ -233,53 +233,36 @@ public extension LCSnackBarView {
/// Handles the `keyboardWillShowNotification` to adjust the snackbar's position. /// Handles the `keyboardWillShowNotification` to adjust the snackbar's position.
/// - Parameter notification: The `Notification` object containing keyboard information. /// - Parameter notification: The `Notification` object containing keyboard information.
@objc private func keyboardWillShow(_ notification: Notification?) -> Void { @MainActor
@objc private func keyboardWillShow(_ notification: Notification?) {
guard let info = notification?.userInfo else { return }
if let info = notification?.userInfo { systemKeyboardVisible = true
systemKeyboardVisible = true let animationCurveRaw = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue
// ?? UInt(UIView.AnimationCurve.easeOut.rawValue)
let curveUserInfoKey = UIResponder.keyboardAnimationCurveUserInfoKey let animationDuration = (info[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue
let durationUserInfoKey = UIResponder.keyboardAnimationDurationUserInfoKey ?? 0.25
let frameEndUserInfoKey = UIResponder.keyboardFrameEndUserInfoKey let keyboardFrame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
// ?? .zero
var animationCurve: UIView.AnimationOptions = .curveEaseOut let height = keyboardFrame.height
var animationDuration: TimeInterval = 0.25 let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw << 16)
var height:CGFloat = 0.0
// Getting keyboard animation. UIView.animate(
if let curve = info[curveUserInfoKey] as? UIView.AnimationOptions { withDuration: animationDuration,
animationCurve = curve delay: 0,
} options: animationCurve
) { [weak self] in
// Getting keyboard animation duration self?.frame.origin.y += height
if let duration = info[durationUserInfoKey] as? TimeInterval {
animationDuration = duration
}
// Getting UIKeyboardSize.
if let kbFrame = info[frameEndUserInfoKey] as? CGRect {
height = kbFrame.size.height
}
DispatchQueue.main.async { [weak self] in
UIView.animate(withDuration: animationDuration,
delay: 0,
options: animationCurve,
animations: {
self?.frame.origin.y += height
})
}
} }
} }
/// Handles the `keyboardWillHideNotification`. /// Handles the `keyboardWillHideNotification`.
/// - Parameter notification: The `Notification` object. /// - Parameter notification: The `Notification` object.
@objc private func keyboardWillHide(_ notification: Notification?) -> Void { @MainActor
DispatchQueue.main.async { [weak self] in @objc private func keyboardWillHide(_ notification: Notification?) {
self?.systemKeyboardVisible = false systemKeyboardVisible = false
// keyboard is hidded // keyboard is hidded
}
} }
/// Updates the snackbar's style properties, such as width and corner radius, based on `_style`. /// Updates the snackbar's style properties, such as width and corner radius, based on `_style`.