From 10e5ffe31b536ef6097070da00e05d9c8ab06878 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Mon, 25 May 2020 13:11:51 +0100 Subject: [PATCH 1/2] Avoid executing locateUser() on onDidFocus() when camera is already set --- app/screens/Explore.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/screens/Explore.js b/app/screens/Explore.js index a52606fda..553cec29c 100644 --- a/app/screens/Explore.js +++ b/app/screens/Explore.js @@ -182,6 +182,11 @@ class Explore extends React.Component { if (!requiresPreauth) { this.forceUpdate() + } + + // When camera is undefined, this is the first time this screen is shown and + // the camera should be set to the user location. + if (!this.state.camera) { this.locateUser() } } @@ -251,14 +256,15 @@ class Explore extends React.Component { try { const userLocation = await getUserLocation() if (userLocation.hasOwnProperty('coords')) { - const centerCoordinate = [userLocation.coords.longitude, userLocation.coords.latitude] - - this.cameraRef && this.cameraRef.setCamera({ - centerCoordinate, + // Create camera object from user location + const camera = { + centerCoordinate: [userLocation.coords.longitude, userLocation.coords.latitude], zoomLevel: 18 - }) + } - this.setState({ centerCoordinate }) + // Set map and component state + this.cameraRef && this.cameraRef.setCamera(camera) + this.setState({ camera }) } } catch (error) { console.log('error fetching user location', error) From 7f010d588ebadcad1884c67f8530a51c2be41d30 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Mon, 25 May 2020 15:07:24 +0100 Subject: [PATCH 2/2] Remove unused method --- app/screens/Explore.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/screens/Explore.js b/app/screens/Explore.js index 553cec29c..711752a6c 100644 --- a/app/screens/Explore.js +++ b/app/screens/Explore.js @@ -248,10 +248,6 @@ class Explore extends React.Component { } } - onUserLocationUpdate = location => { - // console.log('user location updated', location) - } - async locateUser () { try { const userLocation = await getUserLocation()