question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UIViewControllerHierarchyInconsistency

See original GitHub issue

Description

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: Screenshot 2021-05-19 at 01 12 07

Package versions

  • React: 17.0.1
  • React Native: 0.64.1
  • React Native Screens: 3.0.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:25 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
WoLewickicommented, Nov 17, 2021

I debugged it and it seems like there is a race condition between Modal and Screen view 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 adding setTimeout for showing the modal in the new screen, so first the proper native hierarchy of view controllers is established, something like this:

const CrashScreen: FC = () => {
  const [showModal, setShowModal] = useState(false);

  useEffect(() => {
    setTimeout(() => {
      setShowModal(true);
    }, 0);
  }, []);

  return (
    <View style={styles.container}>
      <Text>Crash screen</Text>
      <Modal visible={showModal}>
        <View style={styles.container}>
          <Text>Loading</Text>
        </View>
      </Modal>
    </View>
  );
};

Can you check if it resolves the issue?

1reaction
WoLewickicommented, Apr 21, 2022

I think it is only needed if you open a screen with the modal shown from the beginning since then react-native-screens also changes the native controller hierarchy.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found