8 Commits

View File

@@ -233,36 +233,53 @@ 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 }
systemKeyboardVisible = true if let info = notification?.userInfo {
let animationCurveRaw = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue systemKeyboardVisible = true
?? UInt(UIView.AnimationCurve.easeOut.rawValue) //
let animationDuration = (info[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue let curveUserInfoKey = UIResponder.keyboardAnimationCurveUserInfoKey
?? 0.25 let durationUserInfoKey = UIResponder.keyboardAnimationDurationUserInfoKey
let keyboardFrame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue let frameEndUserInfoKey = UIResponder.keyboardFrameEndUserInfoKey
?? .zero //
let height = keyboardFrame.height var animationCurve: UIView.AnimationOptions = .curveEaseOut
let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw << 16) var animationDuration: TimeInterval = 0.25
var height:CGFloat = 0.0
UIView.animate( // Getting keyboard animation.
withDuration: animationDuration, if let curve = info[curveUserInfoKey] as? UIView.AnimationOptions {
delay: 0, animationCurve = curve
options: animationCurve }
) { [weak self] in
self?.frame.origin.y += height // Getting keyboard animation duration
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.
@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`.