Skip to content

Commit

Permalink
fix crash after marker drag
Browse files Browse the repository at this point in the history
This PR is fixing an issue of crashing after dragging a map marker. It is replicating the changes of the PR in the following link.

react-native-maps#2501
  • Loading branch information
marcopchen committed Jan 30, 2019
1 parent e076b91 commit 82ea575
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/ios/AirMaps/AIRMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ @interface AIRMapManager() <MKMapViewDelegate>

@end

@implementation AIRMapManager
@implementation AIRMapManager{
BOOL _hasObserver;
}

RCT_EXPORT_MODULE()

Expand Down Expand Up @@ -680,11 +682,12 @@ - (void)mapView:(AIRMap *)mapView
if (mapView.onMarkerDragEnd) mapView.onMarkerDragEnd(event);
if (marker.onDragEnd) marker.onDragEnd(event);

[view removeObserver:self forKeyPath:@"center"];
if(_hasObserver) [view removeObserver:self forKeyPath:@"center"];
_hasObserver = NO;
} else if (newState == MKAnnotationViewDragStateStarting) {
// MapKit doesn't emit continuous drag events. To get around this, we are going to use KVO.
[view addObserver:self forKeyPath:@"center" options:NSKeyValueObservingOptionNew context:&kDragCenterContext];

_hasObserver = YES;
if (mapView.onMarkerDragStart) mapView.onMarkerDragStart(event);
if (marker.onDragStart) marker.onDragStart(event);
}
Expand Down

0 comments on commit 82ea575

Please sign in to comment.