diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMap.h b/lib/ios/AirGoogleMaps/AIRGoogleMap.h index c4f87eb85..3d6238fc4 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMap.h +++ b/lib/ios/AirGoogleMaps/AIRGoogleMap.h @@ -30,6 +30,7 @@ @property (nonatomic, copy) RCTBubblingEventBlock onKmlReady; @property (nonatomic, copy) RCTBubblingEventBlock onPress; @property (nonatomic, copy) RCTBubblingEventBlock onLongPress; +@property (nonatomic, copy) RCTBubblingEventBlock onPanDrag; @property (nonatomic, copy) RCTBubblingEventBlock onUserLocationChange; @property (nonatomic, copy) RCTBubblingEventBlock onMarkerPress; @property (nonatomic, copy) RCTBubblingEventBlock onChange; diff --git a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m index 4e0ff578c..752ac09dc 100644 --- a/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m +++ b/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m @@ -50,6 +50,16 @@ - (UIView *)view map.delegate = self; map.indoorDisplay.delegate = self; self.map = map; + map.settings.consumesGesturesInView = NO; + + UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapDrag:)]; + [drag setMinimumNumberOfTouches:1]; + [drag setMaximumNumberOfTouches:1]; + [map addGestureRecognizer:drag]; + + UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapDrag:)]; + [map addGestureRecognizer:pinch]; + return map; } @@ -77,6 +87,7 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(onKmlReady, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock) +RCT_EXPORT_VIEW_PROPERTY(onPanDrag, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onUserLocationChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) RCT_EXPORT_VIEW_PROPERTY(onMarkerPress, RCTDirectEventBlock) @@ -684,6 +695,28 @@ - (void)mapView:(GMSMapView *)mapView AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView; [googleMapView didTapPOIWithPlaceID:placeID name:name location:location]; } + +#pragma mark Gesture Recognizer Handlers + +- (void)handleMapDrag:(UIPanGestureRecognizer*)recognizer { + AIRGoogleMap *map = (AIRGoogleMap *)recognizer.view; + if (!map.onPanDrag) return; + + CGPoint touchPoint = [recognizer locationInView:map]; + CLLocationCoordinate2D coord = [map.projection coordinateForPoint:touchPoint]; + map.onPanDrag(@{ + @"coordinate": @{ + @"latitude": @(coord.latitude), + @"longitude": @(coord.longitude), + }, + @"position": @{ + @"x": @(touchPoint.x), + @"y": @(touchPoint.y), + }, + }); + +} + @end #endif