-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Blur Event Does Not Fire #11788
Comments
I did a little bit of debugging on this problem. What I realized is that the useEffect cleanup function is called before the blur event is even emitted. Currently the only way you have is to do the unsubscribe right after the blur event is emitted (although this is not a good solution). I will continue to investigate. |
@gianlucalippolis, that's interesting. I'll tell you some other things that I found while trying to get this to work, and maybe it will shed some additional light on the issue. First off, the reason I wanted to use the blur event is that if a user is playing a video, and navigates away from the screen while it is playing (users do the weirdest things), I want to save their progress in the video to a database so that they can start from where they left off next time they come to the screen. I tried using the cleanup function of the Why am I trying to use state to update my database? Well, right now, the update is handled by a child component, and the way that the screen lets the child component know that it should do an update is that a state variable changes in the screen, which changes a prop that's passed into the child. When the child is re-rendered, it sees the different value for the prop and knows that it should update the database. I feel like this should work and is consistent with React design principles, but I might try a different architecture in which the database update gets called directly from the screen component. Also, for what it's worth, I'm pretty sure that the blur event used to work. I updated the versions of a lot of libraries (including react-navigation) in my project recently, and it does not work anymore, but I'm pretty sure that it did before I did the updates. |
In the react navigation example app it is working normally 🤨 I will try to debug |
The screen is unmounted immediately when navigating away in case of native stack, so you won't get any events.
|
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
Okay, thanks for the explanation, @satya164. If the
You can probably see how this is misleading if these events are not in fact available for every navigator. In my particular use case, I was able to bubble up the video progress with callbacks from the child components, then use the |
Hi guys, I think this still isn't fixed i.e. having tested, it seems like there's still no clear way to have a focus and blur listener which are cleaned up. When using either
or
...The blur event doesn't run, as the cleanup runs first. We also can't use
I ended up using the following, which I think will work? But I believe it's undocumented (+ could potentially be cleaner?):
Cheers! |
Current behavior
I set up a handler for a 'blur' event; when navigating away from the screen in question, that event never fires.
Expected behavior
The blur event handler should fire.
Reproduction
https://github.com/TheRealMikeD/BlurNoWorkie
Platform
Packages
Environment
The text was updated successfully, but these errors were encountered: