From 3d0ff69e40f0262e0ffc6f6023ec958b52eeb986 Mon Sep 17 00:00:00 2001 From: Quentin Valmori Date: Wed, 6 Jan 2016 11:00:15 -0800 Subject: [PATCH] Map follow user location Summary: Fix #3105 It's the same PR as #3119 but as I force-pushed in my branch, I can't reopen the PR. I added an example. ![capture d ecran 2016-01-05 a 07 15 37](https://cloud.githubusercontent.com/assets/1107936/12108841/2727f504-b37c-11e5-8250-b53785930aba.png) Closes https://github.com/facebook/react-native/pull/5126 Reviewed By: svcscm Differential Revision: D2803052 Pulled By: nicklockwood fb-gh-sync-id: 2e8978ff1b293d699462a8290b45fa74cc16b4dd --- Examples/UIExplorer/MapViewExample.js | 10 +++++++-- Libraries/Components/MapView/MapView.js | 27 +++++++++++++++++-------- React/Views/RCTMap.m | 4 ---- React/Views/RCTMapManager.m | 4 +--- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Examples/UIExplorer/MapViewExample.js b/Examples/UIExplorer/MapViewExample.js index 498a5f83d..bd1173a83 100644 --- a/Examples/UIExplorer/MapViewExample.js +++ b/Examples/UIExplorer/MapViewExample.js @@ -290,9 +290,15 @@ exports.examples = [ } }, { - title: 'Map shows user location', + title: 'showsUserLocation + followUserLocation', render() { - return ; + return ( + + ); } }, { diff --git a/Libraries/Components/MapView/MapView.js b/Libraries/Components/MapView/MapView.js index 2ccb4b8cb..ec2573303 100644 --- a/Libraries/Components/MapView/MapView.js +++ b/Libraries/Components/MapView/MapView.js @@ -49,15 +49,22 @@ const MapView = React.createClass({ style: View.propTypes.style, /** - * If `true` the app will ask for the user's location and focus on it. - * Default value is `false`. + * If `true` the app will ask for the user's location and display it on + * the map. Default value is `false`. * - * **NOTE**: You need to add NSLocationWhenInUseUsageDescription key in - * Info.plist to enable geolocation, otherwise it is going - * to *fail silently*! + * **NOTE**: on iOS, you need to add the `NSLocationWhenInUseUsageDescription` + * key in Info.plist to enable geolocation, otherwise it will fail silently. */ showsUserLocation: React.PropTypes.bool, + /** + * If `true` the map will follow the user's location whenever it changes. + * Note that this has no effect unless `showsUserLocation` is enabled. + * Default value is `true`. + * @platform ios + */ + followUserLocation: React.PropTypes.bool, + /** * If `false` points of interest won't be displayed on the map. * Default value is `true`. @@ -156,13 +163,11 @@ const MapView = React.createClass({ /** * Whether the pin should be draggable or not - * @platform ios */ draggable: React.PropTypes.bool, /** * Event that fires when the annotation drag state changes. - * @platform ios */ onDragStateChange: React.PropTypes.func, @@ -282,7 +287,7 @@ const MapView = React.createClass({ }, render: function() { - let children = [], {annotations, overlays} = this.props; + let children = [], {annotations, overlays, followUserLocation} = this.props; annotations = annotations && annotations.map((annotation: Object) => { let { id, @@ -430,11 +435,17 @@ const MapView = React.createClass({ }; } + // followUserLocation defaults to true if showUserLocation is set + if (followUserLocation === undefined) { + followUserLocation = this.props.showUserLocation; + } + return (