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

Question: Tab bar implementation #92

Closed
tristangodfrey opened this issue Mar 5, 2016 · 11 comments
Closed

Question: Tab bar implementation #92

tristangodfrey opened this issue Mar 5, 2016 · 11 comments

Comments

@tristangodfrey
Copy link

I'm not quite sure how I should implement a tab bar to allow navigation between a small group of routes.

Should I achieve this by nesting a Router inside of the main router? So I'll have a single tab-router route, which loads my tab-bar + router component. Or is there a better way of doing this?

@skizzo
Copy link

skizzo commented Mar 9, 2016

@tristangodfrey I tried this approach by creating a Router component inside a View, but I don't know how to access my 2 routers's toRoute() or toBack() functions.. Were you able to work it out?

@tristangodfrey
Copy link
Author

@skizzo This is roughly how I solved it, just a bunch of snippets but it should give you the general idea


//This is how I give my nested routes access to the main router `toRoute` function

const createTabs = (toRoute) => {
  return [{
      route: {
        component: Dashboard,
        name: "Home",
        passProps: {
          onQuizListPress: () => toRoute(quizList),
          onTaskListPress: () => toRoute(taskList),
        },
      },
      iconName: "home",
    }];
}

//This is the container component that holds our tabBar + nested router

class Container extends Component {

  //This is for changing the route of our nested router
  _onTabPress(tab) {
    //This worked for me, don't think I was able to access the default
    //router methods so I used the navigator
    this.refs.router.refs.navigator.replace(tab.route)
  }

  const tabs = createTabs(toRoute);

  render (
     return (
      <View>
        <Router ref="router" />
        <TabBar tabs={tabs} onTabPress={(tab) => this._onTabPress(tab)} />
      </View>
    );
  )

}

@charpeni
Copy link
Contributor

charpeni commented Mar 9, 2016

I will need this feature soon, I'll look it in a few days and I'll be back with a feedback.

Using method of Navigator with refs will works, maybe our functions should be accessible too.

Thanks for the snippets @tristangodfrey.

@cpjolicoeur
Copy link
Contributor

As a quick "fix" in our fork we just ended up exposing the methods directly: mojotech@7d268d7

And in a stripped down for demo our router w/ tabbar follows similarly to your example

<View>
  <Router .../>
  <TabBar ... />
</View>

@tristangodfrey
Copy link
Author

Thanks @cpjolicoeur , should we document this approach/add an example or just leave this issue up for reference? Would be happy to contribute if needed.

@cpjolicoeur
Copy link
Contributor

we'd want @charpeni and other's opinions on it. Exposing the methods (or a minimal subset of methods) works fine for us. I never formally submitted a Pull Request back to the mainline project with those changes as I didn't know if it was something they were interested in.

But maybe a discussion is in order on it.

@charpeni
Copy link
Contributor

I think it's a great idea to expose these methods.

Would be happy to contribute if needed.

@tristangodfrey It would be appreciate 😃

@SEthX Any thoughts?

@cpjolicoeur
Copy link
Contributor

I'll submit a PR with our exposing changset for review/discussion.

@charpeni
Copy link
Contributor

That was fast!

@charpeni
Copy link
Contributor

@tristangodfrey Does the documentation is still in planning?

@akoshman
Copy link

akoshman commented Jun 5, 2016

<View>
  <Router .../>
  <TabBar ... />
</View>

If I wrap Router by View then nothing appears on the screen.
Can anyone write some instructions how to do this?
And where do you get TabBar component?
Thanks.

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