嗨,我刚开始学习 React Native! 尝试制作自定义抽屉导航器 我为抽屉的内容创建了一个组件 抽屉导航器,如反应导航网站中所述 然后像这样将该组件添加到抽屉本身 不明白为什么我们要在抽屉里添加这样的道具??!!
import React from 'react'
import {View,Text} from 'react-native'
import {createDrawerNavigator} from '@react-navigation/drawer'
import { NavigationContainer } from '@react-navigation/native';
import MainViewHome from './mainViewHome'
import mainViewArticles from './mainViewArticles'
import DrawerContent from './drawerContent'
const drawer=createDrawerNavigator();
export default function MainView(){
return(
<drawer1.Navigator drawerContent={props=><MainViewDrawer {...props}/>}>
<drawer.Screen name='home' component={MainViewHome}/>
<drawer.Screen name='articles' component={mainViewArticles}/>
</drawer1.Navigator>
)
}
感谢您的帮助!
答案 0 :(得分:0)
我不明白为什么我们要在抽屉里添加这样的道具??!!
drawerContent 默认接收以下道具:
见here
现在假设您想将更多道具传递给 MainViewDrawer 组件:
import React,{useState} from 'react';
import {createDrawerNavigator} from '@react-navigation/drawer';
import MainViewDrawer from './MainViewDrawer';
...
const drawer =createDrawerNavigator();
export default function MainView(){
const [newProps, setNewProps] = useState('Hello world');
return(
<drawer.Navigator drawerContent={props=><MainViewDrawer {...props} newProps={newProps} />}>
...
</drawer.Navigator>
)
};