Skip to content

Commit 6c225af

Browse files
authored
Merge pull request #2746 from react-native-community/onPanDrag-ios
Adding onPanDrag compatibility for iOS
2 parents 209df3b + d837cb6 commit 6c225af

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

lib/ios/AirGoogleMaps/AIRGoogleMap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@property (nonatomic, copy) RCTBubblingEventBlock onKmlReady;
3131
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
3232
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;
33+
@property (nonatomic, copy) RCTBubblingEventBlock onPanDrag;
3334
@property (nonatomic, copy) RCTBubblingEventBlock onUserLocationChange;
3435
@property (nonatomic, copy) RCTBubblingEventBlock onMarkerPress;
3536
@property (nonatomic, copy) RCTBubblingEventBlock onChange;

lib/ios/AirGoogleMaps/AIRGoogleMapManager.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ - (UIView *)view
5050
map.delegate = self;
5151
map.indoorDisplay.delegate = self;
5252
self.map = map;
53+
map.settings.consumesGesturesInView = NO;
54+
55+
UIPanGestureRecognizer *drag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapDrag:)];
56+
[drag setMinimumNumberOfTouches:1];
57+
[drag setMaximumNumberOfTouches:1];
58+
[map addGestureRecognizer:drag];
59+
60+
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handleMapDrag:)];
61+
[map addGestureRecognizer:pinch];
62+
5363
return map;
5464
}
5565

@@ -77,6 +87,7 @@ - (UIView *)view
7787
RCT_EXPORT_VIEW_PROPERTY(onKmlReady, RCTBubblingEventBlock)
7888
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
7989
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
90+
RCT_EXPORT_VIEW_PROPERTY(onPanDrag, RCTBubblingEventBlock)
8091
RCT_EXPORT_VIEW_PROPERTY(onUserLocationChange, RCTBubblingEventBlock)
8192
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
8293
RCT_EXPORT_VIEW_PROPERTY(onMarkerPress, RCTDirectEventBlock)
@@ -684,6 +695,28 @@ - (void)mapView:(GMSMapView *)mapView
684695
AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView;
685696
[googleMapView didTapPOIWithPlaceID:placeID name:name location:location];
686697
}
698+
699+
#pragma mark Gesture Recognizer Handlers
700+
701+
- (void)handleMapDrag:(UIPanGestureRecognizer*)recognizer {
702+
AIRGoogleMap *map = (AIRGoogleMap *)recognizer.view;
703+
if (!map.onPanDrag) return;
704+
705+
CGPoint touchPoint = [recognizer locationInView:map];
706+
CLLocationCoordinate2D coord = [map.projection coordinateForPoint:touchPoint];
707+
map.onPanDrag(@{
708+
@"coordinate": @{
709+
@"latitude": @(coord.latitude),
710+
@"longitude": @(coord.longitude),
711+
},
712+
@"position": @{
713+
@"x": @(touchPoint.x),
714+
@"y": @(touchPoint.y),
715+
},
716+
});
717+
718+
}
719+
687720
@end
688721

689722
#endif

0 commit comments

Comments
 (0)