React-native-tab-view: can't dynamic change Tablabel fonsize

Created on 1 Jul 2019  路  11Comments  路  Source: satya164/react-native-tab-view

dynamic change Tablabel fonsize and it will incomplete display.

navigationState={tabRoute}
renderScene={SceneMap({
troubleTicket: () => (),
requestSupport: () => (),
commandMission: () => (),
onSiteAcceptance: () => (),
riskOperation: () => (),
onSiteCooperation: () => (),
businessOpening: () => (),
resourceChange: () => (),
jobPlan: () => (),
})}
renderTabBar={props =>
{...props}
style={styles.tabViewStyle}
tabStyle={styles.tabBarStyle}
scrollEnabled={true}
renderIndicator={() => (null)}
renderLabel={({ route, focused, color }) => {
if (focused)
return (
{route.title}

)
return (
{route.title}

)
}}
/>
}
onIndexChange={this.onTabChange}
initialLayout={{ width: Dimensions.get('window').width }}
lazy
/>

question

Most helpful comment

<TabView
   navigationState={tabRoute}
   renderScene={SceneMap({
    troubleTicket: () => <WaitDoneInfo />,
    requestSupport: () => <WaitDoneInfo />,
    commandMission: () => <WaitDoneInfo />,
    onSiteAcceptance: () => <WaitDoneInfo />,
    riskOperation: () => <WaitDoneInfo />,
    onSiteCooperation: () => <WaitDoneInfo />,
    businessOpening: () => <WaitDoneInfo />,
    resourceChange: () => <WaitDoneInfo />,
    jobPlan: () => <WaitDoneInfo />
   })}
   renderTabBar={props => (
    <TabBar
     {...props}
     style={styles.tabViewStyle}
     tabStyle={styles.tabBarStyle}
     scrollEnabled={true}
     renderIndicator={() => null}
     renderLabel={({ route, focused, color }) => {
      if (focused){
       return <Text style={{ color, fontSize: 15 }}> {route.title} </Text>;
      }
      return <Text style={{ color, fontSize: 15 }}> {route.title} </Text>;
     }}
    />
   )}
   onIndexChange={this.onTabChange}
   initialLayout={{ width: Dimensions.get("window").width }}
   lazy
/>

it is wrong? i mean how can i dynamic change Tab label fonsize

All 11 comments

The code you have written is wrong, you have to close Text tag
Closing as it's not an issue

<TabView
   navigationState={tabRoute}
   renderScene={SceneMap({
    troubleTicket: () => <WaitDoneInfo />,
    requestSupport: () => <WaitDoneInfo />,
    commandMission: () => <WaitDoneInfo />,
    onSiteAcceptance: () => <WaitDoneInfo />,
    riskOperation: () => <WaitDoneInfo />,
    onSiteCooperation: () => <WaitDoneInfo />,
    businessOpening: () => <WaitDoneInfo />,
    resourceChange: () => <WaitDoneInfo />,
    jobPlan: () => <WaitDoneInfo />
   })}
   renderTabBar={props => (
    <TabBar
     {...props}
     style={styles.tabViewStyle}
     tabStyle={styles.tabBarStyle}
     scrollEnabled={true}
     renderIndicator={() => null}
     renderLabel={({ route, focused, color }) => {
      if (focused){
       return <Text style={{ color, fontSize: 15 }}> {route.title} </Text>;
      }
      return <Text style={{ color, fontSize: 15 }}> {route.title} </Text>;
     }}
    />
   )}
   onIndexChange={this.onTabChange}
   initialLayout={{ width: Dimensions.get("window").width }}
   lazy
/>

it is wrong? i mean how can i dynamic change Tab label fonsize

fontSize is same for both focused and non focused elements!!

renderTabBar={props => <TabBar {...props} style={styles.tabViewStyle} tabStyle={styles.tabBarStyle} scrollEnabled={true} renderIndicator={() => (null)} labelStyle={{ fontSize: 17 }} renderLabel={({ route, focused, color }) => { if (!focused) return ( <Text style={{ color, fontSize: 14 }}> {route.title} </Text> ) return ( <Text style={{ color, fontSize: 17 }}> {route.title} </Text> ) }} /> } onIndexChange={this.onTabChange} initialLayout={{ width: Dimensions.get('window').width }} lazy />
sorry,my code 锛孖n fact, this is the case銆俿o fontSize can change? i changed and Showing a bit of a problem

IMG_20190701_211845

You can set custom height and width in tabStyle to make sure your text fits.

I set custom height and width,but i does't work.

tabBarStyle: { width: Dimensions.get('window').width / 2, height: 100 },
IMG_20190701_213522

renderLabel={({ route, focused, color }) => {
  if (focused){
    return <Text style={{ color, fontSize: 15, minWidth: 100, textAlign: 'center' }}> {route.title} </Text>;
  }
  return <Text style={{ color, fontSize: 15, minWidth: 100, textAlign: 'center' }}> {route.title} </Text>;
}}

Try to give a minWidth to the Text element. @chen504554911

@chakrihacker Your answer doesn't mean anything to solve the problem. You can't solve the problem. By closing the problem, you close the opportunity for others to solve the problem

<TabBar {...props} renderLabel={this._renderLabel} />

_renderLabel = ({ route, focused }) => { if (focused) { return <Text style={{ fontSize: 15 }}> {route.title} </Text>; } return <Text style={{ fontSize: 18 }}> {route.title} </Text>; }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndriiUhryn picture AndriiUhryn  路  3Comments

t3chnoboy picture t3chnoboy  路  3Comments

glennvgastel picture glennvgastel  路  3Comments

ios-dev-newbie picture ios-dev-newbie  路  3Comments

moerabaya picture moerabaya  路  4Comments