Skip to content

Commit 993a928

Browse files
nathanajahFacebook Github Bot 1
authored and
Facebook Github Bot 1
committed
Fixed MapView's draggable annotation
Reviewed By: javache Differential Revision: D3384947 fbshipit-source-id: 801a0998c8db788a731d27ae5956193ff23aa198
1 parent 4959b21 commit 993a928

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

Examples/UIExplorer/MapViewExample.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,56 @@ var AnnotationExample = React.createClass({
252252

253253
});
254254

255+
var DraggableAnnotationExample = React.createClass({
256+
257+
createAnnotation(longitude, latitude) {
258+
return {
259+
longitude,
260+
latitude,
261+
draggable: true,
262+
onDragStateChange: (event) => {
263+
if (event.state === 'idle') {
264+
this.setState({
265+
annotations: [this.createAnnotation(event.longitude, event.latitude)],
266+
});
267+
}
268+
console.log('Drag state: ' + event.state);
269+
},
270+
};
271+
},
272+
273+
getInitialState() {
274+
return {
275+
isFirstLoad: true,
276+
annotations: [],
277+
mapRegion: undefined,
278+
};
279+
},
280+
281+
render() {
282+
if (this.state.isFirstLoad) {
283+
var onRegionChangeComplete = (region) => {
284+
//When the MapView loads for the first time, we can create the annotation at the
285+
//region that was loaded.
286+
this.setState({
287+
isFirstLoad: false,
288+
annotations: [this.createAnnotation(region.longitude, region.latitude)],
289+
});
290+
};
291+
}
292+
293+
return (
294+
<MapView
295+
style={styles.map}
296+
onRegionChangeComplete={onRegionChangeComplete}
297+
region={this.state.mapRegion}
298+
annotations={this.state.annotations}
299+
/>
300+
);
301+
},
302+
303+
});
304+
255305
var styles = StyleSheet.create({
256306
map: {
257307
height: 150,
@@ -338,12 +388,7 @@ exports.examples = [
338388
{
339389
title: 'Draggable pin',
340390
render() {
341-
return <AnnotationExample style={styles.map} annotation={{
342-
draggable: true,
343-
onDragStateChange: (event) => {
344-
console.log('Drag state: ' + event.state);
345-
},
346-
}}/>;
391+
return <DraggableAnnotationExample/>;
347392
}
348393
},
349394
{

Libraries/Components/MapView/MapView.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,6 @@ const MapView = React.createClass({
437437
onAnnotationDragStateChange = (event: Event) => {
438438
const annotation = findByAnnotationId(event.nativeEvent.annotationId);
439439
if (annotation) {
440-
// Update location
441-
annotation.latitude = event.nativeEvent.latitude;
442-
annotation.longitude = event.nativeEvent.longitude;
443440
// Call callback
444441
annotation.onDragStateChange &&
445442
annotation.onDragStateChange(event.nativeEvent);

0 commit comments

Comments
 (0)