我有一个IconButton,目前允许用户通过导航到"Manage—box"组件来增加开销.我添加了一个新的BottomTab,显示收入.现在有3个BottomTab(最近费用,所有费用,所有收入).

我想更改添加费用IconButton,以便如果用户在AllIncome BottomTab屏幕上并按下该按钮,则将其定向到ManageIncome组件,如果用户在最近费用或AllExpenses BottomTab屏幕上,则将其导航到ManageIncome组件.

import ManageExpense from './screens/ManageExpense';
import RecentExpenses from './screens/RecentExpenses';
import AllExpenses from './screens/AllExpenses';
import { GlobalStyles } from './constants/styles';
import IconButton from './components/UIElements/IconButton';
import ExpensesContextProvider from './context/expensesContext';
import AllIncome from './screens/AllIncome';
import { IncomeContextProvider } from './context/incomeContext';
import ManageIncome from './screens/ManageIncome';

const Stack = createNativeStackNavigator();
const BottomTabs = createBottomTabNavigator();

function ExpensesOverview() {

  
  return (
    <BottomTabs.Navigator screenOptions={({ navigation }) => ({

      headerStyle: { backgroundColor: GlobalStyles.colors.primary500 },
      headerTintColor: 'white',
      tabBarStyle: { backgroundColor: GlobalStyles.colors.primary500 },
      tabBarActiveTintColor: GlobalStyles.colors.accent500,
      headerRight: ({ tintColor }) => (
        <IconButton
          icon="add-circle-outline"
          size={26} color={tintColor}
          onPress={() => {
            navigation.navigate('ManageExpense');
          }}>
        </IconButton>
      ),
    })}
    >
      <BottomTabs.Screen
        name="RecentExpenses"
        component={RecentExpenses}
        options={{
          title: 'Recent Expenses',
          tabBarLabel: 'Recent Expenses',
          tabBarIcon: ({ color, size }) => (
            <Ionicons name="time-outline" size={size} color={color} />
          ),
        }}
      />
      <BottomTabs.Screen
        name="AllExpenses"
        component={AllExpenses}
        options={{
          title: 'All Expenses',
          tabBarLabel: 'All Expenses',
          tabBarIcon: ({ color, size }) => (
            <Ionicons name="globe-outline" size={size} color={color} />
          ),
        }}
      />
      <BottomTabs.Screen
        name="AllIncome"
        component={AllIncome}
        options={{
          title: 'All Income',
          tabBarLabel: 'View Income',
          tabBarIcon: ({ color, size }) => (
            <Ionicons name="cash-outline" size={size} color={color}></Ionicons>
          ),
        }}
      />
    </BottomTabs.Navigator>
  );
}

export default function App() {
  return (
    <>
      <StatusBar style="auto" />
      <ExpensesContextProvider>
        <IncomeContextProvider>
          <NavigationContainer>
            <Stack.Navigator screenOptions={{
              headerStyle: { backgroundColor: GlobalStyles.colors.primary500 },
              headerTintColor: 'white',
              headerBackTitle: 'Back',
            }}>
              <Stack.Screen
                name="ExpensesOverview"
                component={ExpensesOverview}
                options={{ headerShown: false }}
              />
              <Stack.Screen
                name="ManageExpense"
                component={ManageExpense}
                options={{
                  presentation: 'modal',
                }} />
                 <Stack.Screen
                name="ManageIncome"
                component={ManageIncome}
                options={{
                  presentation: 'modal',
                }} />
            </Stack.Navigator>
          </NavigationContainer>
        </IncomeContextProvider>
      </ExpensesContextProvider>
    </>
  );
};

我试过使用useRoute()函数,但它似乎只返回'ExpensesOverview'值,所以它不能区分不同的BottomTabs,但我可能用错了.谢谢.

推荐答案

更新报头的一种方法是在特定的Screen中使用options.headerRightHomeScreen更新.

<Tab.Navigator
  screenOptions={({ navigation, route }) => ({
    headerRight: () => <Button title="Default" />,
  })}>
  <Tab.Screen
    name="Home"
    component={HomeScreen}
    options={({ navigation, route }) => ({
      headerRight: () => <Button title="Update" />,
    })}
  />
  <Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>

Javascript相关问答推荐

用相器进行向内碰撞检测

字节数组通过echo框架传输到JS blob

未捕获错误:在注销后重定向到/login页面时找不到匹配的路由

网页自检测外部元素无法加载

从WooCommerce Checkout Country字段重新排序国家,保持国家同步

使用LocaleCompare()进行排序时,首先使用大写字母

虚拟滚动实现使向下滚动可滚动到末尾

material UI按钮组样式props 不反射

为什么我的自定义元素没有被垃圾回收?

将Node.js包发布到GitHub包-错误ENEEDAUTH

从另一个数组中的对应行/键值对更新数组中的键值对对象

使用Ace编辑器对子组件实例的native-element 进行Angular 获取时面临的问题

如果一个字符串前面有点、空格或无字符串,后面有空格、连字符或无字符串,则匹配正则表达式

如何在AG-Grid文本字段中创建占位符

Jexl to LowerCase()和Replace()

JavaScript -复制到剪贴板在Windows计算机上无效

Angel Auth Guard-用户只有在未登录时才能访问登录页面,只有在登录时才能访问其他页面

需要刷新以查看Mern堆栈应用程序中的更改

在使用JavaScript以HTML格式显示Google Drive中的图像时遇到问题

Reaction-在同一页内滚动导航(下拉菜单)