【发布时间】:2019-06-28 23:24:32
【问题描述】:
我正在尝试在我的抽屉上添加一个注销按钮,所以我使用 contentComponent 来单独自定义创建注销(而不是其他抽屉菜单)。所以,我创建了一个类并试图接收 DrawerItems 但它说没有定义道具。请帮忙。
我的代码自定义组件:
class DrawerComponent extends Component {
constructor(props) {
super(props)
console.log(this.props)
}
render () {
return (
<View style={{flex:1}}>
<SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }}>
<DrawerItems {props.children} />
<TouchableOpacity onPress={() => console.log("Pressed")}>
<Text>
Logout
</Text>
</TouchableOpacity>
</SafeAreaView>
</View>
);
}
};
我的抽屉选项:
const DrawerNavigator = createDrawerNavigator({
Dashboard: {
screen: AppStackNavigator,
navigationOptions: {
drawerLabel: "Home",
}
},
Training: {
screen: Training,
navigationOptions: {
drawerLabel: "Training"
}
},
RoutePlan: {
screen: RouteCalendar,
navigationOptions: {
drawerLabel: "Route Plan"
}
},
Logout: {
screen: StoreList,
navigationOptions: {
drawerLabel: "Logout"
}
}
},
{
contentOptions: {
activeTintColor: '#127CC1',
},
contentComponent: props => <DrawerComponent {...props}/>,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
navigationOptions : ({navigation}) => {
const { routeName } = navigation.state.routes[navigation.state.index];
const headerTitle = routeName;
return {
headerTitle,
headerLeft: (
<Icon name="md-menu" style={{ marginLeft: 10 }}
onPress={() => navigation.toggleDrawer()}
/>
)
}
}
}
);
我的 customComponent 页面出现错误。请帮助我度过难关!
【问题讨论】:
标签: javascript react-native react-native-navigation