Closed penmatsa closed 6 years ago
this is the right way of working.
if you do not want to be triggered again when the GPS provider is turned off, you can stop the listener with the LocationServicesDialogBox.stopListener()
method.
DeviceEventEmitterListener=(params) => {
if(!params. enabled){
LocationServicesDialogBox.stopListener();
}
}
Hi,
if I off location for once. the listener is calling multiple times and so It enters if condition multiple times.
android version? react native version ? what type of device are you using ? (emulator or real)
android version : 26(SDK) react native version : 0.56.0 device : Samsung s8 (oreo)
The same situation. Any solutions?
It's not a problem of react-native-android-location-services-dialog-box
.
It's a problem about touchable events on Android itself.
You should use deboune
like:
import { debounce } from 'lodash';
...
DeviceEventEmitter.addListener('locationProviderStatusChange', debounce(this.DeviceEventEmitterListener));
constructor(){ super(); this.DeviceEventEmitterListener = this.DeviceEventEmitterListener.bind(this); }
componentWillMount(){
this.enableLocations(); }
componentWillUnmount() {
DeviceEventEmitterListener=(params) => {
enableLocations(){
}).then((success) =>{ console.log(success); // success => {alreadyEnabled: false, enabled: true, status: "enabled"}
}).catch((error) => {
}); }