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

Component renders twice / showing up in nav bar twice #2024

Closed
isAlmogK opened this issue Jul 13, 2017 · 28 comments
Closed

Component renders twice / showing up in nav bar twice #2024

isAlmogK opened this issue Jul 13, 2017 · 28 comments

Comments

@isAlmogK
Copy link

This is a wired issue, not sure why it's happing but it looks like the my home component is getting rendered twice attached gif as you can see the nav bar has home twice and you can go back to home even though
nav-bar-issue
home is the first view.

My code

<Provider store={store}>
                <ConnectedRouter>
                    <Scene key="root">
                        <Scene key="login" component={Login} initial={true} title={'Login'} />
                        <Scene key="ResetPassword" component={ResetPassword} title={'Reset Password'} />
                        <Scene key="tabBar" tabs hideNavBar={true}>
                            <Scene key="tab1" title="Home" tabBarLabel="Home" icon={HomeTabIcon}>
                                <Scene key='Home' component={Home} title='Home' initial={true} />
                                <Scene key='teams' component={Teams} title='Teams' initial={false} />
                            </Scene>
                            <Scene key="tab2" title="Photos" tabBarLabel="Photos" icon={PhotosTabIcon}>
                                <Scene key='Photos' component={Photos} title='Photos' initial={false} />
                            </Scene>
                            <Scene key="tab3" title="Site Diary" tabBarLabel="Site Diary" icon={SiteDiaryTabIcon}>
                                <Scene key='SiteDiary' component={SiteDiary} title='SiteDiary' initial={false} />
                            </Scene>
                        </Scene>
                    </Scene>
                </ConnectedRouter>
            </Provider>
@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017 via email

@isAlmogK
Copy link
Author

No problem "react-native-router-flux": "4.0.0-beta.7",

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Always try latest one before creating of issue ;) Please check with beta.8

@isAlmogK
Copy link
Author

Same issue with 8

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Could you reproduce it with Example? Have you added console logs and see re-rendering several times?

@isAlmogK
Copy link
Author

I did that was the first thing I check as you can see it renders twice
screen shot 2017-07-13 at 5 17 15 am

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Ok, please reproduce with Example and latest beta.8

@isAlmogK
Copy link
Author

Isn't the example code outdated for version 4?

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Why? I've just increased dep to beta.8 if it is what you are saying.

@isAlmogK
Copy link
Author

My code is different than the example code more, I'm not going to rewrite the entire example to like mine and just because the example is not showing this issue does not mean it's not a bug.

And this is a bug

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Sorry, I can't guess the problem, I need to see the code. All I see from screenshot is some weird navbar transition and it could happen because of hidden navbar for tabbar. For such cases look at headerMode setting for RN StackNavigator - 'screen' maybe better ('float' is used by default)

@isAlmogK
Copy link
Author

I debugged the issue, I don't think we need to create examples for each issue if you look at the code that should help, this is how StackOverflow works when you ask for help.

This is definitely a bug

If I'm for example a login screen and have
Actions.Home();

Which is a component inside a tab bar, the first one you get that issue because the lib loads the tab bar and the home component.

If you do the following
Actions.tabBar();

It loads the tab bar which in turn loads the fist component, or it just gets loaded once.

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Then try to fix it by yourself - RNRF is just wrapper around react-navigation and build all screens for you. As far as I can see when you are calling Actions.Home - you are telling react-navigation to PUSH Home - but Home is already exist as start screen, so you will have two screens as the result

@isAlmogK
Copy link
Author

I already fixed it, just did Actions.tabBar();

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

That is why I said. So it is not bug, but incorrect usage.

@aksonov aksonov closed this as completed Jul 13, 2017
@isAlmogK
Copy link
Author

No, I still think it's a bug, but you can explain.

I have a 3 tabs each have 1 view component

How do I navigate between tabs because if I do

Actions.Photos();

The second tab it loads the photos component tab twice

@isAlmogK
Copy link
Author

To follow up it seems that if your component is inside a tabs scene and you use Actions.xx to call it for some reason it loads that component twice

@isAlmogK
Copy link
Author

Can you reopen this, it's definitely an issue. Did you understand how it's happing

@aksonov aksonov reopened this Jul 13, 2017
@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

As I said RNRF is just wrapper.
Is it similar to react-navigation/react-navigation#476 ?

@isAlmogK
Copy link
Author

@aksonov I understood that I was saying we should keep it open until 476 is fixed

@aksonov
Copy link
Owner

aksonov commented Jul 13, 2017

Please try PR #2025, I did some workaround

@isAlmogK
Copy link
Author

Tried testing it, PR has an issue

aksonov added a commit that referenced this issue Jul 14, 2017
- Enhancement: support inheritance of scene props (useful for `headerMode` attribute for different RN StackNavigator animation)
- Fix: attempt to fix react-navigation pushes instead of jumping when user taps the same tab (#2024)
- Enhancement: use navBarButtonColor or tintColor or headerTintColor for image button tintcolor (#2028)
- Fix: use backBehavior='initialRoute' by default (#2026)
- Enhancement: allow right/leftTitle, right/leftButtonImage to be static functions within scene component
- Enhancement: allow wrapping all screens and navbar buttons with `wrapBy` parameter for `Router`. It could be `observer` from MobX, or `connect` from Redux or any other function.
- Fix: eslint formatting, fix CircleCI build
@isAlmogK
Copy link
Author

I can confirm this still happens with beta 9 and I'm on "react-navigation": "^1.0.0-beta.11", I'm calling
Actions.Photos(); which is inside a tab bar

@aksonov
Copy link
Owner

aksonov commented Jul 14, 2017 via email

@isAlmogK
Copy link
Author

How do I do that? What is the code?

@aksonov
Copy link
Owner

aksonov commented Jul 14, 2017 via email

@isAlmogK
Copy link
Author

Thanks perfect and working great

@ShawSmall
Copy link

The bottom navigation switch, the page is reloaded, resulting in slow switching and waste of traffic

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

No branches or pull requests

3 participants