douglasjunior / react-native-keyboard-manager

⚛ Library to prevent issues of keyboard sliding up and cover inputs on React-Native iOS projects.
https://www.npmjs.com/package/react-native-keyboard-manager
MIT License
934 stars 60 forks source link

Crash on IOS 14 #73

Closed VitamineC closed 3 years ago

VitamineC commented 3 years ago

App chased on start with error

static let kbManager = IQKeyboardManager() "Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread."

douglasjunior commented 3 years ago

Hi @VitamineC, thanks for the feedback.

Could you provide more information about when the error happens, and how to reproduce it?

We are running some apps on iOS 14 and we haven't seen any problems like this yet.

marcinkornek commented 3 years ago

I have exactly the same stack and I have the same error when building ios :(

the error says: Thread 3: "Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread."

image

douglasjunior commented 3 years ago

Could you copy the entire stacktrace?

I need to know which method of this module is starting the problem: https://github.com/douglasjunior/react-native-keyboard-manager/blob/master/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m

marcinkornek commented 3 years ago
Thread 13 Queue : com.facebook.react.ReactNativeKeyboardManagerQueue (serial)
#0  0x00007fff60c5833a in __pthread_kill ()
#1  0x00007fff60c8de60 in pthread_kill ()
#2  0x00007fff200fab94 in abort ()
#3  0x00007fff20252818 in abort_message ()
#4  0x00007fff20243e7d in demangling_terminate_handler() ()
#5  0x00007fff201780d1 in _objc_terminate() ()
#6  0x00007fff20251c47 in std::__terminate(void (*)()) ()
#7  0x00007fff20251be9 in std::terminate() ()
#8  0x00007fff20178071 in objc_terminate ()
#9  0x00000001145cc9dc in _dispatch_client_callout ()
#10 0x00000001145cdf33 in _dispatch_once_callout ()
#11 0x0000000113c89e5a in swift_once ()
#12 0x000000010e41f0c4 in kbManager.unsafeMutableAddressor in Static #1 in static IQKeyboardManager.shared.getter at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQKeyboardManager.swift:179
#13 0x000000010e41f069 in static IQKeyboardManager.shared.getter at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQKeyboardManager.swift:183
#14 0x000000010e41f03c in @objc static IQKeyboardManager.shared.getter ()
#15 0x000000010e89f8f3 in -[ReactNativeKeyboardManager setToolbarPreviousNextButtonEnable:] at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native-keyboard-manager/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m:108
#16 0x00007fff204272fc in __invoking___ ()
#17 0x00007fff204247b6 in -[NSInvocation invoke] ()
#18 0x00007fff20424a47 in -[NSInvocation invokeWithTarget:] ()
#19 0x000000010e61e2e4 in -[RCTModuleMethod invokeWithBridge:module:arguments:] at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/Base/RCTModuleMethod.mm:584
#20 0x000000010e62248e in facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:114
#21 0x000000010e621f56 in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:75
#22 0x000000010e621ebc in invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:67
#23 0x00000001145cb7ec in _dispatch_call_block_and_release ()
#24 0x00000001145cc9c8 in _dispatch_client_callout ()
#25 0x00000001145d3296 in _dispatch_lane_serial_drain ()
#26 0x00000001145d3f67 in _dispatch_lane_invoke ()
#27 0x00000001145dfde2 in _dispatch_workloop_worker_thread ()
#28 0x00007fff60c8aa3d in _pthread_wqthread ()
#29 0x00007fff60c89b77 in start_wqthread ()
Thread#0    0x00007fff20420ae6 in __exceptionPreprocess ()
#1  0x00007fff20177e78 in objc_exception_throw ()
#2  0x00007fff59575c89 in _AssertAutoLayoutOnAllowedThreadsOnly ()
#3  0x00007fff59575f15 in -[NSISEngine withBehaviors:performModifications:] ()
#4  0x00007fff24af91c7 in __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke ()
#5  0x00007fff24af8f66 in -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] ()
#6  0x00007fff24af7fa6 in -[UIView(AdditionalLayoutSupport) _initializeHostedLayoutEngine] ()
#7  0x00007fff24af973d in -[UIView(AdditionalLayoutSupport) _layoutEngineCreateIfNecessary] ()
#8  0x00007fff24aec076 in -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] ()
#9  0x00007fff24aec60e in -[UIView(UIConstraintBasedLayout) nsli_addConstraint:] ()
#10 0x00007fff5958f17a in +[NSLayoutConstraint _addOrRemoveConstraints:activate:] ()
#11 0x00007fff23ca6aad in -[_UIToolbarContentView _ensureButtonBar] ()
#12 0x00007fff23ca7285 in -[_UIToolbarContentView updateWithItems:fromOldItems:animate:] ()
#13 0x00007fff23ca423f in -[_UIToolbarVisualProviderModernIOS _setViewOwnersAndUpdateContentViewForItems:withOldItems:animated:] ()
#14 0x00007fff23ca46de in -[_UIToolbarVisualProviderModernIOS updateWithItems:fromOldItems:animate:] ()
#15 0x00007fff23c987ce in -[UIToolbar setItems:animated:] ()
#16 0x000000010e479522 in UIView.addKeyboardToolbarWithTarget(target:titleText:rightBarButtonConfiguration:previousBarButtonConfiguration:nextBarButtonConfiguration:) at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQToolbar/IQUIView+IQKeyboardToolbar.swift:455
#17 0x000000010e479b40 in @objc UIView.addKeyboardToolbarWithTarget(target:titleText:rightBarButtonConfiguration:previousBarButtonConfiguration:nextBarButtonConfiguration:) ()
#18 0x000000010e47a02c in UIView.addDoneOnKeyboardWithTarget(_:action:titleText:) at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQToolbar/IQUIView+IQKeyboardToolbar.swift:488
#19 0x000000010e47a155 in @objc UIView.addDoneOnKeyboardWithTarget(_:action:titleText:) ()
#20 0x000000010e479dba in UIView.addDoneOnKeyboardWithTarget(_:action:shouldShowPlaceholder:) at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQToolbar/IQUIView+IQKeyboardToolbar.swift:481
#21 0x000000010e479e38 in @objc UIView.addDoneOnKeyboardWithTarget(_:action:shouldShowPlaceholder:) ()
#22 0x000000010e42e2f4 in IQKeyboardManager.init() at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQKeyboardManager.swift:871
#23 0x000000010e42e953 in @objc IQKeyboardManager.init() ()
#24 0x000000010e42bd8b in IQKeyboardManager.__allocating_init() ()
#25 0x000000010e44aa3c in globalinit_33_1804EA4A44CDC62F5B66EAD58B4692DC_func3 at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQKeyboardManager.swift:179
#26 0x00000001145cc9c8 in _dispatch_client_callout ()
#27 0x00000001145cdf33 in _dispatch_once_callout ()
#28 0x0000000113c89e5a in swift_once ()
#29 0x000000010e41f0c4 in kbManager.unsafeMutableAddressor in Static #1 in static IQKeyboardManager.shared.getter at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQKeyboardManager.swift:179
#30 0x000000010e41f069 in static IQKeyboardManager.shared.getter at /Users/marcinkornek/Documents/netguru/projects/Shepper/ios/Pods/IQKeyboardManagerSwift/IQKeyboardManagerSwift/IQKeyboardManager.swift:183
#31 0x000000010e41f03c in @objc static IQKeyboardManager.shared.getter ()
#32 0x000000010e89f8f3 in -[ReactNativeKeyboardManager setToolbarPreviousNextButtonEnable:] at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native-keyboard-manager/ios/ReactNativeKeyboardManager/ReactNativeKeyboardManager.m:108
#33 0x00007fff204272fc in __invoking___ ()
#34 0x00007fff204247b6 in -[NSInvocation invoke] ()
#35 0x00007fff20424a47 in -[NSInvocation invokeWithTarget:] ()
#36 0x000000010e61e2e4 in -[RCTModuleMethod invokeWithBridge:module:arguments:] at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/Base/RCTModuleMethod.mm:584
#37 0x000000010e62248e in facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&) at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:114
#38 0x000000010e621f56 in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:75
#39 0x000000010e621ebc in invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int) at /Users/marcinkornek/Documents/netguru/projects/Shepper/node_modules/react-native/React/CxxModule/RCTNativeModule.mm:67
#40 0x00000001145cb7ec in _dispatch_call_block_and_release ()
#41 0x00000001145cc9c8 in _dispatch_client_callout ()
#42 0x00000001145d3296 in _dispatch_lane_serial_drain ()
#43 0x00000001145d3f67 in _dispatch_lane_invoke ()
#44 0x00000001145dfde2 in _dispatch_workloop_worker_thread ()
#45 0x00007fff60c8aa3d in _pthread_wqthread ()
#46 0x00007fff60c89b77 in start_wqthread ()
douglasjunior commented 3 years ago

I changed the module configuration to force the use of the main queue.

Could you please test the "force-main-queue" branch?

npm install react-native-keyboard-manager@https://github.com/douglasjunior/react-native-keyboard-manager.git#force-main-queue

or

yarn add react-native-keyboard-manager@https://github.com/douglasjunior/react-native-keyboard-manager.git#force-main-queue
jacobmllr95 commented 3 years ago

@douglasjunior I have/had the same issue with v6.5.4-0 and the changes of the force-main-queue branch seem to fix the issue 👍

douglasjunior commented 3 years ago

Good, thanks!

douglasjunior commented 3 years ago

https://github.com/douglasjunior/react-native-keyboard-manager/releases/tag/6.5.4-1

rohanvasishth commented 1 year ago

Still having this error @douglasjunior just started using the library.

douglasjunior commented 1 year ago

Still having this error @douglasjunior just started using the library.

It is probably not related to the problem fixed in this issue.

If you wish, please create a new issue with a reproducible demo.