您可以使用抽屉导航配置中的 contentComponent 选项来实现它。根据所需的配置级别,您可以采用两种方法:
方法一。
DrawerItems 来自 react-navigation(自行处理导航)-
import {DrawerItems, DrawerNavigation} from 'react-navigation';
export default DrawerNavigator({
// ... your screens
}, {
// define customComponent here
contentComponent: (props) =>
<View style={{flex: 1}}>
<Text>Header</Text>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</View>
});
这会为下面的菜单项创建一个带有滚动视图的固定标题。
方法二。
创建您自己的自定义组件 -
import { DrawerNavigation } from 'react-navigation'
export default DrawerNavigator({
// ... your screens
}, {
// define customComponent here
contentComponent: props => <SideMenu {...props}>
});
这里的 SideMenu 是您自己的要在抽屉中显示的组件。您可以使用 react-navigation NavigationActions.navigate(screen) 来处理菜单项的 onPress 路由。
第二种方法更详细的解释https://medium.com/@kakul.gupta009/custom-drawer-using-react-navigation-80abbab489f7