Compare commits
2 Commits
1.0.6
...
a15d95ed59
| Author | SHA1 | Date | |
|---|---|---|---|
| a15d95ed59 | |||
|
|
40581d791a |
@@ -233,54 +233,37 @@ public extension LCSnackBarView {
|
||||
|
||||
/// Handles the `keyboardWillShowNotification` to adjust the snackbar's position.
|
||||
/// - Parameter notification: The `Notification` object containing keyboard information.
|
||||
@objc private func keyboardWillShow(_ notification: Notification?) -> Void {
|
||||
|
||||
if let info = notification?.userInfo {
|
||||
@MainActor
|
||||
@objc private func keyboardWillShow(_ notification: Notification?) {
|
||||
guard let info = notification?.userInfo else { return }
|
||||
|
||||
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
|
||||
|
||||
// Getting keyboard animation.
|
||||
if let curve = info[curveUserInfoKey] as? UIView.AnimationOptions {
|
||||
animationCurve = curve
|
||||
}
|
||||
let animationCurveRaw = (info[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber)?.uintValue
|
||||
?? UInt(UIView.AnimationCurve.easeOut.rawValue)
|
||||
let animationDuration = (info[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue
|
||||
?? 0.25
|
||||
let keyboardFrame = (info[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
|
||||
?? .zero
|
||||
let height = keyboardFrame.height
|
||||
let animationCurve = UIView.AnimationOptions(rawValue: animationCurveRaw << 16)
|
||||
|
||||
// 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,
|
||||
UIView.animate(
|
||||
withDuration: animationDuration,
|
||||
delay: 0,
|
||||
options: animationCurve,
|
||||
animations: {
|
||||
options: animationCurve
|
||||
) { [weak self] in
|
||||
self?.frame.origin.y += height
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles the `keyboardWillHideNotification`.
|
||||
/// - Parameter notification: The `Notification` object.
|
||||
@objc private func keyboardWillHide(_ notification: Notification?) -> Void {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.systemKeyboardVisible = false
|
||||
@MainActor
|
||||
@objc private func keyboardWillHide(_ notification: Notification?) {
|
||||
systemKeyboardVisible = false
|
||||
// keyboard is hidded
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the snackbar's style properties, such as width and corner radius, based on `_style`.
|
||||
private func updateStyle() {
|
||||
|
||||
Reference in New Issue
Block a user