React 本机应用程序在发布模式下崩溃,出现以下错误 null 不是对象(评估"s.drawer._root")



我使用的是在调试模式下运行良好的本机基础抽屉

AndroidRuntime: com.facebook.react.common.JavascriptException: null is 
not an object (evaluating 's.drawer._root')

代码:

 closeDrawer = () => {
 this.drawer._root && this.drawer._root.close();
};
openDrawer = () => {
this.drawer._root && this.drawer._root.open();
};
<Drawer
      ref={(ref) => {
        this.drawer = ref;
      }}
      type="overlay"
      side={'left'}
      openDrawerOffset={0.2}
      panOpenMask={0.2}
      tapToClose={true}
      content={
        <SideBar
          navigator={this.navigator}
          closeDrawer={() => this.closeDrawer()}
          {...this.props}
        />
      }
      tweenHandler={(ratio) => ({
        main: { opacity: (2 - ratio) / 2 }
      })}
      onClose={() => this.closeDrawer()}
    >

查看有关Ref

的React文档

如果参考回调定义为内联函数,则在更新期间将两次调用,首先使用null,然后再用DOM元素

再次调用

在您的闭合器和opendrawer回调中,此抽屉可能是无效的,也许您应该添加一些代码,例如

this.drawer && this.drawer._root && this.drawer._root.close();
this.drawer && this.drawer._root && this.drawer._root.open();

最新更新