fix: use old keyboardView
reference for removing observer
#157
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
馃摐 Description
Use memoized
keyboardView
reference for removing observer.馃挕 Motivation and Context
Since
keyboardView
is a getter there are some chances that it may return a new reference to a view when we access it.In some cases it may be a problem, because it can return a reference to a view which doesn't contain an observer yet. As a result when we'll try to remove an observer from a view which doesn't have it -> we'll get a crash.
To prevent a crash in
removeKVObserver
we start to use_keyboardView
instead ofkeyboardView
. It'll give us an access to old view and we can safely remove the observer.Fixes #155
Potentially also fixes: #152
馃摙 Changelog
iOS
_keyboardView
instead ofkeyboardView
when remove observer;馃 How Has This Been Tested?
Tested on iPhone 14 (simulator, iOS 16.2) using following code:
馃摳 Screenshots (if appropriate):
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-05-30.at.16.55.42.mp4
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-05-30.at.16.54.08.mp4
馃摑 Checklist