Skip to content
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

fix: crash in KeyboardMovementObserver due to incorrect KVO removal #787

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Jan 29, 2025

📜 Description

Fixed a crash in KeyboardMovementObserver due to incorrect KVO removal.

💡 Motivation and Context

Similar to #768

Instead of using plain KVO we are using block-scoped KVO, mainly to prevent random crashes, when we try to remove a KVO from a view that doesn't have it.

I can not 100% gurantee, that crash will not happen again, because a crash was very random and we can not reproduce it ourself (we just see it in Sentry) - so basically I can not test it.

But I'm pretty confident, that a new approach will fix the issue, since we will not accidentally remove KVO where it doesn't exist (because of block-scoped approach) 🤞

Also new approach reduces code duplication (such as if keyPath == "center") and reduces a number of code lines 👀

Fixes #152 (comment)

📢 Changelog

iOS

  • use block-scoped KVO in KeyboardMovementObserver;

🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro (iOS 17.5).

📸 Screenshots (if appropriate):

trimmed-kvo-new-approach.mp4

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@kirillzyusko kirillzyusko self-assigned this Jan 29, 2025
Copy link
Contributor

github-actions bot commented Jan 29, 2025

📊 Package size report

Current size Target Size Difference
168887 bytes 168937 bytes -50 bytes 📉

@kirillzyusko kirillzyusko added 🍎 iOS iOS specific 🎯 crash Library triggers a crash of the app labels Jan 29, 2025
@kirillzyusko kirillzyusko marked this pull request as ready for review January 29, 2025 16:18
@kirillzyusko kirillzyusko merged commit 49d20fc into main Jan 29, 2025
15 checks passed
@kirillzyusko kirillzyusko deleted the fix/crash-in-keybard-movement-observer-due-to-kvo branch January 29, 2025 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 crash Library triggers a crash of the app 🍎 iOS iOS specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS: Crash on @objc func windowDidBecomeHidden(_: Notification) { removeKVObserver() }
1 participant