所以我有一个SplashScreen,在启用gps之前,我还不想将其导航到AuthScreen.js。我该怎么办?
在我现在的情况下,它不起作用,GPS模式将显示,但是setTimeOut正在运行,或者SplashScreen在1000之后导航到AuthScreen。
我要停止的setTimeOut为1000,启用gps后它将继续计数,然后导航到AuthScreen.js。
我已经试图停止SplashScreen,但是我使用PermissionAndroid而不是GPS或LocationServicesDialog。因此,我现在尝试使用的是GPS位置,在无法正常工作后,请尝试同时运行Permission Android和GPS位置,但现在不必担心。现在让我们专注于GPS。谢谢!
async function requestGPStoEnable() {
try {
let check = await LocationServicesDialogBox.checkLocationServicesIsEnabled({
message: "<h2>Use Location?</h2> \
This app wants to change your device settings:<br/><br/>\
Use GPS for location<br/><br/>",
ok: "Yes",
cancel: "No",
enableHighAccuracy: true,
showDialog: true,
openLocationServices: true,
preventOutSideTouch: true,
preventBackClick: true,
providerListener: true
}).then(function(success) {
console.log(success);
}).catch((error) => {
console.log(error.message);
});
} catch (err) {
console.warn(err);
}
}
class SplashScreen extends Component {
constructor(props) {
super(props);
this.state = {
timePassed: false
};
}
componentDidMount() {
setTimeout( () => {
this.setTimePassed();
}, 1000)
requestGPStoEnable();
};
gpsLocation() {
if (Platform.OS === 'android') {
LocationServicesDialogBox.checkLocationServicesIsEnabled({
message: "<h2>Use Location?</h2> \
This app wants to change your device settings:<br/><br/>\
Use GPS for location<br/><br/>",
ok: "Yes",
cancel: "No",
enableHighAccuracy: true,
showDialog: true,
openLocationServices: true,
preventOutSideTouch: true,
preventBackClick: true,
providerListener: true
}).then(function(success) {
console.log(success);
// this.setTimePassed();
setTimeout( () => {
this.setTimePassed();
}, 1000)
}).catch((error) => {
console.log(error.message);
});
}
}
setTimePassed() {
this.setState({timePassed: true})
};
render() {
if(!this.state.timePassed) {
return (
<View style={styles.container}>
<Text>Hello</Text>
</View>
);
} else {
return <AuthScreen/>
}
};
};