Javascript React Native Android hardaware BackButton click上出错;Undefined不是一个函数(计算';_this2.close()';);
我已经安装了react native-orientation-loading overlay软件包,用于在屏幕上应用加载程序。 当用户单击硬件后退按钮时,将调用backAndroid的addEventListener。根据条件,加载程序的动画属性设置为true,方向加载程序开始加载。 加载时,另一个函数Javascript React Native Android hardaware BackButton click上出错;Undefined不是一个函数(计算';_this2.close()';);,javascript,android,react-native,Javascript,Android,React Native,我已经安装了react native-orientation-loading overlay软件包,用于在屏幕上应用加载程序。 当用户单击硬件后退按钮时,将调用backAndroid的addEventListener。根据条件,加载程序的动画属性设置为true,方向加载程序开始加载。 加载时,另一个函数this.fetchData()开始运行,该函数通过运行webservice获取数据,并显示在同一页面的listview中,即mainPage。 加载时,如果用户再次按下后退按钮,则显示红色屏幕,
this.fetchData()
开始运行,该函数通过运行webservice获取数据,并显示在同一页面的listview中,即mainPage。
加载时,如果用户再次按下后退按钮,则显示红色屏幕,错误为“react native Orientation loading overlay\src\index.js file的onRequestClose方法中的Undefined不是函数(评估\u this2.close()
”。我已尝试BackAndroid.removeEventListener('hardwareBackPress',()=>{})加载程序的动画属性设置为true但其值不为true后的代码>
工作
请给我任何解决办法
import OrientationLoadingOverlay from 'react-native-orientation-loading-overlay';
<OrientationLoadingOverlay
visible={this.state.animating}
color="#6495ed"
indicatorSize="large"
messageFontSize={16}
message="Loading..."
/>
这里的stack.length
是导航路由数组的长度。我的backButtonEvent()
函数如下所示:
BackAndroid.addEventListener('hardwareBackPress', () => {
if(this.state.drawerState===true) {
this.refs['draw'].closeDrawer();
} else {
if(this.props.navigator.getCurrentRoutes().length===1&&
this.state.tagPressed===false){
if (stack.length===0){
Alert.alert(
'Exit',
'Are you sure?',
[
{text: 'Cancel', onPress: () => {return true;}},
{text: 'Yes', onPress: () => BackAndroid.exitApp()},
],
)
} else {
this.backButtonEvent();
}
} else {
if(this.props.navigator.getCurrentRoutes().length===1&&
this.state.tagPressed===true) {
this.setState({ animating: true });
this.setState({ tagPressed: false });
this.setState({ title: 'Repository' });
this.fetchData();
} else {
this.props.navigator.pop();
}
}
}
return true;
});
backButtonEvent() {
if(stack.length===0) {
this.refs['draw'].openDrawer();
} else{
this.setState({animating:true});
dirPath = stack.pop();
title = this.titleStack.pop();
if(stack.length===0) {
this.setState({srcUrl:require('../image/drawer1.png')});
this.setState({drawerLock:'unlocked'});
}
this.fetchData();
}
}
<ListView
dataSource={this.state.dataSource}
renderRow={(this.renderItem.bind(this))}
enableEmptySections = {true}
/>
fetchData(data){
this.setState({
dataSource: this.state.dataSource.cloneWithRows(data)
});
}
backButtonEvent(){
if(stack.length==0){
this.refs['draw'].openDrawer();
}否则{
this.setState({animating:true});
dirPath=stack.pop();
title=this.titleStack.pop();
if(stack.length==0){
this.setState({srcUrl:require('../image/drawer1.png'))});
this.setState({drawerLock:'unlocked'});
}
这是fetchData();
}
}
获取数据(数据){
这是我的国家({
dataSource:this.state.dataSource.cloneWithRows(数据)
});
}
参考的第82行,它使用函数this.close()
关闭模式,但当参考时,this.close()
不是模式的预定义函数,因此当this.props.children的类型=='undefined'
时,它触发了上述错误。这是软件包的一个bug。它可能有新的状态来控制模式的开/关,并允许此.close()函数将状态更改为关闭模式。参考的第82行,它使用函数this.close()
来关闭模式,但当参考时,this.close()
不是模式的预定义函数,因此,当this.props.children==='undefined'
的类型时,它触发了上述错误。这是软件包的一个bug。它可能有新的状态来控制模式的开/关,并允许此.close()函数将状态更改为关闭模式。这非常有用。我在react native orientation加载覆盖包的index.js文件中声明了一个函数“close()”。这对我来说很好。这真的很有帮助。我在react native orientation加载覆盖包的index.js文件中声明了一个函数“close()”。所以它对我来说很好。