Skip to content

Commit

Permalink
Add default arguments to fitToCoordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
naoufal committed Sep 22, 2016
1 parent d63e849 commit 3647602
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 5 additions & 1 deletion components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ class MapView extends React.Component {
this._runCommand('fitToSuppliedMarkers', [markers, animated]);
}

fitToCoordinates(coordinates, edgePadding, animated) {
fitToCoordinates(
coordinates = [],
edgePadding = { top: 0, right: 0, bottom: 0, left: 0 },
animated = true
) {
this._runCommand('fitToCoordinates', [coordinates, edgePadding, animated]);
}

Expand Down
20 changes: 8 additions & 12 deletions ios/AirMaps/AIRMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ - (UIView *)view

RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
coordinates:(nonnull NSArray<AIRMapCoordinate *> *)coordinates
edgePadding:(NSDictionary *)edgePadding
animated:(BOOL)animated)
edgePadding:(nonnull NSDictionary *)edgePadding
animated:(nonnull BOOL)animated)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
Expand All @@ -208,16 +208,12 @@ - (UIView *)view
MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];

// Set Map viewport
if (!edgePadding) {
[mapView setVisibleMapRect:[polyline boundingMapRect] animated:animated];
} else {
CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];

[mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:animated];
}
CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];

[mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:animated];

}
}];
Expand Down

0 comments on commit 3647602

Please sign in to comment.