|
@@ -24,6 +24,10 @@ import {
|
|
usePostUpdateLocationMutation
|
|
usePostUpdateLocationMutation
|
|
} from '@api/location';
|
|
} from '@api/location';
|
|
import LocationIcon from 'assets/icons/location.svg';
|
|
import LocationIcon from 'assets/icons/location.svg';
|
|
|
|
+import {
|
|
|
|
+ startBackgroundLocationUpdates,
|
|
|
|
+ stopBackgroundLocationUpdates
|
|
|
|
+} from 'src/utils/backgroundLocation';
|
|
|
|
|
|
const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
const token = storage.get('token', StoreType.STRING) as string;
|
|
const token = storage.get('token', StoreType.STRING) as string;
|
|
@@ -37,6 +41,8 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
const [isSharingWithEveryone, setIsSharingWithEveryone] = useState(false);
|
|
const [isSharingWithEveryone, setIsSharingWithEveryone] = useState(false);
|
|
const [askLocationVisible, setAskLocationVisible] = useState<boolean>(false);
|
|
const [askLocationVisible, setAskLocationVisible] = useState<boolean>(false);
|
|
const [openSettingsVisible, setOpenSettingsVisible] = useState<boolean>(false);
|
|
const [openSettingsVisible, setOpenSettingsVisible] = useState<boolean>(false);
|
|
|
|
+ const [openSettingsBackgroundVisible, setOpenSettingsBackgroundVisible] =
|
|
|
|
+ useState<boolean>(false);
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
const syncSettings = async () => {
|
|
const syncSettings = async () => {
|
|
@@ -67,6 +73,7 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
setSettings({ token, sharing: 0 });
|
|
setSettings({ token, sharing: 0 });
|
|
storage.set('showNomads', false);
|
|
storage.set('showNomads', false);
|
|
setIsSharingWithEveryone(false);
|
|
setIsSharingWithEveryone(false);
|
|
|
|
+ await stopBackgroundLocationUpdates();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -85,6 +92,7 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
setSettings({ token, sharing: 0 });
|
|
setSettings({ token, sharing: 0 });
|
|
storage.set('showNomads', false);
|
|
storage.set('showNomads', false);
|
|
setIsSharingWithEveryone(false);
|
|
setIsSharingWithEveryone(false);
|
|
|
|
+ await stopBackgroundLocationUpdates();
|
|
}
|
|
}
|
|
setInitialPermissionStatus(status);
|
|
setInitialPermissionStatus(status);
|
|
};
|
|
};
|
|
@@ -112,6 +120,7 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
setSettings({ token, sharing: 0 });
|
|
setSettings({ token, sharing: 0 });
|
|
storage.set('showNomads', false);
|
|
storage.set('showNomads', false);
|
|
setIsSharingWithEveryone(false);
|
|
setIsSharingWithEveryone(false);
|
|
|
|
+ await stopBackgroundLocationUpdates();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
@@ -121,6 +130,18 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
|
|
|
|
if (status === 'granted' && isServicesEnabled) {
|
|
if (status === 'granted' && isServicesEnabled) {
|
|
getLocation();
|
|
getLocation();
|
|
|
|
+ const bgStatus = await Location.getBackgroundPermissionsAsync();
|
|
|
|
+ if (bgStatus.status !== 'granted') {
|
|
|
|
+ const { status } = await Location.requestBackgroundPermissionsAsync();
|
|
|
|
+ if (status === Location.PermissionStatus.GRANTED) {
|
|
|
|
+ await startBackgroundLocationUpdates();
|
|
|
|
+ } else {
|
|
|
|
+ await stopBackgroundLocationUpdates();
|
|
|
|
+ setOpenSettingsBackgroundVisible(true);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ await startBackgroundLocationUpdates();
|
|
|
|
+ }
|
|
} else if (!canAskAgain || !isServicesEnabled) {
|
|
} else if (!canAskAgain || !isServicesEnabled) {
|
|
setOpenSettingsVisible(true);
|
|
setOpenSettingsVisible(true);
|
|
} else {
|
|
} else {
|
|
@@ -148,6 +169,18 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
|
|
|
|
if (status === 'granted' && isServicesEnabled) {
|
|
if (status === 'granted' && isServicesEnabled) {
|
|
getLocation();
|
|
getLocation();
|
|
|
|
+ const bgStatus = await Location.getBackgroundPermissionsAsync();
|
|
|
|
+ if (bgStatus.status !== 'granted') {
|
|
|
|
+ const { status } = await Location.requestBackgroundPermissionsAsync();
|
|
|
|
+ if (status === Location.PermissionStatus.GRANTED) {
|
|
|
|
+ await startBackgroundLocationUpdates();
|
|
|
|
+ } else {
|
|
|
|
+ await stopBackgroundLocationUpdates();
|
|
|
|
+ setOpenSettingsBackgroundVisible(true);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ await startBackgroundLocationUpdates();
|
|
|
|
+ }
|
|
} else if (!canAskAgain || !isServicesEnabled) {
|
|
} else if (!canAskAgain || !isServicesEnabled) {
|
|
setOpenSettingsVisible(true);
|
|
setOpenSettingsVisible(true);
|
|
}
|
|
}
|
|
@@ -201,8 +234,11 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
/>
|
|
/>
|
|
<WarningModal
|
|
<WarningModal
|
|
type={'success'}
|
|
type={'success'}
|
|
- isVisible={openSettingsVisible}
|
|
|
|
- onClose={() => setOpenSettingsVisible(false)}
|
|
|
|
|
|
+ isVisible={openSettingsVisible || openSettingsBackgroundVisible}
|
|
|
|
+ onClose={() => {
|
|
|
|
+ setOpenSettingsVisible(false);
|
|
|
|
+ setOpenSettingsBackgroundVisible(false);
|
|
|
|
+ }}
|
|
action={async () => {
|
|
action={async () => {
|
|
const isServicesEnabled = await Location.hasServicesEnabledAsync();
|
|
const isServicesEnabled = await Location.hasServicesEnabledAsync();
|
|
|
|
|
|
@@ -214,7 +250,11 @@ const LocationSharingScreen = ({ navigation }: { navigation: any }) => {
|
|
Platform.OS === 'ios' ? Linking.openURL('app-settings:') : Linking.openSettings();
|
|
Platform.OS === 'ios' ? Linking.openURL('app-settings:') : Linking.openSettings();
|
|
}
|
|
}
|
|
}}
|
|
}}
|
|
- message="NomadMania app needs location permissions to function properly. Open settings?"
|
|
|
|
|
|
+ message={
|
|
|
|
+ openSettingsBackgroundVisible
|
|
|
|
+ ? "NomadMania app needs background location access to update your location automatically. Please select 'Always' in location permissions. Open settings?"
|
|
|
|
+ : 'NomadMania app needs location permissions to function properly. Open settings?'
|
|
|
|
+ }
|
|
/>
|
|
/>
|
|
</PageWrapper>
|
|
</PageWrapper>
|
|
);
|
|
);
|