Skip to content

Commit b491acd

Browse files
peterjuraschristopherdro
authored andcommitted
Add mapPadding property (react-native-maps#1750)
* Add mapPadding property * Fix trailing whitespace in MapView comments
1 parent 1f558b1 commit b491acd

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

lib/android/src/main/java/com/airbnb/android/react/maps/AirMapManager.java

+29
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ public void setMapStyle(AirMapView view, @Nullable String customMapStyleString)
9393
view.map.setMapStyle(new MapStyleOptions(customMapStyleString));
9494
}
9595

96+
@ReactProp(name = "mapPadding")
97+
public void setMapPadding(AirMapView view, @Nullable ReadableMap padding) {
98+
int left = 0;
99+
int top = 0;
100+
int right = 0;
101+
int bottom = 0;
102+
double density = (double) view.getResources().getDisplayMetrics().density;
103+
104+
if (padding != null) {
105+
if (padding.hasKey("left")) {
106+
left = (int) (padding.getDouble("left") * density);
107+
}
108+
109+
if (padding.hasKey("top")) {
110+
top = (int) (padding.getDouble("top") * density);
111+
}
112+
113+
if (padding.hasKey("right")) {
114+
right = (int) (padding.getDouble("right") * density);
115+
}
116+
117+
if (padding.hasKey("bottom")) {
118+
bottom = (int) (padding.getDouble("bottom") * density);
119+
}
120+
}
121+
122+
view.map.setPadding(left, top, right, bottom);
123+
}
124+
96125
@ReactProp(name = "showsUserLocation", defaultBoolean = false)
97126
public void setShowsUserLocation(AirMapView view, boolean showUserLocation) {
98127
view.setShowsUserLocation(showUserLocation);

lib/components/MapView.js

+9
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ const propTypes = {
303303
*/
304304
liteMode: PropTypes.bool,
305305

306+
/**
307+
* (Google Maps only)
308+
*
309+
* Padding that is used by the Google Map View to position
310+
* the camera, legal labels and buttons
311+
*
312+
*/
313+
mapPadding: EdgeInsetsPropType,
314+
306315
/**
307316
* Maximum size of area that can be displayed.
308317
*

lib/ios/AirGoogleMaps/AIRGoogleMap.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@property (nonatomic, assign) MKCoordinateRegion initialRegion;
1919
@property (nonatomic, assign) MKCoordinateRegion region;
2020
@property (nonatomic, assign) NSString *customMapStyleString;
21+
@property (nonatomic, assign) UIEdgeInsets mapPadding;
2122
@property (nonatomic, copy) RCTBubblingEventBlock onMapReady;
2223
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
2324
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;

lib/ios/AirGoogleMaps/AIRGoogleMap.m

+7
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ - (void)idleAtCameraPosition:(GMSCameraPosition *)position {
219219
if (self.onChange) self.onChange(event); // complete
220220
}
221221

222+
- (void)setMapPadding:(UIEdgeInsets)mapPadding {
223+
self.padding = mapPadding;
224+
}
225+
226+
- (UIEdgeInsets)mapPadding {
227+
return self.padding;
228+
}
222229

223230
- (void)setScrollEnabled:(BOOL)scrollEnabled {
224231
self.settings.scrollGestures = scrollEnabled;

lib/ios/AirGoogleMaps/AIRGoogleMapManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ - (UIView *)view
6363
RCT_EXPORT_VIEW_PROPERTY(showsMyLocationButton, BOOL)
6464
RCT_EXPORT_VIEW_PROPERTY(showsIndoorLevelPicker, BOOL)
6565
RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString)
66+
RCT_EXPORT_VIEW_PROPERTY(mapPadding, UIEdgeInsets)
6667
RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock)
6768
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
6869
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)

0 commit comments

Comments
 (0)