Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mapPadding property #1750

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
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 @@ -302,6 +302,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 @@ -60,6 +60,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