Skip to content

Commit

Permalink
feat: improve UX of location permission requests
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouxm authored and paulschreiber committed Jul 11, 2024
1 parent 4134f81 commit 7c7f534
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 57 deletions.
9 changes: 9 additions & 0 deletions dev-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dev-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"expo-dev-client": "~4.0.19",
"expo-image-manipulator": "~12.0.5",
"expo-image-picker": "~15.0.7",
"expo-location": "~17.0.1",
"expo-media-library": "~16.0.4",
"expo-screen-orientation": "~7.0.5",
"expo-sensors": "~13.0.9",
Expand Down
9 changes: 0 additions & 9 deletions dev-client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import {APP_CONFIG} from 'terraso-mobile-client/config';
import {GeospatialProvider} from 'terraso-mobile-client/context/GeospatialContext';
import {HeaderHeightContext} from 'terraso-mobile-client/context/HeaderHeightContext';
import {HomeScreenContextProvider} from 'terraso-mobile-client/context/HomeScreenContext';
import {checkAndroidPermissions} from 'terraso-mobile-client/native/checkAndroidPermissions';
import {RootNavigator} from 'terraso-mobile-client/navigation/navigators/RootNavigator';
import {Toasts} from 'terraso-mobile-client/screens/Toasts';
import {createStore} from 'terraso-mobile-client/store';
Expand All @@ -75,14 +74,6 @@ LogBox.ignoreLogs([
const store = createStore();

function App(): React.JSX.Element {
useEffect(() =>
checkAndroidPermissions(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
),
);

const [headerHeight, setHeaderHeight] = useState(0);

return (
<GestureHandlerRootView style={style}>
<Provider store={store}>
Expand Down
40 changes: 0 additions & 40 deletions dev-client/src/native/checkAndroidPermissions.ts

This file was deleted.

10 changes: 10 additions & 0 deletions dev-client/src/screens/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import {
useState,
} from 'react';

import {useForegroundPermissions} from 'expo-location';

import BottomSheet, {BottomSheetModal} from '@gorhom/bottom-sheet';
import Mapbox from '@rnmapbox/maps';

Expand Down Expand Up @@ -58,6 +60,14 @@ import {ScreenScaffold} from 'terraso-mobile-client/screens/ScreenScaffold';
import {useDispatch, useSelector} from 'terraso-mobile-client/store';

export const HomeScreen = memo(() => {
const [locationPermission, requestLocationPermission] =
useForegroundPermissions();
useEffect(() => {
if (!locationPermission?.granted) {
requestLocationPermission();
}
}, []);

const infoBottomSheetRef = useRef<BottomSheetModal>(null);
const siteListBottomSheetRef = useRef<BottomSheet>(null);
const [mapStyleURL, setMapStyleURL] = useState(Mapbox.StyleURL.Street);
Expand Down
27 changes: 19 additions & 8 deletions dev-client/src/screens/HomeScreen/components/MapSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ import {Keyboard} from 'react-native';
import Autocomplete from 'react-native-autocomplete-input';
import {Searchbar} from 'react-native-paper';

import {useForegroundPermissions} from 'expo-location';

import {Pressable} from 'native-base';

import {Coords} from 'terraso-client-shared/types';

import {IconButton} from 'terraso-mobile-client/components/icons/IconButton';
import {searchBarStyles} from 'terraso-mobile-client/components/ListFilter';
import {PermissionsRequestModal} from 'terraso-mobile-client/components/modals/PermissionsRequestModal';
import {
Box,
Column,
Expand Down Expand Up @@ -211,14 +214,22 @@ export default function MapSearch({zoomTo, zoomToUser, toggleMapLayer}: Props) {
padding={2}
onPress={toggleMapLayer}
/>
<IconButton
name="my-location"
_icon={{color: 'action.active'}}
bgColor="white"
padding={2}
borderRadius={15}
onPress={zoomToUser}
/>
<PermissionsRequestModal
title={t('permissions.location_title')}
body={t('permissions.location_body')}
usePermissions={useForegroundPermissions}
permissionedAction={zoomToUser}>
{onRequest => (
<IconButton
name="my-location"
_icon={{color: 'action.active'}}
bgColor="white"
padding={2}
borderRadius={15}
onPress={onRequest}
/>
)}
</PermissionsRequestModal>
</Column>
</Row>
</Box>
Expand Down

0 comments on commit 7c7f534

Please sign in to comment.