[ios] Consider anchored UIView callouts when deciding whether to enable presentsWithTransaction (#14445)

This commit is contained in:
Julian Rex
2019-04-17 15:06:46 -04:00
committed by GitHub
parent 38a4caa3f4
commit dfb88e3541
2 changed files with 29 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* Fix a bug that wrong position of attribution dialog after rotation. ([#14185](https://github.com/mapbox/mapbox-gl-native/pull/14185))
* Fixed a bug where non-opaque `UIColor` values were ignored when assigned to a style layer color property. ([#14406](https://github.com/mapbox/mapbox-gl-native/pull/14406))
* Speculatively fixed a bug where GL rendering could occur in the background. ([#14439](https://github.com/mapbox/mapbox-gl-native/pull/14439))
* Fixed a bug with jittery callout views when using sprite-based annotations. ([#14445](https://github.com/mapbox/mapbox-gl-native/pull/14445))
## 4.10.0

View File

@@ -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;