android - React native App 在发布模式下崩溃,并出现以下错误 null is not an object (evalating 's.drawer._root')
问题描述
我使用了本机基础抽屉,它在调试模式下工作正常,但是当我创建发布 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()}
>
解决方案
看一下关于 ref的react 文档
如果 ref 回调被定义为内联函数,它将在更新期间被调用两次,第一次使用 null,然后再次使用 DOM 元素
在您的 closeDrawer 和 openDrawer 回调中, this.drawer 可能为空,也许您应该添加一些代码,例如
this.drawer && this.drawer._root && this.drawer._root.close();
this.drawer && this.drawer._root && this.drawer._root.open();
推荐阅读
- maven - 即使在 Cygwin 中成功,Maven 也会返回 0
- java - 输入流的什么输入会导致IOException?
- canvas - WebGL 2 - 奇怪的混合行为
- hash - Murmurhash 在 32 位输入上有冲突吗?
- sql-server - 您可以在不删除消息的情况下从 Service Broker 队列中读取吗?
- python - Python - 如何访问实例变量?
- javascript - 如何从 Javascript 中的嵌套对象中获取值数组
- php - 如何在带有斜杠的 URL 中获取 woocommerce 的订单 ID
- jmeter - JMeter Maven 插件无法从创建的胖快照 Jar 中检测到 JUnit 测试
- python - FastApi:将一个 JSon 解析成可以具有不同属性的模型