我的 RNNv2 顶部栏中有一个自定义组件“菜单按钮”。我希望 openMenu() 在单击此按钮时运行,但这不会发生。我的打字稿 linting 告诉我Property openMenu does not exist on typeof Home
。为什么是这样?
class Home extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
Navigation.events().bindComponent(this);
}
closeMenu = () => {
this._drawer.close();
};
openMenu = () => {
this._drawer.open();
};
static options(passProps) {
return {
topBar: {
rightButtons: [
{
component: {
name: 'MenuButton',
passProps: {
onClick: () => this.openMenu(),
},
},
},
],
},
};
}
render() {
return (
...
);
}
}
参考我的passProps
代码来自:https ://github.com/wix/react-native-navigation/issues/3648