Skip to content

fix: native alert crash #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions ios/KeyboardMovementObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,6 @@ public class KeyboardMovementObserver: NSObject {
name: UIResponder.keyboardDidHideNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(windowDidBecomeVisible),
name: UIWindow.didBecomeVisibleNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(windowDidBecomeHidden),
name: UIWindow.didBecomeHiddenNotification,
object: nil
)
}

@objc func windowDidBecomeHidden(_: Notification) {
removeKVObserver()
}

@objc func windowDidBecomeVisible(_: Notification) {
setupKVObserver()
}

private func setupKVObserver() {
Expand Down Expand Up @@ -116,8 +96,8 @@ public class KeyboardMovementObserver: NSObject {
) {
// swiftlint:disable:next force_cast
if keyPath == "center", object as! NSObject == _keyboardView! {
// if we are currently animating keyboard or keyboard is not shown yet -> we need to ignore values from KVO
if displayLink != nil || keyboardHeight == 0.0 {
// if we are currently animating keyboard -> we need to ignore values from KVO
if displayLink != nil {
return
}

Expand Down Expand Up @@ -170,6 +150,7 @@ public class KeyboardMovementObserver: NSObject {
onNotify("KeyboardController::keyboardWillHide", data)

setupKeyboardWatcher()
removeKVObserver()
}

@objc func keyboardDidAppear(_ notification: Notification) {
Expand All @@ -184,15 +165,14 @@ public class KeyboardMovementObserver: NSObject {
onNotify("KeyboardController::keyboardDidShow", data)

removeKeyboardWatcher()
setupKVObserver()
}
}

@objc func keyboardDidDisappear() {
var data = [AnyHashable: Any]()
data["height"] = 0

keyboardHeight = 0.0

onEvent("onKeyboardMoveEnd", 0 as NSNumber, 0)
onNotify("KeyboardController::keyboardDidHide", data)

Expand Down