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

iOS: Crash on @objc func windowDidBecomeHidden(_: Notification) { removeKVObserver() } #152

Closed
gtokman opened this issue May 15, 2023 · 18 comments · Fixed by #157 or #787
Closed

iOS: Crash on @objc func windowDidBecomeHidden(_: Notification) { removeKVObserver() } #152

gtokman opened this issue May 15, 2023 · 18 comments · Fixed by #157 or #787
Assignees
Labels
🐛 bug Something isn't working 🎯 crash Library triggers a crash of the app 🍎 iOS iOS specific

Comments

@gtokman
Copy link

gtokman commented May 15, 2023

Describe the bug

We have a crash that occurs on iOS when reading the reanimated keyboard height.

Code snippet

  const { height: keyboardHeight } = useReanimatedKeyboardAnimation()

Repo for reproducing
It's in our main application. I can't provided a project to reproduce at this time.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
CleanShot 2023-05-15 at 14 15 03@2x

mobile[62515:8433225] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <KeyboardMovementObserver 0x600007c9cba0> for the key path "center" from <UIInputSetHostView 0x1342e19e0> because it is not registered as an observer.'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000180437330 __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x0000000180051274 objc_exception_throw + 56
	2   Foundation                          0x0000000180b2f1e0 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 616
	3   Foundation                          0x0000000180b2f5bc -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 132
	4   Foundation                          0x0000000180b2f4d0 -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 184
	5   mobile                              0x00000001033eaf6c $s32react_native_keyboard_controller24KeyboardMovementObserverC16removeKVObserver33_98D42DC26656EA4CABF65DBC7E7C9563LLyyF + 192
	6   mobile                              0x00000001033eabb4 $s32react_native_keyboard_controller24KeyboardMovementObserverC21windowDidBecomeHiddenyy10Foundation12NotificationVF + 36
	7   mobile                              0x00000001033eac38 $s32react_native_keyboard_controller24KeyboardMovementObserverC21windowDidBecomeHiddenyy10Foundation12NotificationVFTo + 120
	8   CoreFoundation                      0x000000018036bff8 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 140
	9   CoreFoundation                      0x000000018036bf1c ___CFXRegistrationPost_block_invoke + 84
	10  CoreFoundation                      0x000000018036b424 _CFXRegistrationPost + 404
	11  CoreFoundation                      0x000000018036ae10 _CFXNotificationPost + 664
	12  Foundation                          0x0000000180b5309c -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
	13  UIKitCore                           0x0000000116dd3314 -[UIWindow _setHidden:forced:] + 680
	14  UIKitCore                           0x0000000116c380ec -[_UIRemoteKeyboards setWindowEnabled:force:] + 324
	15  UIKitCore                           0x0000000116c3a6b4 -[_UIRemoteKeyboards setWindowLevel:sceneLevel:forResponder:] + 588
	16  UIKitCore                           0x000000011683f8f8 -[UIKeyboardSceneDelegate setWindowLevel:sceneLevel:forResponder:] + 144
	17  UIKitCore                           0x000000011684048c -[UIKeyboardSceneDelegate setTextEffectsWindowLevelForInputView:responder:] + 864
	18  UIKitCore                           0x0000000116843cc4 -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:] + 524
	19  UIKitCore                           0x0000000116843a84 -[UIKeyboardSceneDelegate setInputViews:animationStyle:] + 132
	20  UIKitCore                           0x0000000116844a54 -[UIKeyboardSceneDelegate setInputViews:animated:] + 72
	21  UIKitCore                           0x0000000116844aa4 -[UIKeyboardSceneDelegate setInputViews:] + 52
	22  UIKitCore                           0x0000000116842b48 __102-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]_block_invoke.314 + 24
	23  UIKitCore                           0x0000000116c10d0c __65-[UIPeripheralHost(UIKitInternal) queueDelayedTask:forKey:delay:]_block_invoke + 156
	24  libdispatch.dylib                   0x0000000106bb1d50 _dispatch_client_callout + 16
	25  libdispatch.dylib                   0x0000000106bb5208 _dispatch_continuation_pop + 756
	26  libdispatch.dylib                   0x0000000106bcc8d4 _dispatch_source_invoke + 1676
	27  libdispatch.dylib                   0x0000000106bc2634 _dispatch_main_queue_drain + 848
	28  libdispatch.dylib                   0x0000000106bc22d4 _dispatch_main_queue_callback_4CF + 40
	29  CoreFoundation                      0x000000018039a784 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
	30  CoreFoundation                      0x0000000180394de4 __CFRunLoopRun + 1912
	31  CoreFoundation                      0x0000000180394254 CFRunLoopRunSpecific + 584
	32  GraphicsServices                    0x0000000188eb7c9c GSEventRunModal + 160
	33  UIKitCore                           0x0000000116d9aff0 -[UIApplication _run] + 868
	34  UIKitCore                           0x0000000116d9ef3c UIApplicationMain + 124
	35  mobile                              0x00000001027f7ed8 main + 96
	36  dyld                                0x0000000106579514 start_sim + 20
	37  ???                                 0x0000000106699f28 0x0 + 4402552616
	38  ???                                 0x3a17800000000000 0x0 + 4185955116152520704
)

Smartphone (please complete the following information):

  • iPhone 14 Pro, iOS 16.4, Xcode 14.3
@gtokman gtokman added the 🐛 bug Something isn't working label May 15, 2023
@kirillzyusko kirillzyusko added the 🍎 iOS iOS specific label May 15, 2023
@kirillzyusko
Copy link
Owner

@gtokman I guess it happens on latest version of the library, right?

As an intermediate solution I can suggest to revert back to 1.4.4

In a meantime I'll try to find a solution and provide a fix 🙂

@gtokman
Copy link
Author

gtokman commented May 15, 2023

@kirillzyusko yes, on the latest version of the library and 2.14 for reanimated.

@kirillzyusko
Copy link
Owner

kirillzyusko commented May 15, 2023

@gtokman could you please also tell more about how do you use the library and when this exception occurs?

How many KeyboardProviders do you have? When this exception occurs (I guess when keyboard becomes hidden, but how long do you need to show/hide keyboard before you meet an exception? Maybe you see the exception when you switch between different type of keyboards (like number/alphabetical keyboard)?

@kirillzyusko
Copy link
Owner

@gtokman also, if you are able to test, could you please try to change:

keyboardView?.removeObserver(self, forKeyPath: "center", context: nil)

to

_keyboardView?.removeObserver(self, forKeyPath: "center", context: nil)

Just add _ to keyboardView variable.

I have an assumption, that when we refer to keyboardView it may re-run a process of finding a view and return a new instance without a listener 🤷‍♂️

@kirillzyusko kirillzyusko mentioned this issue May 17, 2023
@kirillzyusko kirillzyusko added the 🎯 crash Library triggers a crash of the app label May 22, 2023
@kirillzyusko
Copy link
Owner

@gtokman could you please check whether #157 fixes the problem?

@cgav
Copy link

cgav commented May 31, 2023

@gtokman could you please check whether #157 fixes the problem?

@kirillzyusko I had the same issue and applying the patch from your PR fixes the crash for me. Thank you 👍

@kirillzyusko
Copy link
Owner

Awesome @cgav Glad to know the fix is actually working!
I'm going to merge this PR within this week and prepare a new release, since it's quite impactful change 😎

kirillzyusko added a commit that referenced this issue Jun 1, 2023
## 📜 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 of `keyboardView`. It'll give us an access to old view and we
can safely remove the observer.

Fixes
#155

Potentially also fixes:
#152

## 📢 Changelog

### iOS
- use `_keyboardView` instead of `keyboardView` when remove observer;

## 🤔 How Has This Been Tested?

Tested on iPhone 14 (simulator, iOS 16.2) using following code:

```tsx
<Button title="show image picker" onPress={async () => {
  // You can also use as a promise without 'callback':
  const result = await launchImageLibrary();
}} />
```

## 📸 Screenshots (if appropriate):

|Before|After|
|------|-----|
|<video
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/077f279e-f95b-4aea-ac09-41d8a7d4c846">|<video
src="https://github.com/kirillzyusko/react-native-keyboard-controller/assets/22820318/e5a5e9aa-2204-42cc-b767-07d43053bf7d">|

## 📝 Checklist

- [x] CI successfully passed
@gunnartorfis
Copy link

FYI I'm also having this issue. I'm just using the KeyboardProvider in my App.tsx, and then in one place in my app:

 React.useEffect(() => {
    const show = KeyboardEvents.addListener('keyboardWillShow', () => {
      bottomSheetRef.current?.expand();
    });

    return () => {
      show.remove();
    };
}, []);

The thing is that I can't reproduce this myself but Sentry has reported over 2.5k users experiencing this. What's weird to me about that 2.5k number is that the feature where the above code is, isn't much used. Could it be that the crash occurs when just applying the KeyboardProvider?

@kirillzyusko
Copy link
Owner

Hi @gunnartorfis

Yes, the issue will occur when you've wrapped app into KeyboardProvider (underhood it'll render KeyboardControllerView which setup all listeners and etc.).

@gunnartorfis could you please try to apply patch from #157 and see whether the amount of errors will be decreased?

@gunnartorfis
Copy link

gunnartorfis commented Jun 1, 2023

Hi @gunnartorfis

Yes, the issue will occur when you've wrapped app into KeyboardProvider (underhood it'll render KeyboardControllerView which setup all listeners and etc.).

@gunnartorfis could you please try to apply patch from #157 and see whether the amount of errors will be decreased?

I see, thanks. Since I'm unable to reproduce the issue myself I don't want to release the patch to production until it has been released. If you have any ideas on how I might reproduce this myself then I'd be happy to. It seems to be hitting quite the range of iOS versions, etc - I'm on 16.3 myself.

Screenshot 2023-06-01 at 09 12 22 Screenshot 2023-06-01 at 09 12 58 Screenshot 2023-06-01 at 09 12 18

@kirillzyusko
Copy link
Owner

@gunnartorfis that's the problem that I don't know how to reproduce this crash 🤷‍♂️ I can not reproduce the problem in example app and I don't have reproducible example.

I have only guesses, that the reference to the keyboard view is changing and I'm trying to remove an observer which doesn't exist anymore... I really hope this patch can fix everything - if not, then I'll be happy to continue investigation on how to resolve the problem. The new version of the library 1.5.4 will be published today.

@gunnartorfis since you are not using other functionality apart of keyboardWillShow you can safely downgrade keyboard-controller version to 1.4.4 - this version will not have crashes, since I'm not using KVO mechanism in this version.

@gunnartorfis
Copy link

@kirillzyusko Thanks for the info. I will downgrade for now and keep a close eye on this.

Feel free to tag me if there's anything I can do to help out.

@kirillzyusko
Copy link
Owner

GitHub automatically closed this issue since PR that had a reference to this issue was merged.

I've published 1.5.4 to npm-registry. Hopefully the issue is resolved, but in any case feel free to re-open this issue or feel free to create a new one.

@bcgilliom
Copy link
Contributor

I'm seeing this issue in bugsnag with 1.10.3 Here's the stack trace:

Hardware Model:     iPhone14,5
Process:            App
Identifier:         com.app
Role:               Foreground
OS Version:         iOS 16.5


NSRangeException: Cannot remove an observer <KeyboardMovementObserver 0x283160310> for the key path "center" from <UIInputSetHostView 0x10b613c70> because it is not registered as an observer.

0  CoreFoundation +0x9cb0      ___exceptionPreprocess
1  libobjc.A.dylib +0x183cc    _objc_exception_throw
2  Foundation +0x6621c         -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:]
3  Foundation +0x65f5c         -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:]
4  Foundation +0x65e6c         -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:]
5  App +0x571850           KeyboardMovementObserver.removeKVObserver() (KeyboardMovementObserver.swift:98:20)
6  App +0x572b50           @objc KeyboardMovementObserver.keyboardWillAppear(_:)
7  CoreFoundation +0x3758c     ___CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
8  CoreFoundation +0xdb824     ____CFXRegistrationPost_block_invoke
9  CoreFoundation +0xbe8b4     __CFXRegistrationPost
10 CoreFoundation +0x4baf8     __CFXNotificationPost
11 Foundation +0x5cd34         -[NSNotificationCenter postNotificationName:object:userInfo:]
12 UIKitCore +0xb7ed9c         -[UIInputWindowController postNotificationName:userInfo:]
13 UIKitCore +0x39245c         ___68-[UIInputWindowController postValidatedStartNotifications:withInfo:]_block_invoke
14 UIKitCore +0x3b2e28         -[UIInputWindowController postValidatedStartNotifications:withInfo:]
15 UIKitCore +0x314424         -[UIInputWindowController postStartNotifications:withInfo:]
16 UIKitCore +0xb7fad4         ___77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke_4
17 UIKitCore +0x3d8ad0         +[UIView(UIViewAnimationWithBlocksPrivate) _modifyAnimationsWithPreferredFrameRateRange:updateReason:animations:]
18 UIKitCore +0xcd2ac          +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:]
19 UIKitCore +0x5538c0         +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:]
20 UIKitCore +0x2ce2b4         -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:]
21 UIKitCore +0x2ce174         -[_UIViewControllerKeyboardAnimationStyle _launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:]
22 UIKitCore +0x2cde80         +[UIView(Animation) _performWithAnimation:]
23 UIKitCore +0x2cddc8         -[_UIViewControllerKeyboardAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:]
24 UIKitCore +0xb807d0         ___77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.459
25 UIKitCore +0x36f4e4         -[UIInputWindowController chainPlacementsIfNecessaryFrom:toPlacement:transition:completion:]
26 UIKitCore +0x36ca9c         -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]
27 UIKitCore +0x36bc00         -[UIInputWindowController setInputViewSet:]
28 UIKitCore +0x36b638         -[UIInputWindowController performOperations:withAnimationStyle:]
29 UIKitCore +0x27b92c         -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:]
30 UIKitCore +0x27ae20         -[UIKeyboardSceneDelegate setInputViews:animationStyle:]
31 UIKitCore +0x204678         -[UIKeyboardSceneDelegate setInputViews:animated:]
32 UIKitCore +0x20168c         -[UIKeyboardSceneDelegate setInputViews:]
33 UIKitCore +0x8ea2e4         ___102-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]_block_invoke.329
34 UIKitCore +0x8e9d74         -[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]
35 UIKitCore +0x8e8a30         -[UIKeyboardSceneDelegate _reloadInputViewsForResponder:force:fromBecomeFirstResponder:]
36 UIKitCore +0x27c8c0         -[UIResponder(UIResponderInputViewAdditions) reloadInputViews]
37 UIKitCore +0x21a44c         -[UIResponder becomeFirstResponder]
38 UIKitCore +0xfdb73c         ___99-[_UIRemoteViewController _serviceWantsKeyboardEventsWithPromotedFirstResponder:completionHandler:]_block_invoke

@kirillzyusko
Copy link
Owner

kirillzyusko commented Feb 26, 2024

@bcgilliom can you please test 1.11.0 and if it's still reproducible, then open a new issue? 🙏

And maybe you can shed some light on additional aspects, such as how frequently it happens, how much users are affected (in percentage, like 0.02% or smth like that), and maybe when it happens (maybe user navigated from modal screen to non-modal or something else)?

@bcgilliom
Copy link
Contributor

@kirillzyusko it seems to be extremely rare - we had a few reports early on, so I wasn't sure at first. I'll bump the library to latest and report back 👍 Thanks for all of your help and work on this lib. It's been great!

@Antisane76
Copy link

Hi @kirillzyusko I'm seeing this issue in Sentry using version 1.15.2 across different iPhones and iOS versions

As above it does seem to be quite rare so it's difficult to create a repro. From sentry breadcrumbs I can see that it's maybe related to backgrounding the app. After backgrounding event I see about 4 or so of these device events in quick succession before the exception

Device Event
info
11:46:53.338 AM
{
    action: UIKeyboardDidShowNotification
}

Device Event
info
11:46:53.286 AM
{
    action: UIKeyboardDidShowNotification
}

NPM packages

"expo": "52.0.27",
"react-native": "0.76.6"
"react-native-keyboard-controller" : "1.15.2"
New architecture enabled

Stacktrace

OS Version: iOS 18.1.1 (22B91)
Report Version: 104

Exception Type: EXC_CRASH (SIGABRT)
Crashed Thread: 0

Application Specific Information:
Cannot remove an observer < KeyboardMovementObserver 0x3005a8dc0 > for the key path "center" from < UIInputSetHostView 0x119403100 > because it is not registered as an observer.

Thread 0 Crashed:
0   CoreFoundation                  0x31ef8e7cc         __exceptionPreprocess
1   libobjc.A.dylib                 0x31959f2e0         objc_exception_throw
2   Foundation                      0x31c8a6368         -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:]
3   Foundation                      0x31c8a60a8         -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:]
4   Foundation                      0x31c8a5fc0         -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:]
5   App                    	    0x2036b5f30         [inlined] KeyboardMovementObserver.removeKVObserver (KeyboardMovementObserver.swift:107)
6   App                    	    0x2036b5f30         KeyboardMovementObserver.keyboardWillDisappear (KeyboardMovementObserver.swift:193)
7   App                    	    0x2036b6860         KeyboardMovementObserver.keyboardWillAppear
8   CoreFoundation                  0x31ef5d2f0         __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
9   CoreFoundation                  0x31ef5d20c         ___CFXRegistrationPost_block_invoke
10  CoreFoundation                  0x31ef5d154         _CFXRegistrationPost
11  CoreFoundation                  0x31ef5b708         _CFXNotificationPost
12  Foundation                      0x31c7c1ea0         -[NSNotificationCenter postNotificationName:object:userInfo:]
13  UIKitCore                       0x32428d88c         -[UIInputWindowController postNotificationName:userInfo:]
14  UIKitCore                       0x32428d304         __68-[UIInputWindowController postValidatedStartNotifications:withInfo:]_block_invoke
15  UIKitCore                       0x3241d05e0         -[UIInputWindowController postValidatedStartNotifications:withInfo:]
16  UIKitCore                       0x3241d032c         -[UIInputWindowController postStartNotifications:withInfo:]
17  UIKitCore                       0x324e190b8         __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.529
18  UIKitCore                       0x32428c04c         -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:]
19  UIKitCore                       0x324e1a2a4         __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.557
20  UIKitCore                       0x32428b970         -[UIInputWindowController chainPlacementsIfNecessaryFrom:toPlacement:transition:completion:]
21  UIKitCore                       0x3240ce9f8         -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]
22  UIKitCore                       0x3241cdaec         -[UIInputWindowController setInputViewSet:]
23  UIKitCore                       0x3241cd444         -[UIInputWindowController performOperations:withAnimationStyle:]
24  UIKitCore                       0x32402c2f8         -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:]
25  UIKitCore                       0x3241ce4d8         -[UIKeyboardSceneDelegate setInputViews:animationStyle:]
26  UIKitCore                       0x3241ce400         -[UIKeyboardSceneDelegate setInputViews:animated:]
27  UIKitCore                       0x3241ce390         -[UIKeyboardSceneDelegate setInputViews:]
28  UIKitCore                       0x324b050f0         __102-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]_block_invoke.563
29  UIKitCore                       0x324172064         -[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:]
30  UIKitCore                       0x3241ce62c         -[UIKeyboardSceneDelegate _reloadInputViewsForResponder:force:fromBecomeFirstResponder:]
31  UIKitCore                       0x32420b528         -[UIResponder _finishResignFirstResponderFromBecomeFirstResponder:]
32  UIKitCore                       0x32420aa4c         -[UIResponder resignFirstResponder]
33  UIKitCore                       0x324013944         -[UITextView resignFirstResponder]
34  UIKitCore                       0x323fa11f4         __UIViewWillBeRemovedFromSuperview
35  UIKitCore                       0x323fa0d20         -[UIView(Hierarchy) removeFromSuperview]
36  App                    	    0x2032e52cc         -[RCTSurfaceHostingView setIsSurfaceViewVisible:] (RCTSurfaceHostingView.mm:182)
37  App                    	    0x2032e5554         -[RCTSurfaceHostingView _updateViews] (RCTSurfaceHostingView.mm:221)
38  App                    	    0x2032f1c04         RCTExecuteOnMainQueue (RCTUtils.m:276)
39  App                    	    0x2032e5614         -[RCTSurfaceHostingView surface:didChangeStage:] (RCTSurfaceHostingView.mm:235)
40  App                    	    0x2032e486c         -[RCTSurfaceHostingProxyRootView surface:didChangeStage:] (RCTSurfaceHostingProxyRootView.mm:124)
41  App                    	    0x2033f05a0         -[RCTFabricSurface _propagateStageChange] (RCTFabricSurface.mm:167)
42  App                    	    0x2033f02e0         -[RCTFabricSurface stop] (RCTFabricSurface.mm:122)
43  App                    	    0x203410ff0         __53-[RCTSurfacePresenter _stopAllSurfacesWithScheduler:]_block_invoke (RCTSurfacePresenter.mm:291)
44  App                    	    0x2034145c0         -[RCTSurfaceRegistry enumerateWithBlock:] (RCTSurfaceRegistry.mm:35)
45  App                    	    0x203410f1c         -[RCTSurfacePresenter _stopAllSurfacesWithScheduler:] (RCTSurfacePresenter.mm:289)
46  App                    	    0x203410110         -[RCTSurfacePresenter suspend] (RCTSurfacePresenter.mm:197)
47  CoreFoundation                  0x31ef5d2f0         __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__
48  CoreFoundation                  0x31ef5d20c         ___CFXRegistrationPost_block_invoke
49  CoreFoundation                  0x31ef5d154         _CFXRegistrationPost
50  CoreFoundation                  0x31ef5b708         _CFXNotificationPost
51  Foundation                      0x31c7c1ea0         -[NSNotificationCenter postNotificationName:object:userInfo:]
52  UIKitCore                       0x325017dec         -[UIApplication _terminateWithStatus:]
53  UIKitCore                       0x324056f84         -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
54  UIKitCore                       0x3248378f0         -[_UISceneLifecycleMultiplexer forceExitWithTransitionContext:scene:]
55  UIKitCore                       0x325013548         -[UIApplication workspaceShouldExit:withTransitionContext:]
56  FrontBoardServices              0x351b76f64         __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke_2
57  FrontBoardServices              0x351b36c40         -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
58  FrontBoardServices              0x351b76f04         __63-[FBSWorkspaceScenesClient willTerminateWithTransitionContext:]_block_invoke
59  libdispatch.dylib               0x32e9b80cc         _dispatch_client_callout
60  libdispatch.dylib               0x32e9bbb10         _dispatch_block_invoke_direct
61  FrontBoardServices              0x351b382fc         __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
62  FrontBoardServices              0x351b3827c         -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible]
63  FrontBoardServices              0x351b38154         -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource]
64  CoreFoundation                  0x31ef62324         __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
65  CoreFoundation                  0x31ef622b8         __CFRunLoopDoSource0
66  CoreFoundation                  0x31ef5fdbc         __CFRunLoopDoSources0
67  CoreFoundation                  0x31ef5efb8         __CFRunLoopRun
68  CoreFoundation                  0x31ef5e82c         CFRunLoopRunSpecific
69  GraphicsServices                0x3b6f6f1c0         GSEventRunModal
70  UIKitCore                       0x3242aaeac         -[UIApplication _run]
71  UIKitCore                       0x3243595b0         UIApplicationMain
72  App                    	    0x202f9c528         main (main.m:7)

Let me know if there's anything else I can provide and I'll see what I can do. Thanks!

kirillzyusko added a commit that referenced this issue Jan 29, 2025
…#787)

## 📜 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

<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->

### iOS

- use block-scoped KVO in `KeyboardMovementObserver`;

## 🤔 How Has This Been Tested?

Tested manually on iPhone 15 Pro (iOS 17.5).

## 📸 Screenshots (if appropriate):


https://github.com/user-attachments/assets/acb009a1-8c25-44c5-93ff-cf1ad0a48dc7

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
@kirillzyusko
Copy link
Owner

@Antisane76 @bcgilliom fixed in #787 Will be published under 1.16.1 by the end of this week or next week 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🎯 crash Library triggers a crash of the app 🍎 iOS iOS specific
Projects
None yet
6 participants