来自 UI Kitten 的 Top Navigation 组件如何作为自定义 header 在 React Native Stack Navigator 中使用
How can Top Navigation component from UI Kitten can be used in React Native Stack Navigator as a custom header
我有一个使用 UI Kitten“顶部导航”组件设计的自定义 header 组件(link 下面的示例)我想将其用作 header 在主页上而不是 header Stack Navigator 提供
假设在 NotificationScreen
中使用名为 AppHeader
的自定义“顶部导航”组件
import React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import routes from './routes';
import AppHeader from '../components/AppHeader';
import NotificationScreen from '../screens/notification/NotificationScreen';
import UserProfileScreen from '../screens/userProfile/UserProfileScreen';
const {Navigator, Screen} = createStackNavigator();
const StackNavigatorPage = () => (
<Navigator>
<Screen name={routes.NOTIFICATION_SCREEN} component={NotificationScreen} />
<Screen name={routes.USER_PROFILE_SCREEN} component={UserProfileScreen} />
</Navigator>
);
export default StackNavigatorPage;
import React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import routes from './routes';
import AppHeader from '../components/AppHeader';
import NotificationScreen from '../screens/notification/NotificationScreen';
import UserProfileScreen from '../screens/userProfile/UserProfileScreen';
import HomeScreen from '../screens/dashboard/HomeScreen';
const {Navigator, Screen} = createStackNavigator();
const StackNavigatorPage = () => (
<Navigator>
<Screen
name={routes.HOME_SCREEN}
component={HomeScreen}
options={({navigation}) => {
return {
header: () => <AppHeader navigation={navigation} />,
};
}}
/>
<Screen name={routes.NOTIFICATION_SCREEN} component={NotificationScreen} />
<Screen name={routes.USER_PROFILE_SCREEN} component={UserProfileScreen} />
</Navigator>
);
export default StackNavigatorPage;
我有一个使用 UI Kitten“顶部导航”组件设计的自定义 header 组件(link 下面的示例)我想将其用作 header 在主页上而不是 header Stack Navigator 提供
假设在 NotificationScreen
AppHeader
的自定义“顶部导航”组件
import React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import routes from './routes';
import AppHeader from '../components/AppHeader';
import NotificationScreen from '../screens/notification/NotificationScreen';
import UserProfileScreen from '../screens/userProfile/UserProfileScreen';
const {Navigator, Screen} = createStackNavigator();
const StackNavigatorPage = () => (
<Navigator>
<Screen name={routes.NOTIFICATION_SCREEN} component={NotificationScreen} />
<Screen name={routes.USER_PROFILE_SCREEN} component={UserProfileScreen} />
</Navigator>
);
export default StackNavigatorPage;
import React from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import routes from './routes';
import AppHeader from '../components/AppHeader';
import NotificationScreen from '../screens/notification/NotificationScreen';
import UserProfileScreen from '../screens/userProfile/UserProfileScreen';
import HomeScreen from '../screens/dashboard/HomeScreen';
const {Navigator, Screen} = createStackNavigator();
const StackNavigatorPage = () => (
<Navigator>
<Screen
name={routes.HOME_SCREEN}
component={HomeScreen}
options={({navigation}) => {
return {
header: () => <AppHeader navigation={navigation} />,
};
}}
/>
<Screen name={routes.NOTIFICATION_SCREEN} component={NotificationScreen} />
<Screen name={routes.USER_PROFILE_SCREEN} component={UserProfileScreen} />
</Navigator>
);
export default StackNavigatorPage;