React本机App在发布模式下崩溃,并显示以下错误null不是对象(评估's.drawer._root')

时间:2019-05-28 05:05:36

标签: android react-native native-base

我使用了本机基础抽屉,它在调试模式下工作正常,但是当我创建发行版APK时,应用崩溃了,并出现以下错误。

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()}
    >

1 个答案:

答案 0 :(得分:1)

看看有关参考文献的react document

  

如果ref回调被定义为内联函数,则在更新期间它将被调用两次,首先是null,然后是DOM元素

在您的closeDrawer和openDrawer回调中,this.drawer可能为null,也许您应该添加一些代码,例如

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