From 390a1af8ba8c5c7491e207d2289a4f24f78b341a Mon Sep 17 00:00:00 2001 From: Johan Chrillesen Date: Wed, 14 Feb 2024 09:04:40 -0500 Subject: [PATCH] Enable google maps on android (#44) * Enable google maps on android * Remove unused text import --- android/app/build.gradle | 11 ++++ android/app/src/main/AndroidManifest.xml | 7 ++- src/screens/home/MapView/MapView.tsx | 56 +++++++++---------- .../home/MapView/useMapViewController.tsx | 11 +--- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 7e6d8337f..5f4e9acf6 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -69,18 +69,29 @@ def enableProguardInReleaseBuilds = false */ def jscFlavor = 'org.webkit:android-jsc:+' + android { ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion compileSdk rootProject.ext.compileSdkVersion namespace "com.nolosay" + + def googleMapsApiKey = "" + try { + Properties properties = new Properties() + properties.load(project.rootProject.file('local.properties').newDataInputStream()) + googleMapsApiKey = properties.getProperty('GOOGLE_MAPS_API_KEY') + } catch (Exception e) { + println "Error reading GOOGLE_MAPS_API_KEY from local.properties: " + e.getMessage() + } defaultConfig { applicationId "com.nolosay" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 1 versionName "0.0.1" + manifestPlaceholders = [GOOGLE_MAPS_API_KEY: "\"${googleMapsApiKey}\""] } signingConfigs { debug { diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index e2116cd3e..8b9d7e7fc 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -16,7 +16,10 @@ + android:name="com.google.mlkit.vision.DEPENDENCIES" + android:value="barcode" /> + diff --git a/src/screens/home/MapView/MapView.tsx b/src/screens/home/MapView/MapView.tsx index 0eb39b2ac..49e40c641 100644 --- a/src/screens/home/MapView/MapView.tsx +++ b/src/screens/home/MapView/MapView.tsx @@ -8,8 +8,8 @@ */ import React from 'react' -import { StyleSheet, View, Text } from 'react-native' -import MapView, { Marker } from 'react-native-maps' +import { StyleSheet, View, Platform } from 'react-native' +import MapView, { Marker, PROVIDER_DEFAULT, PROVIDER_GOOGLE } from 'react-native-maps' import colors from '@global/colors' import images from '@global/images' import { Place } from '@global/types/Places' @@ -27,36 +27,34 @@ interface Props { * @returns {JSX.Element} */ export default function PlacesMapView({ places, navigation }: Props): JSX.Element { - const { account, onMarkerPress, mapRef, isMapAvailable } = useMapViewController({ navigation }) + const { account, onMarkerPress, mapRef } = useMapViewController({ navigation }) return ( - {isMapAvailable() && ( - - {places.map(marker => ( - onMarkerPress(marker)} - /> - ))} - - )} - {!isMapAvailable() && Pas encore fonctionnel} + + {places.map(marker => ( + onMarkerPress(marker)} + /> + ))} + ) } diff --git a/src/screens/home/MapView/useMapViewController.tsx b/src/screens/home/MapView/useMapViewController.tsx index 8d85e12f6..2c6eeac12 100644 --- a/src/screens/home/MapView/useMapViewController.tsx +++ b/src/screens/home/MapView/useMapViewController.tsx @@ -6,7 +6,7 @@ * @requires MapView react-native-maps */ import { Ref, useContext, useRef } from 'react' -import { Alert, Platform } from 'react-native' +import { Alert } from 'react-native' import MapView from 'react-native-maps' import { AccountContext } from '@global/contexts/AccountProvider' import { AccountType } from '@global/types/Account' @@ -16,7 +16,6 @@ interface MapViewController { account: AccountType mapRef: Ref onMarkerPress: (place: Place) => void - isMapAvailable: () => boolean } interface Props { @@ -71,17 +70,9 @@ export default function useMapViewController({ navigation }: Props): MapViewCont ]) } - /** - * @function isMapAvailable - * @description Checks if the map is available on the current platform. - * @returns {boolean} - */ - const isMapAvailable = (): boolean => Platform.OS === 'ios' || Platform.OS === 'macos' - return { account, mapRef, onMarkerPress, - isMapAvailable, } }