我使用了本机基础抽屉,它在调试模式下工作正常,但是当我创建发行版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()}
>
答案 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();