Skip to content
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

Fixed onModalHide being called early #733

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

s77rt
Copy link

@s77rt s77rt commented Feb 12, 2023

Overview

The onModalHide is being called too early (i.e. before actually hiding the modal) and if we try to focus an element on that callback it will fail due to RN focus trap.

Unfortunately there is no easy way to know when the modal has been hidden (RN does not have onHide prop). But I found that we can fix this be delaying the callback by 2 cycles, first one to ensure that the modal content has been unmounted and the second to ensure that the focus trap is no longer active (after refocusing the element that triggered opening the modal).

Test Plan

Consider the example stated above where we try to focus an element onModalHide callback.

Before After
Kooha-2023-02-12-13-20-44.mp4
Kooha-2023-02-12-13-22-42.mp4

@s77rt
Copy link
Author

s77rt commented Feb 14, 2023

@mmazzarolo @alimek Would you please take a look at this one?

@s77rt
Copy link
Author

s77rt commented Mar 18, 2023

@ancyrweb Can you please check this when you get the time. Thanks!

@s77rt
Copy link
Author

s77rt commented Apr 9, 2023

The onModalHide callback is called right after setting isVisible to false. But we will still render the <Modal /> from RNW. And it uses hooks that apply after such changes. So even that isVisible=false the modal content is still there and hooks will still be executed. Calling onModalHide at this point is too early. We need to delay that call after the hooks are executed. To be specific we need to ensure that the call is made after this hook. Looking here we need to wait 2 cycles for that to happen. First one for ModalContent and second for ModalFocusTrap (where the hook is located).

@priyeshshah11
Copy link

Any updates on this? @mmazzarolo

Is this still an active repo? asking since no PRs have been merged since almost a year despite having 34 PRs open.

@mmazzarolo
Copy link
Member

@priyeshshah11
#738
#598

@priyeshshah11
Copy link

@priyeshshah11 #738 #598

Thanks for the reference @mmazzarolo. There seems to be good amount of interest from everyone on that thread then what needs to happen to get PRs reviewed & merged?

@lgibso34
Copy link

lgibso34 commented May 2, 2023

+1

@mmazzarolo
Copy link
Member

mmazzarolo commented May 2, 2023

Thanks for the reference @mmazzarolo. There seems to be good amount of interest from everyone on that thread

Sadly 99% of the interest in that thread comes from folks who just say "I'm interested" without ever having contributed. There have been a few people who contributed (e.g., @ancyrweb, who became a maintainer and a couple of other who declined the invite to become contributors), so I'm definitely open to it if anyone is willing to commit to it 👍
With regard with this PR, I appreciate @s77rt work, and a good way to make it easier for me to merge it would be for other persons to review this changes by actually trying this fix and letting me know if it works — possibly not on the same use-case @s77rt is trying it out (which I assume it's expensify). This is especially true for PRs that introduce hacks.
Please also keep in mind that I'm not using RN anymore and I don't follow closely GH issues anymore, so I might be very slow to respond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants