Skip to content

Commit

Permalink
Fixed MapView's draggable annotation
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D3384947

fbshipit-source-id: 801a0998c8db788a731d27ae5956193ff23aa198
  • Loading branch information
nathanajah authored and bubblesunyum committed Aug 23, 2016
1 parent 8735309 commit ee903ce
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
57 changes: 51 additions & 6 deletions Examples/UIExplorer/MapViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,56 @@ var AnnotationExample = React.createClass({

});

var DraggableAnnotationExample = React.createClass({

createAnnotation(longitude, latitude) {
return {
longitude,
latitude,
draggable: true,
onDragStateChange: (event) => {
if (event.state === 'idle') {
this.setState({
annotations: [this.createAnnotation(event.longitude, event.latitude)],
});
}
console.log('Drag state: ' + event.state);
},
};
},

getInitialState() {
return {
isFirstLoad: true,
annotations: [],
mapRegion: undefined,
};
},

render() {
if (this.state.isFirstLoad) {
var onRegionChangeComplete = (region) => {
//When the MapView loads for the first time, we can create the annotation at the
//region that was loaded.
this.setState({
isFirstLoad: false,
annotations: [this.createAnnotation(region.longitude, region.latitude)],
});
};
}

return (
<MapView
style={styles.map}
onRegionChangeComplete={onRegionChangeComplete}
region={this.state.mapRegion}
annotations={this.state.annotations}
/>
);
},

});

var styles = StyleSheet.create({
map: {
height: 150,
Expand Down Expand Up @@ -338,12 +388,7 @@ exports.examples = [
{
title: 'Draggable pin',
render() {
return <AnnotationExample style={styles.map} annotation={{
draggable: true,
onDragStateChange: (event) => {
console.log('Drag state: ' + event.state);
},
}}/>;
return <DraggableAnnotationExample/>;
}
},
{
Expand Down
3 changes: 0 additions & 3 deletions Libraries/Components/MapView/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,6 @@ const MapView = React.createClass({
onAnnotationDragStateChange = (event: Event) => {
const annotation = findByAnnotationId(event.nativeEvent.annotationId);
if (annotation) {
// Update location
annotation.latitude = event.nativeEvent.latitude;
annotation.longitude = event.nativeEvent.longitude;
// Call callback
annotation.onDragStateChange &&
annotation.onDragStateChange(event.nativeEvent);
Expand Down

0 comments on commit ee903ce

Please sign in to comment.