Skip to content

fix: do not force cast KVO values #359

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 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions ios/observers/FocusedInputObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ public class FocusedInputObserver: NSObject {
change _: [NSKeyValueChangeKey: Any]?,
context _: UnsafeMutableRawPointer?
) {
// swiftlint:disable:next force_cast
if keyPath == "center", object as! NSObject == currentInput! {
if keyPath == "center", object as? NSObject == currentInput {
// we need to read layout in next frame, otherwise we'll get old
// layout values
DispatchQueue.main.async {
Expand Down
9 changes: 5 additions & 4 deletions ios/observers/KeyboardMovementObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public class KeyboardMovementObserver: NSObject {
change: [NSKeyValueChangeKey: Any]?,
context _: UnsafeMutableRawPointer?
) {
// swiftlint:disable:next force_cast
if keyPath == "center", object as! NSObject == _keyboardView! {
if keyPath == "center", object as? NSObject == _keyboardView {
// if we are currently animating keyboard -> we need to ignore values from KVO
if displayLink != nil {
return
Expand All @@ -117,8 +116,10 @@ public class KeyboardMovementObserver: NSObject {
return
}

// swiftlint:disable:next force_cast
let keyboardFrameY = (change?[.newKey] as! NSValue).cgPointValue.y
guard let changeValue = change?[.newKey] as? NSValue else {
return
}
let keyboardFrameY = changeValue.cgPointValue.y
let keyboardWindowH = keyboardView?.window?.bounds.size.height ?? 0
let keyboardPosition = keyboardWindowH - keyboardFrameY
let position = CGFloat.interpolate(
Expand Down