Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2949: Fix map user location with approximate permission #2987

Open
wants to merge 1 commit into
base: 2949-coarse-location-android
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions native/src/components/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ const MapView = ({
)

const onRequestLocation = useCallback(async () => {
if (userLocation) {
moveTo(userLocation)
const newUserLocation = userLocation ?? (await refreshPermissionAndLocation())?.coordinates
if (newUserLocation) {
moveTo(newUserLocation)
setFollowUserLocation(true)
}
await refreshPermissionAndLocation()
}, [refreshPermissionAndLocation, moveTo, userLocation])

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/base/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const StyledPressable = styled(Pressable)`
type IconButtonProps = {
accessibilityLabel: string
icon: ReactElement
onPress: () => Promise<void> | void
onPress: () => unknown
style?: StyleProp<ViewStyle>
}

Expand Down
29 changes: 17 additions & 12 deletions native/src/hooks/useUserLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type RequestPermissionAndLocationOptions = {
}

type UseUserLocationReturn = LocationStateType & {
refreshPermissionAndLocation: (options?: RequestPermissionAndLocationOptions) => Promise<void>
refreshPermissionAndLocation: (options?: RequestPermissionAndLocationOptions) => Promise<LocationStateType | null>
}

const initialState: LocationStateType = { status: 'loading', message: 'loading', coordinates: undefined }
Expand All @@ -69,7 +69,10 @@ const useUserLocation = ({ requestPermissionInitially }: UseUserLocationProps):
const { t } = useTranslation()

const refreshPermissionAndLocation = useCallback(
async ({ showSnackbarIfBlocked = true, requestPermission = true }: RequestPermissionAndLocationOptions = {}) => {
async ({
showSnackbarIfBlocked = true,
requestPermission = true,
}: RequestPermissionAndLocationOptions = {}): Promise<LocationStateType | null> => {
setLocationState(initialState)

const locationPermissionStatus = await getLocationPermissionStatus(requestPermission)
Expand All @@ -79,17 +82,19 @@ const useUserLocation = ({ requestPermissionInitially }: UseUserLocationProps):
}

if (locationPermissionStatus === RESULTS.GRANTED) {
setLocationState(await getUserLocation())
} else {
setLocationState({ message: 'noPermission', status: 'unavailable', coordinates: undefined })

if (requestPermission && showSnackbarIfBlocked && locationPermissionStatus === RESULTS.BLOCKED) {
showSnackbar({
text: t('landing:noPermission'),
positiveAction: { label: t('layout:settings'), onPress: openSettings },
})
}
const location = await getUserLocation()
setLocationState(location)
return location
}

setLocationState({ message: 'noPermission', status: 'unavailable', coordinates: undefined })
if (requestPermission && showSnackbarIfBlocked && locationPermissionStatus === RESULTS.BLOCKED) {
showSnackbar({
text: t('landing:noPermission'),
positiveAction: { label: t('layout:settings'), onPress: openSettings },
})
}
return null
},
[showSnackbar, t],
)
Expand Down
Loading