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

willBlur/didBlur events fired when trying to navigate to the current tab #3511

Closed
MichaelBorde opened this issue Feb 13, 2018 · 7 comments
Closed

Comments

@MichaelBorde
Copy link

MichaelBorde commented Feb 13, 2018

Current Behavior

I have a TabNavigator and i use navigation.addListener to catch events like willBlur or didBlur.

When i try to navigate to the same tab i am actually on willBlur and didBlur events are triggered.

I want to load data on focus event and clean data on blur event. Triggering a blur event when tab is not changed is difficult to handle.

Expected Behavior

Blur events should be fired only when tab is changed or focus events should follow blur events in this specific case.

How to reproduce

There is a snack : https://snack.expo.io/@michaelborde/react-navigation-willblur

Environment

software version
react-navigation 1.0.3
react-native 0.53.0

Thoughts

I agree it is not common to navigate to the current screen but i discovered this behaviour with a specific use case. Feel free to close this issue if you think it's irrelevant. For the moment my workaround is to check wether i try to navigate to the current screen or not.

@satya164
Copy link
Member

Hey, please provide a repro on snack.expo.io

@MichaelBorde MichaelBorde changed the title willBlur/didBlur events fired when current tab is pressed willBlur/didBlur events fired when trying to navigate to the current tab Feb 14, 2018
@MichaelBorde
Copy link
Author

You help me understand my issue was not so simple. I made a snack and edited the issue.

@satya164
Copy link
Member

So the issue you have is that you're already on "Settings" screen and try to navigate to the same screen again, then you get "willBlur", right? I can repro it on snack. It fires only the first time I try to navigate though.

cc @ericvicenti

@MichaelBorde
Copy link
Author

That's right. The use case may seem odd but i discovered this behaviour trying to implement a custom tab bar. When i press a tab i navigate to it but i had no guard to prevent navigation to the current tab.

Anyway in that specific use case, the screen blurs but no other screen is focused though i am on a screen actually.

@brentvatne
Copy link
Member

repros on 2.0 -- @ericvicenti https://snack.expo.io/Hy_mKLApG

@jozan
Copy link

jozan commented May 8, 2018

We encountered this recently when using StackNavigator.

Repro using 2.0: https://snack.expo.io/BkSVTgJCf

@brentvatne
Copy link
Member

brentvatne commented May 9, 2018

2.0.1 should resolve these issues, with #4168 (edit - confirmed: i tested both of those snacks against 2.0.1 and they work as expected, thanks for the repros!)

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

No branches or pull requests

5 participants