Skip to content

Commit 82ea575

Browse files
committed
fix crash after marker drag
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
1 parent e076b91 commit 82ea575

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/ios/AirMaps/AIRMapManager.m

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ @interface AIRMapManager() <MKMapViewDelegate>
3737

3838
@end
3939

40-
@implementation AIRMapManager
40+
@implementation AIRMapManager{
41+
BOOL _hasObserver;
42+
}
4143

4244
RCT_EXPORT_MODULE()
4345

@@ -680,11 +682,12 @@ - (void)mapView:(AIRMap *)mapView
680682
if (mapView.onMarkerDragEnd) mapView.onMarkerDragEnd(event);
681683
if (marker.onDragEnd) marker.onDragEnd(event);
682684

683-
[view removeObserver:self forKeyPath:@"center"];
685+
if(_hasObserver) [view removeObserver:self forKeyPath:@"center"];
686+
_hasObserver = NO;
684687
} else if (newState == MKAnnotationViewDragStateStarting) {
685688
// MapKit doesn't emit continuous drag events. To get around this, we are going to use KVO.
686689
[view addObserver:self forKeyPath:@"center" options:NSKeyValueObservingOptionNew context:&kDragCenterContext];
687-
690+
_hasObserver = YES;
688691
if (mapView.onMarkerDragStart) mapView.onMarkerDragStart(event);
689692
if (marker.onDragStart) marker.onDragStart(event);
690693
}

0 commit comments

Comments
 (0)