React 本机应用程序在发布模式下崩溃,出现以下错误 null is not an object (evaluating 's.drawer._root')
React native App gets crashed on release mode with the following error null is not an object (evaluating '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()}
>
看看 react document 关于 ref
If the ref callback is defined as an inline function, it will get called twice during updates, first with null and then again with the DOM element
在您的 closeDrawer 和 openDrawer 回调中,this.drawer 可能为空,也许您应该添加一些代码,例如
this.drawer && this.drawer._root && this.drawer._root.close();
this.drawer && this.drawer._root && this.drawer._root.open();
我使用了本机基础抽屉,它在调试模式下工作正常,但是当我创建一个发布 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()}
>
看看 react document 关于 ref
If the ref callback is defined as an inline function, it will get called twice during updates, first with null and then again with the DOM element
在您的 closeDrawer 和 openDrawer 回调中,this.drawer 可能为空,也许您应该添加一些代码,例如
this.drawer && this.drawer._root && this.drawer._root.close();
this.drawer && this.drawer._root && this.drawer._root.open();