Test is failing in Detox when the layout is overlayed

I get the following error in Detox when the test clicks on a button, the click works but after the component re-renders because of a state change, the test strangely wants to click on the button again but since the button is not in the view, the test fails.

Test Failed: Wait for
[com.wix.detox.reactnative.idlingresources.AnimatedModuleIdlingResource]
to become idle timed out

My test script:

await element(by.id("post-1-cm")).tap();

await waitFor(element(by.id("comment-error")))
  .not.toExist()
  .withTimeout(5000);

The Button component:

<AppButton
          onPress={() => toggleComments(true)}
          disabled={disabled || submitting}
          inverted
          testID={`${testID}-cm`}
          buttonStyles={styles.button}>

Code of the component that gets rendered when the button is clicked and toggleComments changes the showComments state to True:

  {showComments && (
    <CommentsModal
      reloadPosts={props.reload}
      visible={showComments}
      blockUser={blockUser}
      close={() => toggleComments(false)}
    />
  )}