Compare commits
3 Commits
57ce0dc87a
...
1.0.7
| Author | SHA1 | Date | |
|---|---|---|---|
| c0eb5f95c6 | |||
| a15d95ed59 | |||
|
|
40581d791a |
@@ -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?) {
|
||||||
if let info = notification?.userInfo {
|
guard let info = notification?.userInfo else { return }
|
||||||
|
|
||||||
systemKeyboardVisible = true
|
systemKeyboardVisible = true
|
||||||
//
|
|
||||||
let curveUserInfoKey = UIResponder.keyboardAnimationCurveUserInfoKey
|
let animationCurveRaw = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue
|
||||||
let durationUserInfoKey = UIResponder.keyboardAnimationDurationUserInfoKey
|
?? UInt(UIView.AnimationCurve.easeOut.rawValue)
|
||||||
let frameEndUserInfoKey = UIResponder.keyboardFrameEndUserInfoKey
|
let animationDuration = (info[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue
|
||||||
//
|
?? 0.25
|
||||||
var animationCurve: UIView.AnimationOptions = .curveEaseOut
|
let keyboardFrame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
|
||||||
var animationDuration: TimeInterval = 0.25
|
?? .zero
|
||||||
var height:CGFloat = 0.0
|
let height = keyboardFrame.height
|
||||||
|
let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw << 16)
|
||||||
// Getting keyboard animation.
|
|
||||||
if let curve = info[curveUserInfoKey] as? UIView.AnimationOptions {
|
UIView.animate(
|
||||||
animationCurve = curve
|
withDuration: animationDuration,
|
||||||
}
|
delay: 0,
|
||||||
|
options: animationCurve
|
||||||
// Getting keyboard animation duration
|
) { [weak self] in
|
||||||
if let duration = info[durationUserInfoKey] as? TimeInterval {
|
self?.frame.origin.y += height
|
||||||
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`.
|
||||||
|
|||||||
Reference in New Issue
Block a user