React native 如何将值从屏幕传递到底部选项卡图标徽章?

React native 如何将值从屏幕传递到底部选项卡图标徽章?,react-native,react-navigation,react-props,React Native,React Navigation,React Props,我希望能够为我的底部选项卡(提醒)的图标之一设置徽章,但我不知道如何传递该值,以便徽章显示提醒屏幕中给出的数值 那我该怎么做呢?我对react导航的工作原理很困惑。任何帮助都将不胜感激!谢谢 在App.js中 const TabStack = createBottomTabNavigator( { Home : { screen: HomeStack }, Reminders: { screen: ReminderStack, navigationOptions:

我希望能够为我的底部选项卡(提醒)的图标之一设置徽章,但我不知道如何传递该值,以便徽章显示提醒屏幕中给出的数值

那我该怎么做呢?我对react导航的工作原理很困惑。任何帮助都将不胜感激!谢谢

在App.js中

const TabStack = createBottomTabNavigator(
  {
    Home : { screen: HomeStack },
    Reminders: { screen: ReminderStack,
      navigationOptions: ({ screenProps }) => ({
        tabBarIcon: ({tintColor}) =>
        <View style={{flexDirection: 'row',alignItems: 'center',justifyContent: 'center',}}>
        <IconBadge
          MainElement={
            <View style={{
              marginRight:15
            }}>
            <Ionicons name={`ios-alarm`} size={30} color={tintColor} />
          </View>

          }
          BadgeElement={

            <Text style={{color:'#FFFFFF'}}>{screenProps.notifCount}</Text>
          }
          Hidden={true}
          IconBadgeStyle={
            {width:20,
            height:20,
            backgroundColor: 'red'}
          }

          />
      </View>

      })

    },
  },

  {
    defaultNavigationOptions: ({ navigation }) => ({
      tabBarIcon: ({ focused, horizontal, tintColor }) => {
        const { routeName } = navigation.state;
        let IconComponent = Ionicons;
        let iconName;
        if (routeName === 'Home') {
          iconName = `ios-home`;
        } else if (routeName === 'Reminders') {
          iconName = `ios-alarm`;
        }

        return <IconComponent name={iconName} size={25} color={tintColor} />;
      },
    }),
    tabBarOptions: {
      activeTintColor: '#0892d0',
      inactiveTintColor: 'gray',
    },
  }
);
const TabStack=createBottomTabNavigator(
{
主页:{screen:HomeStack},
提醒:{屏幕:提醒斯塔克,
导航选项:({screenProps})=>({
tabBarIcon:({tintColor})=>
})
},
},
{
defaultNavigationOptions:({navigation})=>({
tabBarIcon:({聚焦、水平、着色})=>{
const{routeName}=navigation.state;
让IconComponent=Ionicons;
让我来;
如果(routeName==='Home'){
iconName='ios主页';
}否则如果(routeName===‘提醒’){
iconName=`ios报警`;
}
返回;
},
}),
选项卡选项:{
activeTintColor:“#0892d0”,
颜色:“灰色”,
},
}
);
在memberscreen.js中

import React from 'react';
import { Text, View, TouchableOpacity, StyleSheet,Image,ScrollView,Dimensions} from 'react-native';
import { ListItem, withBadge,Badge, } from 'react-native-elements';
import { Container, Header, Tab, Tabs, ScrollableTab } from 'native-base';
import R_Equipment from './rEquipmentTab';
import R_Room from './rRoomTab';
import axios from 'axios';


  export default class ReminderScreen extends React.Component {

    render() {

      return (
        //I want to pass a notifCount variable back to Tabstack
        //e.g. notifCount = 5
        <Container>

        <Tabs  renderTabBar={()=> <ScrollableTab />}>
          <Tab heading="Rooms">
            <R_Room navigation={this.props.navigation} />
          </Tab>
          <Tab heading="Equipment">
            <R_Equipment navigation={this.props.navigation} />
          </Tab>

        </Tabs>
      </Container>


      );
    }
  }
  const styles = StyleSheet.create({
    displayImage: {
      height: 50,
      width: 100,
      borderRadius: 10,

    },
  });
从“React”导入React;
从“react native”导入{文本、视图、TouchableOpacity、样式表、图像、滚动视图、维度};
从“react native elements”导入{ListItem,withBadge,Badge,};
从“本机基”导入{容器、标题、选项卡、选项卡、可滚动选项卡};
从“/requirementtab”导入R_设备;
从“./rRoomTab”导入R_文件室;
从“axios”导入axios;
导出默认类提醒屏幕扩展React.Component{
render(){
返回(
//我想将notifCount变量传递回Tabstack
//e、 g.notifCount=5
}>
);
}
}
const styles=StyleSheet.create({
显示图像:{
身高:50,
宽度:100,
边界半径:10,
},
});

您可以将其作为父对象发送给子对象,或者您可以使用state,如果更方便的话,您可以使用Redux

//这将使用vanilla.js或state common

<YourComponent = badgeData={this.state.badgedata} />
或者,有关更多详细信息,您不能点击以下链接:


您可以将其作为父对象发送给子对象,或者您可以使用state,如果更方便的话,您可以使用Redux

//这将使用vanilla.js或state common

<YourComponent = badgeData={this.state.badgedata} />
或者,有关更多详细信息,您不能点击以下链接:


我遇到了同样的问题,有什么解决办法吗?我遇到了同样的问题,有什么解决办法吗?