-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Comments
@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 🙂 |
@kirillzyusko yes, on the latest version of the library and 2.14 for reanimated. |
@gtokman could you please also tell more about how do you use the library and when this exception occurs? How many |
@gtokman also, if you are able to test, could you please try to change:
to
Just add I have an assumption, that when we refer to |
@kirillzyusko I had the same issue and applying the patch from your PR fixes the crash for me. Thank you 👍 |
Awesome @cgav Glad to know the fix is actually working! |
## 📜 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
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? |
Yes, the issue will occur when you've wrapped app into @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. ![]() ![]() ![]() |
@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 @gunnartorfis since you are not using other functionality apart of |
@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. |
GitHub automatically closed this issue since PR that had a reference to this issue was merged. I've published |
I'm seeing this issue in bugsnag with
|
@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)? |
@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! |
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! |
…#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
@Antisane76 @bcgilliom fixed in #787 Will be published under |
Describe the bug
We have a crash that occurs on iOS when reading the reanimated keyboard height.
Code snippet
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](https://private-user-images.githubusercontent.com/12258850/238435699-83d3c376-4f47-4f7a-a873-dac084f6d021.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMjg0MzcsIm5iZiI6MTczOTEyODEzNywicGF0aCI6Ii8xMjI1ODg1MC8yMzg0MzU2OTktODNkM2MzNzYtNGY0Ny00ZjdhLWE4NzMtZGFjMDg0ZjZkMDIxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDE5MDg1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYxYjZlOTg0NjMwMjg1M2VkYzc3NDMxODcxN2RkMjA3MjcyZDM5M2ExNWY2Zjk5YzJmZGI5OWVhODZjNWMxNTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.RfrNUOJ8brscqNxWDj9FfnqP-L-Ls-_AU-LIB2EesMI)
Smartphone (please complete the following information):
The text was updated successfully, but these errors were encountered: