NativeBase icon indicating copy to clipboard operation
NativeBase copied to clipboard

Style Tabbar with Icons

Open googl3r opened this issue 9 years ago • 15 comments

Hi, I have a Tabbar with icons and Text i am facing 2 problems: 1-Text doesn't go to the bottom of the icon 2-ActiveTabStyle doesn't apply on tabs so i can't style my tabs her is my code `

     <Tabs tabBarPosition = "bottom" {...tabProps}>

                    <Tab heading = {<TabHeading>
                            <Icon name="home"/>
                        <Text>Acheter</Text>
                    </TabHeading>}
                         tabStyle = {{backgroundColor: 'transparent'}}
                         activeTabStyle = {{backgroundColor: 'transparent'}}
                         activeTextStyle = {{fontWeight:'bold', color: '#651FFF', fontSize:17}}
                         textStyle = {{color: '#7C4DFF', fontWeight: 'bold', fontSize:16}}
                    >
                        <ProduitsScene style ={{ marginTop: -2}}/>
                    </Tab>

                    <Tab heading = {<TabHeading><Icon name="briefcase"/></TabHeading>}>
                    </Tab>

                    <Tab heading = {<TabHeading><Icon name="ios-menu-outline"/></TabHeading>}>
                    </Tab>

                    <Tab heading = {<TabHeading><Icon name="ios-compass-outline"/></TabHeading>}>
                    </Tab>

                    <Tab heading = {<TabHeading><Icon name="person"/></TabHeading>}>
                    </Tab>
                </Tabs>

`

her is a screen of my tabs capture d ecran 2017-06-13 a 15 45 28

googl3r avatar Jun 13 '17 13:06 googl3r

try this one and add style to center it

<TabHeading><View><Icon name="briefcase"/></View><View><Text>Tab Text</Text></View></TabHeading>

eggybot avatar Jun 13 '17 17:06 eggybot

try <TabHeading style={{ flexDirection: 'column' }}><Icon name="briefcase"/><Text>Tab Text</Text></TabHeading>

shivrajkumar avatar Jun 20 '17 07:06 shivrajkumar

Active tab style does not apply probably since you are importing react native Text. Try to import Text from native base instead.

andidev avatar Jun 20 '17 22:06 andidev

Closing this due to inactivity. And also the above solutions should work

shivrajkumar avatar Jul 03 '17 06:07 shivrajkumar

sorry for the time, i was in holidays, but yes the above solutions works fine thanks a lot

googl3r avatar Jul 03 '17 17:07 googl3r

Hi @googl3r, any feedback on this issue? I'm trying to customize the active state of my TabHeading with no success so far.

wmendes avatar Jan 12 '18 13:01 wmendes

@wmendes What is the issue you are facing? Share your code snippet and output along with RN and NB version

SupriyaKalghatgi avatar Jan 15 '18 04:01 SupriyaKalghatgi

Sorry @SupriyaKalghatgi , my mistake. I was importing RN Text.

wmendes avatar Jan 15 '18 11:01 wmendes

@SupriyaKalghatgi hi i have same issue as googl3r. Obviously the tabs cannot be styled when we use TabHeading. The code below is not executed :
tabStyle = {{backgroundColor: 'transparent'}} activeTabStyle = {{backgroundColor: 'transparent'}} activeTextStyle = {{fontWeight:'bold', color: '#651FFF', fontSize:17}} textStyle = {{color: '#7C4DFF', fontWeight: 'bold', fontSize:16}} >

PdxMehmet avatar Feb 06 '18 10:02 PdxMehmet

@PdxMehmet having the same problem, have you solved it?

Elitebigboss90 avatar Mar 04 '18 10:03 Elitebigboss90

No didnt solve it yet :(

PdxMehmet avatar Mar 04 '18 10:03 PdxMehmet

@PdxMehmet @Elitebigboss90 posting code for the common case without <TabHeading/>

Code

import React, { Component } from 'react';
import { Container, Header, Content, Tab, Tabs, Text } from 'native-base';
export default class TabsExample extends Component {
  render() {
    return (
      <Container>
        <Header hasTabs />
        <Tabs initialPage={1} >
          <Tab heading="Tab1" tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab one</Text>
          </Tab>
          <Tab heading="Tab2"
            tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab two</Text>
          </Tab>
          <Tab heading="Tab3"
            tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab three</Text>
          </Tab>
        </Tabs>
      </Container>
    );
  }
}

Gif

tab styling

handling style programmatically while using <Tabheading/>

Code

import React, { Component } from 'react';
import { Container, Header, Content, Tab, Tabs, Text, TabHeading, Icon } from 'native-base';
import { StyleSheet } from 'react-native'
export default class TabsExample extends Component {

  constructor(props) {
    super(props)
    this.state = { page: 1 }
  }

  render() {
    return (
      <Container>
        <Header hasTabs />
        <Tabs initialPage={1} onChangeTab={({ i }) => this.setState({ page: i })}>
          <Tab heading={<TabHeading style={this.state.page === 0 ? styles.activeTabStyle : styles.tabStyle}>
            <Icon name="camera" />
            <Text style={this.state.page === 0 ? styles.activeTextStyle : styles.textStyle}>Camera</Text>
          </TabHeading>}>
            <Text>Tab one</Text>
          </Tab>
          <Tab heading={<TabHeading style={this.state.page === 1 ? styles.activeTabStyle : styles.tabStyle}>
            <Text style={this.state.page === 0 ? styles.activeTextStyle : styles.textStyle}>No Icon</Text>
          </TabHeading>}>
            <Text>Tab two</Text>
          </Tab>
          <Tab heading={<TabHeading style={this.state.page === 2 ? styles.activeTabStyle : styles.tabStyle}>
            <Icon name="apps" />
          </TabHeading>}>
            <Text>Tab three</Text>
          </Tab>
        </Tabs>
      </Container >
    );
  }
}

const styles = StyleSheet.create({
  tabStyle: { backgroundColor: 'transparent' },
  activeTabStyle: { backgroundColor: 'transparent' },
  activeTextStyle: { fontWeight: 'bold', color: '#651FFF', fontSize: 17 },
  textStyle: { color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }
})

Gif

tab styling2

akhil-ga avatar Mar 06 '18 07:03 akhil-ga

@akhil-geekyants You are my hero! :D it works perfectly fine.

msqar avatar Jan 19 '19 02:01 msqar

@PdxMehmet @Elitebigboss90 posting code for the common case without <TabHeading/>

Code

import React, { Component } from 'react';
import { Container, Header, Content, Tab, Tabs, Text } from 'native-base';
export default class TabsExample extends Component {
  render() {
    return (
      <Container>
        <Header hasTabs />
        <Tabs initialPage={1} >
          <Tab heading="Tab1" tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab one</Text>
          </Tab>
          <Tab heading="Tab2"
            tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab two</Text>
          </Tab>
          <Tab heading="Tab3"
            tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab three</Text>
          </Tab>
        </Tabs>
      </Container>
    );
  }
}

Gif

tab styling

handling style programmatically while using <Tabheading/>

Code

import React, { Component } from 'react';
import { Container, Header, Content, Tab, Tabs, Text, TabHeading, Icon } from 'native-base';
import { StyleSheet } from 'react-native'
export default class TabsExample extends Component {

  constructor(props) {
    super(props)
    this.state = { page: 1 }
  }

  render() {
    return (
      <Container>
        <Header hasTabs />
        <Tabs initialPage={1} onChangeTab={({ i }) => this.setState({ page: i })}>
          <Tab heading={<TabHeading style={this.state.page === 0 ? styles.activeTabStyle : styles.tabStyle}>
            <Icon name="camera" />
            <Text style={this.state.page === 0 ? styles.activeTextStyle : styles.textStyle}>Camera</Text>
          </TabHeading>}>
            <Text>Tab one</Text>
          </Tab>
          <Tab heading={<TabHeading style={this.state.page === 1 ? styles.activeTabStyle : styles.tabStyle}>
            <Text style={this.state.page === 0 ? styles.activeTextStyle : styles.textStyle}>No Icon</Text>
          </TabHeading>}>
            <Text>Tab two</Text>
          </Tab>
          <Tab heading={<TabHeading style={this.state.page === 2 ? styles.activeTabStyle : styles.tabStyle}>
            <Icon name="apps" />
          </TabHeading>}>
            <Text>Tab three</Text>
          </Tab>
        </Tabs>
      </Container >
    );
  }
}

const styles = StyleSheet.create({
  tabStyle: { backgroundColor: 'transparent' },
  activeTabStyle: { backgroundColor: 'transparent' },
  activeTextStyle: { fontWeight: 'bold', color: '#651FFF', fontSize: 17 },
  textStyle: { color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }
})

Gif

tab styling2

Is there any faster solutions?

mahdibarati avatar Mar 26 '19 08:03 mahdibarati

@PdxMehmet @Elitebigboss90 posting code for the common case without <TabHeading/>

Code

import React, { Component } from 'react';
import { Container, Header, Content, Tab, Tabs, Text } from 'native-base';
export default class TabsExample extends Component {
  render() {
    return (
      <Container>
        <Header hasTabs />
        <Tabs initialPage={1} >
          <Tab heading="Tab1" tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab one</Text>
          </Tab>
          <Tab heading="Tab2"
            tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab two</Text>
          </Tab>
          <Tab heading="Tab3"
            tabStyle={{ backgroundColor: 'transparent' }}
            activeTabStyle={{ backgroundColor: 'transparent' }}
            activeTextStyle={{ fontWeight: 'bold', color: '#651FFF', fontSize: 17 }}
            textStyle={{ color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }}>
            <Text>Tab three</Text>
          </Tab>
        </Tabs>
      </Container>
    );
  }
}

Gif

tab styling

handling style programmatically while using <Tabheading/>

Code

import React, { Component } from 'react';
import { Container, Header, Content, Tab, Tabs, Text, TabHeading, Icon } from 'native-base';
import { StyleSheet } from 'react-native'
export default class TabsExample extends Component {

  constructor(props) {
    super(props)
    this.state = { page: 1 }
  }

  render() {
    return (
      <Container>
        <Header hasTabs />
        <Tabs initialPage={1} onChangeTab={({ i }) => this.setState({ page: i })}>
          <Tab heading={<TabHeading style={this.state.page === 0 ? styles.activeTabStyle : styles.tabStyle}>
            <Icon name="camera" />
            <Text style={this.state.page === 0 ? styles.activeTextStyle : styles.textStyle}>Camera</Text>
          </TabHeading>}>
            <Text>Tab one</Text>
          </Tab>
          <Tab heading={<TabHeading style={this.state.page === 1 ? styles.activeTabStyle : styles.tabStyle}>
            <Text style={this.state.page === 0 ? styles.activeTextStyle : styles.textStyle}>No Icon</Text>
          </TabHeading>}>
            <Text>Tab two</Text>
          </Tab>
          <Tab heading={<TabHeading style={this.state.page === 2 ? styles.activeTabStyle : styles.tabStyle}>
            <Icon name="apps" />
          </TabHeading>}>
            <Text>Tab three</Text>
          </Tab>
        </Tabs>
      </Container >
    );
  }
}

const styles = StyleSheet.create({
  tabStyle: { backgroundColor: 'transparent' },
  activeTabStyle: { backgroundColor: 'transparent' },
  activeTextStyle: { fontWeight: 'bold', color: '#651FFF', fontSize: 17 },
  textStyle: { color: '#7C4DFF', fontWeight: 'bold', fontSize: 16 }
})

Gif

tab styling2

it works for me but it "seems" that the itenary for my TabHeading components really slows down the render of my code. everytime I need to change the tabs it takes me around 1.5 to 2 seconds, even worse for certain tabs. i'm using icon from native base which requires me to do the itenary method. without it the styles of my activeTabsStyle and tabStyle will not be detected as @PdxMehmet mentions above. any new solutions regarding of this problem @SupriyaKalghatgi ? Thanks in advance.

ghost avatar Apr 17 '19 17:04 ghost