Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Deprecate methods in favor of new completion handler versions #14959

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
* `-[MGLMapView setTargetCoordinate:animated:completionHandler:]`
* `-[MGLMapView showAnnotations:edgePadding:animated:completionHandler:]`
* `-[MGLMapView selectAnnotation:animated:completionHandler:]`
* Deprecated variants of the above methods without completion handlers. ([#14959](https://github.com/mapbox/mapbox-gl-native/pull/14959))

## 5.1.0 - June 19, 2019

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,20 @@ - (void)testUserLocationWithOffsetAnchorPoint {
MGLTestLocationManager *locationManager = [[MGLTestLocationManager alloc] init];
self.mapView.locationManager = locationManager;

[self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:NO];
[self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:NO completionHandler:nil];
CGRect originalFrame = [self.mapView viewForAnnotation:self.mapView.userLocation].frame;

// Temporarily disable location tracking so we can save the value of
// the originalFrame in memory
[self.mapView setUserTrackingMode:MGLUserTrackingModeNone animated:NO];
[self.mapView setUserTrackingMode:MGLUserTrackingModeNone animated:NO completionHandler:nil];

CGPoint offset = CGPointMake(20, 20);

self.mapViewUserLocationAnchorPoint = ^CGPoint (MGLMapView *mapView) {
return offset;;
};

[self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:NO];
[self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:NO completionHandler:nil];
CGRect offsetFrame = [self.mapView viewForAnnotation:self.mapView.userLocation].frame;

XCTAssertEqual(originalFrame.origin.x + offset.x, offsetFrame.origin.x);
Expand Down
8 changes: 4 additions & 4 deletions platform/ios/app/MBXViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,14 @@ - (void)performActionForSettingAtIndexPath:(NSIndexPath *)indexPath
heading:0];
__weak typeof(self) weakSelf = self;
[self.mapView setCamera:camera withDuration:0.3 animationTimingFunction:nil completionHandler:^{
[weakSelf.mapView setContentInset:contentInsets animated:YES];
[weakSelf.mapView setContentInset:contentInsets animated:YES completionHandler:nil];
}];
} else {
[self.view sendSubviewToBack:self.contentInsetsOverlays[0]];
[self.view sendSubviewToBack:self.contentInsetsOverlays[1]];
[self.view sendSubviewToBack:self.contentInsetsOverlays[2]];
[self.view sendSubviewToBack:self.contentInsetsOverlays[3]];
[self.mapView setContentInset:_originalContentInsets animated:YES];
[self.mapView setContentInset:_originalContentInsets animated:YES completionHandler:nil];
}
break;
}
Expand Down Expand Up @@ -1686,7 +1686,7 @@ - (void)testQueryPointAnnotations {
- (void)selectAnOffscreenPointAnnotation {
id<MGLAnnotation> annotation = [self randomOffscreenPointAnnotation];
if (annotation) {
[self.mapView selectAnnotation:annotation animated:YES];
[self.mapView selectAnnotation:annotation animated:YES completionHandler:nil];

NSAssert(self.mapView.selectedAnnotations.firstObject, @"The annotation was not selected");
}
Expand Down Expand Up @@ -1946,7 +1946,7 @@ - (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress
// positioning rect)

[self.mapView addAnnotation:pin];
[self.mapView selectAnnotation:pin animated:YES];
[self.mapView selectAnnotation:pin animated:YES completionHandler:nil];
}
}

Expand Down
38 changes: 19 additions & 19 deletions platform/ios/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ MGL_EXPORT
@property (nonatomic, assign) MGLUserTrackingMode userTrackingMode;

/**
Sets the mode used to track the user location, with an optional transition.
Deprecated. Sets the mode used to track the user location, with an optional transition.

To specify a completion handler to execute after the animation finishes, use
the `-setUserTrackingMode:animated:completionHandler:` method.
Expand All @@ -515,7 +515,7 @@ MGL_EXPORT
affects the initial transition; subsequent changes to the user location or
heading are always animated.
*/
- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated;
- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated __attribute__((deprecated("Use `-setUserTrackingMode:animated:completionHandler:` instead.")));

/**
Sets the mode used to track the user location, with an optional transition and
Expand Down Expand Up @@ -609,8 +609,8 @@ MGL_EXPORT
@property (nonatomic, assign) CLLocationCoordinate2D targetCoordinate;

/**
Sets the geographic coordinate that is the subject of observation as the user
location is being tracked, with an optional transition animation.
Deprecated. Sets the geographic coordinate that is the subject of observation as
the user location is being tracked, with an optional transition animation.

By default, the target coordinate is set to an invalid coordinate, indicating
that there is no target. In course tracking mode, the target forms one of two
Expand All @@ -629,7 +629,7 @@ MGL_EXPORT
@param animated If `YES`, the map animates to fit the target within the map
view. If `NO`, the map fits the target instantaneously.
*/
- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated;
- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated __attribute__((deprecated("Use `-setTargetCoordinate:animated:completionHandler:` instead.")));

/**
Sets the geographic coordinate that is the subject of observation as the user
Expand Down Expand Up @@ -934,8 +934,8 @@ MGL_EXPORT
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated;

/**
Changes the receiver’s viewport to fit the given coordinate bounds with some
additional padding on each side.
Deprecated. Changes the receiver’s viewport to fit the given coordinate bounds with
some additional padding on each side.

To bring both sides of the antimeridian or international date line into view,
specify some longitudes less than −180 degrees or greater than 180 degrees. For
Expand All @@ -951,7 +951,7 @@ MGL_EXPORT
@param animated Specify `YES` to animate the change by smoothly scrolling and
zooming or `NO` to immediately display the given bounds.
*/
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated __attribute__((deprecated("Use `-setVisibleCoordinateBounds:edgePadding:animated:completionHandler:` instead.")));

/**
Changes the receiver’s viewport to fit the given coordinate bounds with some
Expand Down Expand Up @@ -1028,8 +1028,8 @@ MGL_EXPORT
- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations animated:(BOOL)animated;

/**
Sets the visible region so that the map displays the specified annotations with
the specified amount of padding on each side.
Deprecated. Sets the visible region so that the map displays the specified
annotations with the specified amount of padding on each side.

Calling this method updates the value in the `visibleCoordinateBounds` property
and potentially other properties to reflect the new map region.
Expand All @@ -1043,7 +1043,7 @@ MGL_EXPORT
@param animated `YES` if you want the map region change to be animated, or `NO`
if you want the map to display the new region immediately without animations.
*/
- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated;
- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated __attribute__((deprecated("Use `-showAnnotations:edgePadding:animated:completionHandler:` instead.")));

/**
Sets the visible region so that the map displays the specified annotations with
Expand Down Expand Up @@ -1316,8 +1316,8 @@ MGL_EXPORT
@property (nonatomic, assign) UIEdgeInsets contentInset;

/**
Sets the distance from the edges of the map view’s frame to the edges of the
map view’s logical viewport with an optional transition animation.
Deprecated. Sets the distance from the edges of the map view’s frame to the edges
of the map view’s logical viewport with an optional transition animation.

When the value of this property is equal to `UIEdgeInsetsZero`, viewport
properties such as `centerCoordinate` assume a viewport that matches the map
Expand All @@ -1337,7 +1337,7 @@ MGL_EXPORT
the content inset or `NO` if you want the map to inset the content
immediately.
*/
- (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated;
- (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated __attribute__((deprecated("Use `-setContentInset:animated:completionHandler:` instead.")));

/**
Sets the distance from the edges of the map view’s frame to the edges of the
Expand Down Expand Up @@ -1443,7 +1443,7 @@ MGL_EXPORT
*/
- (CLLocationDistance)metersPerPointAtLatitude:(CLLocationDegrees)latitude;

- (CLLocationDistance)metersPerPixelAtLatitude:(CLLocationDegrees)latitude __attribute__((unavailable("Use -metersPerPointAtLatitude:.")));
- (CLLocationDistance)metersPerPixelAtLatitude:(CLLocationDegrees)latitude __attribute__((unavailable("Use `-metersPerPointAtLatitude:`.")));

#pragma mark Annotating the Map

Expand Down Expand Up @@ -1601,7 +1601,7 @@ MGL_EXPORT
@property (nonatomic, copy) NSArray<id <MGLAnnotation>> *selectedAnnotations;

/**
Selects an annotation and displays its callout view.
Deprecated. Selects an annotation and displays its callout view.

The `animated` parameter determines whether the selection is animated including whether the map is
panned to bring the annotation into view, specifically:
Expand All @@ -1622,7 +1622,7 @@ MGL_EXPORT
@note In versions prior to `4.0.0` selecting an offscreen annotation did not
change the camera.
*/
- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated;
- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated __attribute__((deprecated("Use `-selectAnnotation:animated:completionHandler:` instead.")));

/**
Selects an annotation and displays its callout view with an optional completion
Expand Down Expand Up @@ -1941,9 +1941,9 @@ MGL_EXPORT
*/
@property (nonatomic) MGLMapDebugMaskOptions debugMask;

@property (nonatomic, getter=isDebugActive) BOOL debugActive __attribute__((unavailable("Use -debugMask and -setDebugMask:.")));
@property (nonatomic, getter=isDebugActive) BOOL debugActive __attribute__((unavailable("Use `-debugMask` and `-setDebugMask:`.")));

- (void)toggleDebug __attribute__((unavailable("Use -setDebugMask:.")));
- (void)toggleDebug __attribute__((unavailable("Use `-setDebugMask:`.")));
friedbunny marked this conversation as resolved.
Show resolved Hide resolved

- (void)emptyMemoryCache __attribute__((unavailable));

Expand Down
23 changes: 8 additions & 15 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,7 @@ - (void)adjustContentInset

- (void)setContentInset:(UIEdgeInsets)contentInset
{
MGLLogDebug(@"Setting contentInset: %@", NSStringFromUIEdgeInsets(contentInset));
[self setContentInset:contentInset animated:NO];
[self setContentInset:contentInset animated:NO completionHandler:nil];
}

- (void)setContentInset:(UIEdgeInsets)contentInset animated:(BOOL)animated
Expand Down Expand Up @@ -1546,7 +1545,7 @@ - (void)touchesBegan:(__unused NSSet<UITouch *> *)touches withEvent:(__unused UI
self.mbglMap.setGestureInProgress(false);
if (self.userTrackingState == MGLUserTrackingStateBegan)
{
[self setUserTrackingMode:MGLUserTrackingModeNone animated:NO];
[self setUserTrackingMode:MGLUserTrackingModeNone animated:NO completionHandler:nil];
}

[self cancelTransitions];
Expand Down Expand Up @@ -3327,14 +3326,12 @@ - (MGLCoordinateBounds)visibleCoordinateBounds

- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds
{
MGLLogDebug(@"Setting visibleCoordinateBounds: %@", MGLStringFromCoordinateBounds(bounds));
[self setVisibleCoordinateBounds:bounds animated:NO];
}

- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds animated:(BOOL)animated
{
MGLLogDebug(@"Setting visibleCoordinateBounds: %@ animated: %@", MGLStringFromCoordinateBounds(bounds), MGLStringFromBOOL(animated));
[self setVisibleCoordinateBounds:bounds edgePadding:UIEdgeInsetsZero animated:animated];
[self setVisibleCoordinateBounds:bounds edgePadding:UIEdgeInsetsZero animated:animated completionHandler:nil];
}

- (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated
Expand Down Expand Up @@ -4671,7 +4668,6 @@ - (void)setSelectedAnnotation:(id <MGLAnnotation>)annotation

- (void)setSelectedAnnotations:(NSArray<id <MGLAnnotation>> *)selectedAnnotations
{
MGLLogDebug(@"Selecting: %lu annotations", selectedAnnotations.count);
if ( ! selectedAnnotations.count) return;

id <MGLAnnotation> firstAnnotation = selectedAnnotations[0];
Expand All @@ -4680,7 +4676,7 @@ - (void)setSelectedAnnotations:(NSArray<id <MGLAnnotation>> *)selectedAnnotation

if ([firstAnnotation isKindOfClass:[MGLMultiPoint class]]) return;

[self selectAnnotation:firstAnnotation animated:YES];
[self selectAnnotation:firstAnnotation animated:YES completionHandler:nil];
}

- (void)selectAnnotation:(id <MGLAnnotation>)annotation animated:(BOOL)animated
Expand Down Expand Up @@ -5100,14 +5096,13 @@ - (void)calloutViewWillAppear:(UIView <MGLCalloutView> *)calloutView

- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations animated:(BOOL)animated
{
MGLLogDebug(@"Showing: %lu annotations animated: %@", annotations.count, MGLStringFromBOOL(animated));
CGFloat maximumPadding = 100;
CGFloat yPadding = (self.frame.size.height / 5 <= maximumPadding) ? (self.frame.size.height / 5) : maximumPadding;
CGFloat xPadding = (self.frame.size.width / 5 <= maximumPadding) ? (self.frame.size.width / 5) : maximumPadding;

UIEdgeInsets edgeInsets = UIEdgeInsetsMake(yPadding, xPadding, yPadding, xPadding);

[self showAnnotations:annotations edgePadding:edgeInsets animated:animated];
[self showAnnotations:annotations edgePadding:edgeInsets animated:animated completionHandler:nil];
}

- (void)showAnnotations:(NSArray<id <MGLAnnotation>> *)annotations edgePadding:(UIEdgeInsets)insets animated:(BOOL)animated
Expand Down Expand Up @@ -5306,7 +5301,7 @@ - (void)setShowsUserLocation:(BOOL)showsUserLocation
[self.delegate mapViewDidStopLocatingUser:self];
}

[self setUserTrackingMode:MGLUserTrackingModeNone animated:YES];
[self setUserTrackingMode:MGLUserTrackingModeNone animated:YES completionHandler:nil];

[self.userLocationAnnotationView removeFromSuperview];
self.userLocationAnnotationView = nil;
Expand Down Expand Up @@ -5346,8 +5341,7 @@ - (BOOL)isUserLocationVisible

- (void)setUserTrackingMode:(MGLUserTrackingMode)mode
{
MGLLogDebug(@"Setting userTrackingMode: %lu", mode);
[self setUserTrackingMode:mode animated:YES];
[self setUserTrackingMode:mode animated:YES completionHandler:nil];
}

- (void)setUserTrackingMode:(MGLUserTrackingMode)mode animated:(BOOL)animated
Expand Down Expand Up @@ -5448,8 +5442,7 @@ - (void)setUserLocationVerticalAlignment:(MGLAnnotationVerticalAlignment)alignme

- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate
{
MGLLogDebug(@"Setting targetCoordinate: %@", MGLStringFromCLLocationCoordinate2D(targetCoordinate));
[self setTargetCoordinate:targetCoordinate animated:YES];
[self setTargetCoordinate:targetCoordinate animated:YES completionHandler:nil];
}

- (void)setTargetCoordinate:(CLLocationCoordinate2D)targetCoordinate animated:(BOOL)animated
Expand Down
6 changes: 3 additions & 3 deletions platform/ios/test/MGLAnnotationViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ - (void)testSelectingOffscreenAnnotation
XCTAssertNil(_mapView.selectedAnnotations.firstObject, @"There should be no selected annotation");

// First selection
[_mapView selectAnnotation:annotation animated:NO];
[_mapView selectAnnotation:annotation animated:NO completionHandler:nil];
selectionCount++;

XCTAssert(_mapView.selectedAnnotations.count == 1, @"There should only be 1 selected annotation");
Expand Down Expand Up @@ -190,7 +190,7 @@ - (void)testSelectingOnscreenAnnotationThatHasNotBeenAdded {
XCTAssert(MGLCoordinateInCoordinateBounds(point.coordinate, coordinateBounds), @"The test point should be within the visible map view");

// Select on screen annotation (DO NOT ADD FIRST).
[self.mapView selectAnnotation:point animated:YES];
[self.mapView selectAnnotation:point animated:YES completionHandler:nil];

// Expect - the camera NOT to move.
MGLCameraChangeReason reasonAfter = self.mapView.cameraChangeReasonBitmask;
Expand Down Expand Up @@ -235,7 +235,7 @@ - (void)testSelectingADisabledAnnotationViewPENDING {

XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations");

[self.mapView selectAnnotation:point animated:NO];
[self.mapView selectAnnotation:point animated:NO completionHandler:nil];

XCTAssert(self.mapView.selectedAnnotations.count == 0, @"There should be 0 selected annotations");
}
Expand Down
6 changes: 3 additions & 3 deletions platform/macos/src/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ MGL_EXPORT IB_DESIGNABLE
@property (nonatomic, assign) NSEdgeInsets contentInsets;

/**
Sets the distance from the edges of the map view’s frame to the edges of the
map view’s logical viewport, with an optional transition animation.
Deprecated. Sets the distance from the edges of the map view’s frame to the
edges of the map view’s logical viewport, with an optional transition animation.

When the value of this property is equal to `NSEdgeInsetsZero`, viewport
properties such as `centerCoordinate` assume a viewport that matches the map
Expand All @@ -646,7 +646,7 @@ MGL_EXPORT IB_DESIGNABLE
the content insets or `NO` if you want the map to inset the content
immediately.
*/
- (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated;
- (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated __attribute__((deprecated("Use `-setContentInsets:animated:completionHandler:` instead.")));

/**
Sets the distance from the edges of the map view’s frame to the edges of the
Expand Down
3 changes: 1 addition & 2 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,7 @@ - (void)adjustContentInsets {
}

- (void)setContentInsets:(NSEdgeInsets)contentInsets {
MGLLogDebug(@"Setting contentInset: %@", MGLStringFromNSEdgeInsets(contentInsets));
[self setContentInsets:contentInsets animated:NO];
[self setContentInsets:contentInsets animated:NO completionHandler:nil];
}

- (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated {
Expand Down