From 932af0e93be43df4cc4b2e21be399b342d991b4c Mon Sep 17 00:00:00 2001 From: Nicolas Burtey Date: Thu, 14 Mar 2024 18:40:38 -0600 Subject: [PATCH] chore: remove circular deps --- app/components/map-component/index.tsx | 2 +- app/screens/map-screen/functions.tsx | 33 ++++++++++++++++++++++++++ app/screens/map-screen/map-screen.tsx | 32 ++----------------------- 3 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 app/screens/map-screen/functions.tsx diff --git a/app/components/map-component/index.tsx b/app/components/map-component/index.tsx index 831a750e2b..170d45fc7a 100644 --- a/app/components/map-component/index.tsx +++ b/app/components/map-component/index.tsx @@ -7,7 +7,7 @@ import { PermissionStatus, RESULTS, request } from "react-native-permissions" import { useApolloClient } from "@apollo/client" import { updateMapLastCoords } from "@app/graphql/client-only-query" import { BusinessMapMarkersQuery, MapMarker } from "@app/graphql/generated" -import { LOCATION_PERMISSION, getUserRegion } from "@app/screens/map-screen/map-screen" +import { LOCATION_PERMISSION, getUserRegion } from "@app/screens/map-screen/functions" import { isIOS } from "@rneui/base" import { makeStyles, useTheme } from "@rneui/themed" diff --git a/app/screens/map-screen/functions.tsx b/app/screens/map-screen/functions.tsx new file mode 100644 index 0000000000..88048a3984 --- /dev/null +++ b/app/screens/map-screen/functions.tsx @@ -0,0 +1,33 @@ +import { Region } from "react-native-maps" +import { PERMISSIONS } from "react-native-permissions" + +import { isIos } from "@app/utils/helper" +import Geolocation from "@react-native-community/geolocation" + +export const LOCATION_PERMISSION = isIos + ? PERMISSIONS.IOS.LOCATION_WHEN_IN_USE + : PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION + +export const getUserRegion = (callback: (region?: Region) => void) => { + try { + Geolocation.getCurrentPosition( + (data: GeolocationPosition) => { + if (data) { + const region: Region = { + latitude: data.coords.latitude, + longitude: data.coords.longitude, + latitudeDelta: 0.02, + longitudeDelta: 0.02, + } + callback(region) + } + }, + () => { + callback(undefined) + }, + { timeout: 5000 }, + ) + } catch (e) { + callback(undefined) + } +} diff --git a/app/screens/map-screen/map-screen.tsx b/app/screens/map-screen/map-screen.tsx index 1e90f9b74a..7dee312814 100644 --- a/app/screens/map-screen/map-screen.tsx +++ b/app/screens/map-screen/map-screen.tsx @@ -3,7 +3,7 @@ import * as React from "react" // eslint-disable-next-line react-native/split-platform-components import { Alert, Dimensions } from "react-native" import { Region, MapMarker as MapMarkerType } from "react-native-maps" -import { check, PERMISSIONS, PermissionStatus, RESULTS } from "react-native-permissions" +import { check, PermissionStatus, RESULTS } from "react-native-permissions" import { gql } from "@apollo/client" import MapComponent from "@app/components/map-component" @@ -15,7 +15,6 @@ import { import { useIsAuthed } from "@app/graphql/is-authed-context" import useDeviceLocation from "@app/hooks/use-device-location" import { useI18nContext } from "@app/i18n/i18n-react" -import { isIos } from "@app/utils/helper" import Geolocation from "@react-native-community/geolocation" import { useFocusEffect } from "@react-navigation/native" import { StackNavigationProp } from "@react-navigation/stack" @@ -25,6 +24,7 @@ import { Screen } from "../../components/screen" import { RootStackParamList } from "../../navigation/stack-param-lists" import { toastShow } from "../../utils/toast" import { PhoneLoginInitiateType } from "../phone-auth-screen" +import { LOCATION_PERMISSION, getUserRegion } from "./functions" const EL_ZONTE_COORDS = { latitude: 13.496743, @@ -33,10 +33,6 @@ const EL_ZONTE_COORDS = { longitudeDelta: 0.02, } -export const LOCATION_PERMISSION = isIos - ? PERMISSIONS.IOS.LOCATION_WHEN_IN_USE - : PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION - // essentially calculates zoom for location being set based on country const { height, width } = Dimensions.get("window") const LATITUDE_DELTA = 15 // <-- decrease for more zoom @@ -53,30 +49,6 @@ Geolocation.setRNConfiguration({ locationProvider: "auto", }) -export const getUserRegion = (callback: (region?: Region) => void) => { - try { - Geolocation.getCurrentPosition( - (data: GeolocationPosition) => { - if (data) { - const region: Region = { - latitude: data.coords.latitude, - longitude: data.coords.longitude, - latitudeDelta: 0.02, - longitudeDelta: 0.02, - } - callback(region) - } - }, - () => { - callback(undefined) - }, - { timeout: 5000 }, - ) - } catch (e) { - callback(undefined) - } -} - gql` query businessMapMarkers { businessMapMarkers {