Skip to content

Unable to set selected default tab #241

@boyaq

Description

@boyaq

Hi,

We've tried to make a default tab using "selected" props of Router like this: (this is part of your example"

<Router selected={"tab5"} footer={TabBar} showNavigationBar={false}>
    <Route name="tab1" schema="tab" title="Tab #1" >
        <Router onPop={()=>{console.log("onPop is called!"); return true} }>
            <Route name="tab1_1" component={TabView} title="Tab #1_1" />
            <Route name="tab1_2" component={TabView} title="Tab #1_2" />
        </Router>
    </Route>
    <Route name="tab2" schema="tab" title="Tab #2" hideNavBar={false}>
        <Router onPop={()=>{console.log("onPop is called!"); return true} }>
            <Route name="tab2_1" component={TabView} title="Tab #2_1" />
            <Route name="tab2_2" component={TabView} title="Tab #2_2" />
        </Router>
    </Route>
    <Route name="tab3" schema="tab" title="Tab #3" component={TabView} hideTabBar={false}/>
    <Route name="tab4" schema="tab" title="Tab #4" component={TabView} />
    <Route name="tab5" schema="tab" title="Tab #5" component={TabView} initial={true}/>
</Router>

Here I set the selected tab.

<Router selected={"tab5"} footer={TabBar} showNavigationBar={false}>

after this I got error like this:

cannot read property 'dispatch' of undefined in Actions.js @ 70:0

So after a lot reading and debugging I found out that it executes "Tabs onSelect function" on first render which I think it shouldn't, as it SHOULD only fires after user tap on the tab icons.

When it executes the onSelect function when rendering, the Actions currentRouter doesn't have the ExRouter as delegate, it remains as RouterDelegate which throws that 'dispatch' error.

So for now, i just added following line to my copy of TabBar's onSelect function to fix it temporarily.

if(Actions.currentRouter.delegate.constructor != ExRouter){ return {selected: true}; }

Hope you can look into it and let me know if there is a solution.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions