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

Custom TabBar Component in v4 #2036

Closed
thngdude opened this issue Jul 15, 2017 · 13 comments
Closed

Custom TabBar Component in v4 #2036

thngdude opened this issue Jul 15, 2017 · 13 comments

Comments

@thngdude
Copy link

Hi, I'm trying to implement a custom tabbar. As a control, I tried the following, which did not work:

import { TabNavigator, TabBarBottom } from 'react-navigation';

<Scene
          key="tabbar"
          gestureEnabled={false}
          tabs
          hideNavBar
          activeBackgroundColor='#ddd'
          component={TabNavigator}>

I also tried substituting TabNavigator with TabBarBottom and it still didn't work.

Resulting errors:

  1. with TabNavigator --> "Cannot read property 'screen' of undefined"
  2. with TabBarBottom --> "Cannot read property 'map' of undefined"
@aksonov
Copy link
Owner

aksonov commented Jul 15, 2017 via email

@thngdude
Copy link
Author

Thanks, @aksonov. Is this currently documented somewhere? Perhaps there's a README I missed.

Btw, this library is really awesome. Thanks for your work.

@thngdude
Copy link
Author

thngdude commented Jul 15, 2017

Ok, I got it working. I would be willing to contribute to add a section about this to the documentation for v4. However, this would be a first for me (contributing documentation) and could use some guidance.

<Scene
          key="tabbar"
          gestureEnabled={false}
          activeBackgroundColor='#ddd'
          tabs
          tabBarComponent={CustomTabBarComponent}>
          	<Scene key="tab1" component={TabOne} title="Tab1"/>
          	<Scene key="tab2" component={TabTwo} title="Tab2"/>
          </Scene>

You must add the tabs and tabBarComponent props, where the CustomTabBarComponent may extend a component such as TabBarBottom from the React Navigation library.

@aksonov
Copy link
Owner

aksonov commented Jul 15, 2017 via email

@krunaldodiya
Copy link

krunaldodiya commented Aug 20, 2017

would you please give example for CustomTabBarComponent as i want to render tabs inside custom component, i am able to render "hello" when i use tabBarComponent={CustomTabBarComponent} but instead i want to render tabs view with tap and slide effect, please help

import React from 'react'
import {Text, View} from "react-native";

export default class CustomTabBarComponent extends React.Component {
    render() {
        return (
            <View><Text>hello</Text></View>
        )
    }
}

@krunaldodiya
Copy link

i want to add a ui like on top left back arrow, right side two icons 1) search 2) more (three dots)

and bottom the 3 tabs => Home, Profile, Settings

If I use tabs i can render tabs but can't set custom header upside, and slide effect working but tap on any tab does not work work :) your guidance would be great help

@roots-ai
Copy link

roots-ai commented Oct 9, 2017

Hi! Was this issue resolved? How did you finally made the custom slidable tabbar components?

@cicerone-f
Copy link

@kunaldodiya can you please share your CustomTabBarComponent?

@krunaldodiya
Copy link

@cicer1 i am no more using this module.. I am now using react navigation

@bruno-edo
Copy link

I was able to make a custom tab bar following the method @thngdude described.

I'll prepare an example and submit a PR to add it to the docs. Meanwhile here's some code that should give some idea on how to implement the custom tab bar:

import { MaterialTopTabBar } from 'react-navigation-tabs';

class testbar extends MaterialTopTabBar {
    static propTypes = {

    }

    render() {
      return (
          <View>
            {
                this.props.navigationState.routes.map((element) => {
                  return (
                      <TouchableOpacity key={element.key} onPress={() => console.log(element.key)}>
                            <Text>{element.key}</Text>
                      </TouchableOpacity>
                  );
                })
            }
        </View>
      );
    }
}

export default testbar;

@ajaykumar97
Copy link

How to navigate to other tab in custom tabbar?

@micahkatz
Copy link

@ajaykumar97 you can use Actions['yourtabroute'](); to switch between tabs
For example, if you have Tab1 and Tab2, and you are currently in Tab1, you can call Actions['Tab2'](); to switch to Tab2

@ajaykumar97
Copy link

Thanks for your reply @micahkatz

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

8 participants