summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-04-16 23:20:27 -0400
committerJulian Rex <julian.rex@mapbox.com>2019-04-16 23:20:27 -0400
commit9663435e51f9098e20572fdc57d45025f893bd0e (patch)
tree6852951bf3056dd7ecee075b6a368fc49f777f52
parent425553646bc79286687f240da34144b44949c9f1 (diff)
downloadqtlocation-mapboxgl-9663435e51f9098e20572fdc57d45025f893bd0e.tar.gz
[ios] Consider anchored UIView callouts when deciding whether to enable presentsWithTransaction
-rw-r--r--platform/ios/src/MGLMapView.mm39
1 files changed, 28 insertions, 11 deletions
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 9a0fcd242a..cadf5be3fd 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -255,7 +255,7 @@ public:
@property (nonatomic) MGLAnnotationContainerView *annotationContainerView;
@property (nonatomic) MGLUserLocation *userLocation;
@property (nonatomic) NSMutableDictionary<NSString *, NSMutableArray<MGLAnnotationView *> *> *annotationViewReuseQueueByIdentifier;
-@property (nonatomic) BOOL enablePresentsWithTransaction;
+@property (nonatomic, readonly) BOOL enablePresentsWithTransaction;
@property (nonatomic) UIImage *lastSnapshotImage;
/// Experimental rendering performance measurement.
@@ -1286,19 +1286,17 @@ public:
[self updateDisplayLinkPreferredFramesPerSecond];
}
-- (void)setEnablePresentsWithTransaction:(BOOL)enablePresentsWithTransaction
+- (void)updatePresentsWithTransaction
{
- if (_enablePresentsWithTransaction == enablePresentsWithTransaction)
- {
- return;
- }
+ BOOL hasEnoughViewAnnotations = (self.annotationContainerView.annotationViews.count > MGLPresentsWithTransactionAnnotationCount);
+ BOOL hasAnAnchoredCallout = [self hasAnAnchoredAnnotationCalloutView];
- _enablePresentsWithTransaction = enablePresentsWithTransaction;
+ _enablePresentsWithTransaction = (hasEnoughViewAnnotations || hasAnAnchoredCallout);
// If the map is visible, change the layer property too
if (self.window) {
CAEAGLLayer *eaglLayer = MGL_OBJC_DYNAMIC_CAST(_glView.layer, CAEAGLLayer);
- eaglLayer.presentsWithTransaction = enablePresentsWithTransaction;
+ eaglLayer.presentsWithTransaction = _enablePresentsWithTransaction;
}
}
@@ -2349,6 +2347,10 @@ public:
{
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil);
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, calloutView);
+
+ [self updatePresentsWithTransaction];
+
+ // TODO: Add sibling disappear method
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
@@ -4339,7 +4341,7 @@ public:
[_glView insertSubview:newAnnotationContainerView atIndex:0];
self.annotationContainerView = newAnnotationContainerView;
- self.enablePresentsWithTransaction = (self.annotationContainerView.annotationViews.count > MGLPresentsWithTransactionAnnotationCount);
+ [self updatePresentsWithTransaction];
}
/// Initialize and return a default annotation image that depicts a round pin
@@ -4513,8 +4515,6 @@ public:
annotationView.annotation = nil;
[annotationView removeFromSuperview];
[self.annotationContainerView.annotationViews removeObject:annotationView];
-
- self.enablePresentsWithTransaction = (self.annotationContainerView.annotationViews.count > MGLPresentsWithTransactionAnnotationCount);
if (annotationTag == _selectedAnnotationTag)
{
@@ -4537,6 +4537,8 @@ public:
self.mbglMap.removeAnnotation(annotationTag);
}
+ [self updatePresentsWithTransaction];
+
[self didChangeValueForKey:@"annotations"];
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);
if (_isChangingAnnotationLayers)
@@ -5214,6 +5216,8 @@ public:
{
[self.delegate mapView:self didDeselectAnnotationView:annotationView];
}
+
+ [self updatePresentsWithTransaction];
}
}
@@ -6440,6 +6444,19 @@ public:
}
}
+- (BOOL)hasAnAnchoredAnnotationCalloutView
+{
+ // TODO: Remove duplicate code.
+ UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;
+ id <MGLAnnotation> annotation = calloutView.representedObject;
+
+ BOOL isAnchoredToAnnotation = (calloutView
+ && annotation
+ && [calloutView respondsToSelector:@selector(isAnchoredToAnnotation)]
+ && calloutView.isAnchoredToAnnotation);
+ return isAnchoredToAnnotation;
+}
+
- (void)updateCalloutView
{
UIView <MGLCalloutView> *calloutView = self.calloutViewForSelectedAnnotation;