例如,在iOS中,我想在UINavigationController B
上方显示UINavigationController A
UINavigationController B
(新堆栈)来启动流程UINavigationController B
将删除显示的堆栈,并将用户带回主页 代码看起来像这样
let navController = UINavigationController(rootViewController: destination)
source.present(navController, animated: animated, completion: completion)
source -> UINavigationController A
navController -> UINavigationController B
如何使用React Navigation在 React Native 中实现这一目标?
答案 0 :(得分:0)
这种导航通常要做的是创建一个包含NavigationController B
的组件作为NavigationController A
上的路线
类似这样的东西:
import React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import Dashboard from '../pages/Dashboard';
import Invoices from '../pages/Invoices';
import Profile from '../pages/Profile';
import Contacts from '../pages/Contacts';
const App = createStackNavigator();
const User = createStackNavigator();
const UserRoutes: React.FC = () => (
<User.Navigator>
<User.Screen name="Profile" component={Profile} />
<User.Screen name="Contacts" component={Contacts} />
</User.Navigator>
)
const AppRoutes: React.FC = () => (
<App.Navigator>
<App.Screen name="Dashboard" component={Dashboard} />
<App.Screen name="User" component={UserRoutes} />
</App.Navigator>
);
export default AppRoutes;
上面的示例使用React Navigation v5和Typescript。
您可以创建任何导航嵌套,然后将其作为Routes。