0

假设我有以下代码片段来创建一个DrawerNavigator

export const DrawerApp = DrawerNavigator({
    PageHome: {
        screen: InboxScreen
    },
},
{
    contentComponent: props => <RightMenuScreen />,
    drawerPosition: 'right'
});

我从这里的示例中读到,我可以banner使用类似的语法将道具(如道具)传递给功能组件

const MyNavScreen = ({ navigation, banner }) => (<View><Text>{banner}</Text></View>);
// ...
// ...
// ...
const InboxScreen = ({ navigation }) => (
    <MyNavScreen banner={'InboxScreen'} navigation={navigation} />
);

但是,如果我使用类 Component 声明我的 Component,我该如何归档将我的自定义 prop 传递给MyNavScreen

class InboxScreen extends Component {

    render() {
        // here I want to get a prop like `banner` or `callback` from props
    }
}
4

1 回答 1

0

通过使用this.props你可以达到同样的效果

class InboxScreen  extends Component{
static navigationOptions = {
  drawerLabel: 'Inbox',
  drawerIcon: ({ tintColor }) => (
    <MaterialIcons
      name="move-to-inbox"
      size={24}
      style={{ color: tintColor }}
    />
  ),
};
render (){
  return(
  <MyNavScreen banner={'Inbox Screen'} navigation={this.props.navigation} />
  );
}
}
于 2017-05-29T10:52:29.793 回答