Skip to content

Commit

Permalink
Add mapPadding property (#1750)
Browse files Browse the repository at this point in the history
* Add mapPadding property

* Fix trailing whitespace in MapView comments
  • Loading branch information
peterjuras authored and christopherdro committed Nov 28, 2017
1 parent 94be5dc commit bf40f06
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ public void setMapStyle(AirMapView view, @Nullable String customMapStyleString)
view.map.setMapStyle(new MapStyleOptions(customMapStyleString));
}

@ReactProp(name = "mapPadding")
public void setMapPadding(AirMapView view, @Nullable ReadableMap padding) {
int left = 0;
int top = 0;
int right = 0;
int bottom = 0;
double density = (double) view.getResources().getDisplayMetrics().density;

if (padding != null) {
if (padding.hasKey("left")) {
left = (int) (padding.getDouble("left") * density);
}

if (padding.hasKey("top")) {
top = (int) (padding.getDouble("top") * density);
}

if (padding.hasKey("right")) {
right = (int) (padding.getDouble("right") * density);
}

if (padding.hasKey("bottom")) {
bottom = (int) (padding.getDouble("bottom") * density);
}
}

view.map.setPadding(left, top, right, bottom);
}

@ReactProp(name = "showsUserLocation", defaultBoolean = false)
public void setShowsUserLocation(AirMapView view, boolean showUserLocation) {
view.setShowsUserLocation(showUserLocation);
Expand Down
9 changes: 9 additions & 0 deletions lib/components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ const propTypes = {
*/
liteMode: PropTypes.bool,

/**
* (Google Maps only)
*
* Padding that is used by the Google Map View to position
* the camera, legal labels and buttons
*
*/
mapPadding: EdgeInsetsPropType,

/**
* Maximum size of area that can be displayed.
*
Expand Down
1 change: 1 addition & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@property (nonatomic, assign) MKCoordinateRegion initialRegion;
@property (nonatomic, assign) MKCoordinateRegion region;
@property (nonatomic, assign) NSString *customMapStyleString;
@property (nonatomic, assign) UIEdgeInsets mapPadding;
@property (nonatomic, copy) RCTBubblingEventBlock onMapReady;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;
Expand Down
7 changes: 7 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ - (void)idleAtCameraPosition:(GMSCameraPosition *)position {
if (self.onChange) self.onChange(event); // complete
}

- (void)setMapPadding:(UIEdgeInsets)mapPadding {
self.padding = mapPadding;
}

- (UIEdgeInsets)mapPadding {
return self.padding;
}

- (void)setScrollEnabled:(BOOL)scrollEnabled {
self.settings.scrollGestures = scrollEnabled;
Expand Down
1 change: 1 addition & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(showsMyLocationButton, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsIndoorLevelPicker, BOOL)
RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString)
RCT_EXPORT_VIEW_PROPERTY(mapPadding, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
Expand Down

0 comments on commit bf40f06

Please sign in to comment.