8 Commits

View File

@@ -233,37 +233,54 @@ 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.
@MainActor @objc private func keyboardWillShow(_ notification: Notification?) -> Void {
@objc private func keyboardWillShow(_ notification: Notification?) {
guard let info = notification?.userInfo else { return } if let info = notification?.userInfo {
systemKeyboardVisible = true systemKeyboardVisible = true
//
let curveUserInfoKey = UIResponder.keyboardAnimationCurveUserInfoKey
let durationUserInfoKey = UIResponder.keyboardAnimationDurationUserInfoKey
let frameEndUserInfoKey = UIResponder.keyboardFrameEndUserInfoKey
//
var animationCurve: UIView.AnimationOptions = .curveEaseOut
var animationDuration: TimeInterval = 0.25
var height:CGFloat = 0.0
let animationCurveRaw = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue // Getting keyboard animation.
?? UInt(UIView.AnimationCurve.easeOut.rawValue) if let curve = info[curveUserInfoKey] as? UIView.AnimationOptions {
let animationDuration = (info[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue animationCurve = curve
?? 0.25 }
let keyboardFrame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
?? .zero
let height = keyboardFrame.height
let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw << 16)
UIView.animate( // Getting keyboard animation duration
withDuration: animationDuration, 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, delay: 0,
options: animationCurve options: animationCurve,
) { [weak self] in animations: {
self?.frame.origin.y += height self?.frame.origin.y += height
})
}
} }
} }
/// Handles the `keyboardWillHideNotification`. /// Handles the `keyboardWillHideNotification`.
/// - Parameter notification: The `Notification` object. /// - Parameter notification: The `Notification` object.
@MainActor @objc private func keyboardWillHide(_ notification: Notification?) -> Void {
@objc private func keyboardWillHide(_ notification: Notification?) { DispatchQueue.main.async { [weak self] in
systemKeyboardVisible = false self?.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`.
private func updateStyle() { private func updateStyle() {