React native 如何在一个标题下指定不同的样式?

React native 如何在一个标题下指定不同的样式?,react-native,tabs,styles,native-base,React Native,Tabs,Styles,Native Base,Native Base随包装器一起提供,因此您可以根据需要对其进行自定义 示例: <Tab heading={ <TabHeading style={{ flexDirection: 'column'}}> <Text style={{ fontSize: 20 }}>{date.format('DD/MM')}</Text> <Text

Native Base随包装器一起提供,因此您可以根据需要对其进行自定义

示例:

<Tab 
          heading={
            <TabHeading style={{ flexDirection: 'column'}}>
                <Text style={{ fontSize: 20 }}>{date.format('DD/MM')}</Text>
                <Text style={{ fontSize: 15 }}>{this.props.weekdayArray[date.day()]}</Text>
             </TabHeading>
          }
          tabStyle={styles.tabStyling} 
          activeTabStyle={styles.activeTabStyle} 
          textStyle={styles.tabTextStyle} 
          activeTextStyle={styles.activeTabTextStyle} 
        >
          <View style={{backgroundColor:'#EEEEEE', flex: 1}}>
            <Content contentDate={date.format('DD/MM')} />
          </View>
        </Tab>
从'native base'导入{Text,Tab,TabHeading,Content,Tabs}
//设置初始状态
建造师(道具){
超级()
此.state={
当前选项卡:0
}
}
this.setState({currentTab:i})
renderTabBar={()=>}>
>

请注意,
TabHeader
是另一个组件,因此它不会继承
选项卡的样式,除非您没有特定的主题,因此您还需要有条件地传递样式。

尝试根据当前选项卡动态设置文本样式

import {Text, Tab, TabHeading, Content, Tabs} from 'native-base'
// Setting the initial State
constructor(props) {
        super()
        this.state = {
            currentTab: 0
        }
    }

<Tabs
   initialPage={this.state.currentTab}
   onChangeTab={({ i }) => this.setState({ currentTab: i })}
   renderTabBar={()=> <ScrollableTab/>}>
>
      <Tab
          heading={
             <TabHeading style={this.state.currentTab === 0 ? styles.activeTabStyle : styles.tabStyling}
      >
                <Text styles={this.state.currentTab === 0 ? styles.activeTabTextStyle : styles.tabTextStyle}>{'Pritish'}</Text>
                <Text styles={this.state.currentTab === 0 ? styles.activeTabTextStyle : styles.tabTextStyle}>{'Vaidya'}</Text>
             </TabHeading>
                   }
        >
           <View style={{ backgroundColor: '#EEEEEE', flex: 1 }}>
              <Content contentDate={moment().format('DD/MM')} />
           </View>
      </Tab>
</Tabs>
import React,{Component}来自'React';
从'native base'导入{Container,Header,Tab,Tabs,TabHeading,Text,ScrollableTab};
从“react native”导入{StyleSheet};
const dataArray=[{日期:“周一”,日期:“16/04”,内容:“表一”},
{日期:“星期二”,日期:“17/04”,内容:“表二”},
{日期:“星期三”,日期:“18/04”,内容:“表三”},
{日期:“星期四”,日期:“19/04”,内容:“表四”},
{日期:“星期五”,日期:“20/04”,内容:“表五”},
{日期:“星期六”,日期:“21/04”,内容:“表六”},
{日期:“太阳”,日期:“2004年22月”,内容:“表七”}]
导出默认类TabsAdvancedExample扩展组件{
状态={currentPage:0}
render(){
返回(
}tabBarUnderlineStyle={{backgroundColor:{00f25f}}onChangeTab={({i})=>this.setState({currentPage:i})}>
{
dataArray.map((项目,索引)=>{
返回(
{item.content}
)
})
}
);
}
}
const styles=StyleSheet.create({
dayStyle:{颜色:“白色”,字体大小:12},
activeDayStyle:{颜色:“白色”,字体大小:18}
})

通过使用此
选项卡标题
,它确实给了我想要的东西,但它也引入了另一个问题,即删除了所有其他样式,如
选项卡样式
活动选项卡样式
、文本样式和
活动文本样式
,很抱歉响应太晚,但您需要使用NativeBase组件。查看更新的答案谢谢您的回复。对于上面列出的组件列表,我已经确保它遵循相同的原则,但仍然会产生相同的结果。如果您也可以在问题中添加样式,那就太好了,我已经更新了我的问题,包括两个选项卡的样式和屏幕截图,以供参考
import {Text, Tab, TabHeading, Content, Tabs} from 'native-base'
// Setting the initial State
constructor(props) {
        super()
        this.state = {
            currentTab: 0
        }
    }

<Tabs
   initialPage={this.state.currentTab}
   onChangeTab={({ i }) => this.setState({ currentTab: i })}
   renderTabBar={()=> <ScrollableTab/>}>
>
      <Tab
          heading={
             <TabHeading style={this.state.currentTab === 0 ? styles.activeTabStyle : styles.tabStyling}
      >
                <Text styles={this.state.currentTab === 0 ? styles.activeTabTextStyle : styles.tabTextStyle}>{'Pritish'}</Text>
                <Text styles={this.state.currentTab === 0 ? styles.activeTabTextStyle : styles.tabTextStyle}>{'Vaidya'}</Text>
             </TabHeading>
                   }
        >
           <View style={{ backgroundColor: '#EEEEEE', flex: 1 }}>
              <Content contentDate={moment().format('DD/MM')} />
           </View>
      </Tab>
</Tabs>
import React, { Component } from 'react';
import { Container, Header, Tab, Tabs, TabHeading, Text, ScrollableTab } from 'native-base';
import { StyleSheet } from 'react-native';

const dataArray = [{ day: "Mon", date: "16/04", content: "Tab one" },
{ day: "Tue", date: "17/04", content: "Tab two" },
{ day: "Wed", date: "18/04", content: "Tab three" },
{ day: "Thu", date: "19/04", content: "Tab four" },
{ day: "Fri", date: "20/04", content: "Tab five" },
{ day: "Sat", date: "21/04", content: "Tab six" },
{ day: "Sun", date: "22/04", content: "Tab seven" }]

export default class TabsAdvancedExample extends Component {
  state = { currentPage: 0 }
  render() {
    return (
      <Container>
        <Header />
        <Tabs renderTabBar={() => <ScrollableTab />} tabBarUnderlineStyle={{ backgroundColor: "#00f25f" }} onChangeTab={({ i }) => this.setState({ currentPage: i })}>
          {
            dataArray.map((item, index) => {
              return (<Tab key={String(index)} heading={<TabHeading style={{ flexDirection: 'column', backgroundColor: "#00ba6f" }}><Text style={{ color: "white" }}>{item.date}</Text><Text style={this.state.currentPage === index ? styles.activeDayStyle : styles.dayStyle}>{item.day}</Text></TabHeading>}>
                <Text>{item.content}</Text>
              </Tab>)
            })
          }
        </Tabs>
      </Container>
    );
  }
}
const styles = StyleSheet.create({
  dayStyle: { color: "white", fontSize: 12 },
  activeDayStyle: { color: "white", fontSize: 18 }
})