UIViewControllerHierarchyInconsistency
See original GitHub issueDescription
The app has been inactive for around 2 min on a “enter pin code page” leading to that the iPhone has been locked. If the user then unlocks the phone, enter the pin code and press the login button, the app then crashes.
After setting enabledScreen(false), I have not been able to reproduce a crash.
Exception from Bugsnag:
UIViewControllerHierarchyInconsistency: child view controller:<RNScreensViewController: 0x126d2ce00> should have parent view controller:(null) but actual parent is:<UIViewController: 0x125e2a7d0>
0 CoreFoundation ___exceptionPreprocess
1 libobjc.A.dylib _objc_exception_throw
2 CoreFoundation +[NSException raise:format:]
3 UIKitCore -[UIView(Hierarchy) _associatedViewControllerForwardsAppearanceCallbacks:performHierarchyCheck:isRoot:]
4 UIKitCore -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:]
5 UIKitCore -[UIView(Internal) _addSubview:positioned:relativeTo:]
6 UIKitCore ___67-[UIViewControllerBuiltinTransitionViewAnimator animateTransition:]_block_invoke_2
7 UIKitCore +[UIView(Animation) performWithoutAnimation:]
8 UIKitCore ___67-[UIViewControllerBuiltinTransitionViewAnimator animateTransition:]_block_invoke
9 UIKitCore +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:]
10 UIKitCore +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:]
11 UIKitCore -[UIViewControllerBuiltinTransitionViewAnimator animateTransition:]
12 UIKitCore ____UIViewControllerTransitioningRunCustomTransition_block_invoke_2
13 UIKitCore +[UIInputResponderController _pinInputViewsForInputResponderController:onBehalfOfResponder:duringBlock:]
14 UIKitCore ____UIViewControllerTransitioningRunCustomTransition_block_invoke.663
15 UIKitCore +[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:]
16 UIKitCore __UIViewControllerTransitioningRunCustomTransition
17 UIKitCore ___56-[UIPresentationController runTransitionForCurrentState]_block_invoke.491
18 UIKitCore -[_UIAfterCACommitBlock run]
19 UIKitCore __runAfterCACommitDeferredBlocks
20 UIKitCore __cleanUpAfterCAFlushAndRunDeferredBlocks
21 UIKitCore __afterCACommitHandler
22 CoreFoundation ___CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
23 CoreFoundation ___CFRunLoopDoObservers
24 CoreFoundation ___CFRunLoopRun
25 CoreFoundation _CFRunLoopRunSpecific
26 GraphicsServices _GSEventRunModal
27 UIKitCore -[UIApplication _run]
28 UIKitCore _UIApplicationMain
Screenshots
This is the “breadcrumb” from Bugsnag:

Package versions
- React: 17.0.1
- React Native: 0.64.1
- React Native Screens: 3.0.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:25 (10 by maintainers)
Top Results From Across the Web
ios - UIViewControllerHierarchyInconsistency - Stack Overflow
'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! View > is associated with ....
Read more >UIViewControllerHierarchyIncon...
Raised if the view controller hierarchy is inconsistent with the view hierarchy. iOS 5.0+ iPadOS 5.0+ Mac Catalyst 13.1+ tvOS ...
Read more >IOS IMA sdk - Fatal Exception - Google Groups
Fatal Exception: UIViewControllerHierarchyInconsistency. A view can only be associated with at most one view controller at a time!
Read more >UIViewControllerHierarchyIncon...
iOS : UIViewControllerHierarchyInconsistency when trying to present a modal view controller [ Gift : Animated Search Engine ...
Read more >A view can only be associated with at most one view controller ...
'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! 2013/07/23 ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I debugged it and it seems like there is a race condition between
ModalandScreenview controllers being attached/detached. I am not sure if we can do anything about it since it comes from asynchronous behaviors of these events. The solution to this is probably addingsetTimeoutfor showing the modal in the new screen, so first the proper native hierarchy of view controllers is established, something like this:Can you check if it resolves the issue?
I think it is only needed if you open a screen with the modal shown from the beginning since then
react-native-screensalso changes the native controller hierarchy.