Add MapView annotation callback when it gets / lost the focus

Summary:
For my project it was required to receive a notification when the MapView annotation was deselected.

So I renamed `onAnnotationPress` to `onAnnotationSelected` and added a new method `onAnnotationDeselected`, this names was "inspired" by the underlaying iOS API. The old API was still called and marked as deprecated.

But maybe you have an idea for a better naming (onAnnotationFocus/-Blur?) -- or should a deselected call the press method again without an annotation (undefined)?
Closes https://github.com/facebook/react-native/pull/5167

Reviewed By: svcscm

Differential Revision: D2869695

Pulled By: nicklockwood

fb-gh-sync-id: 91795ac3f1e4533b250af8901534d8870729d9db
This commit is contained in:
Christoph Jerolimov
2016-01-29 06:25:35 -08:00
committed by facebook-github-bot-4
parent 53100ecccb
commit cb874a55aa
4 changed files with 101 additions and 35 deletions

View File

@@ -97,6 +97,8 @@ RCT_EXPORT_VIEW_PROPERTY(mapType, MKMapType)
RCT_EXPORT_VIEW_PROPERTY(annotations, NSArray<RCTMapAnnotation *>)
RCT_EXPORT_VIEW_PROPERTY(overlays, NSArray<RCTMapOverlay *>)
RCT_EXPORT_VIEW_PROPERTY(onAnnotationDragStateChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onAnnotationFocus, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onAnnotationBlur, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap)
@@ -137,6 +139,7 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap)
- (void)mapView:(RCTMap *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
// TODO: Remove deprecated onAnnotationPress API call later.
if (mapView.onPress && [view.annotation isKindOfClass:[RCTMapAnnotation class]]) {
RCTMapAnnotation *annotation = (RCTMapAnnotation *)view.annotation;
mapView.onPress(@{
@@ -150,6 +153,27 @@ RCT_CUSTOM_VIEW_PROPERTY(region, MKCoordinateRegion, RCTMap)
}
});
}
if ([view.annotation isKindOfClass:[RCTMapAnnotation class]]) {
RCTMapAnnotation *annotation = (RCTMapAnnotation *)view.annotation;
if (mapView.onAnnotationFocus) {
mapView.onAnnotationFocus(@{
@"annotationId": annotation.identifier
});
}
}
}
- (void)mapView:(RCTMap *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
if ([view.annotation isKindOfClass:[RCTMapAnnotation class]]) {
RCTMapAnnotation *annotation = (RCTMapAnnotation *)view.annotation;
if (mapView.onAnnotationBlur) {
mapView.onAnnotationBlur(@{
@"annotationId": annotation.identifier
});
}
}
}
- (void)mapView:(RCTMap *)mapView annotationView:(MKAnnotationView *)view