Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d4ac89d

Browse files
ali-alaminegilbox
authored andcommittedNov 22, 2016
Adds support to ios for the google maps styling customMapStyle prop (react-native-maps#817)
1 parent 87f1b9e commit d4ac89d

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed
 

‎components/MapView.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,26 @@ class MapView extends React.Component {
400400
}
401401
}
402402

403+
componentDidMount() {
404+
const { isReady } = this.state;
405+
if (isReady) {
406+
this._updateStyle();
407+
}
408+
}
409+
410+
_updateStyle() {
411+
const { customMapStyle } = this.props;
412+
this.map.setNativeProps({ customMapStyleString: JSON.stringify(customMapStyle) });
413+
}
414+
403415
_onMapReady() {
404-
const { region, initialRegion, customMapStyle } = this.props;
416+
const { region, initialRegion } = this.props;
405417
if (region) {
406418
this.map.setNativeProps({ region });
407419
} else if (initialRegion) {
408420
this.map.setNativeProps({ region: initialRegion });
409421
}
410-
if (customMapStyle) {
411-
this.map.setNativeProps({ customMapStyleString: JSON.stringify(customMapStyle) });
412-
}
422+
this._updateStyle();
413423
this.setState({ isReady: true });
414424
}
415425

‎ios/AirGoogleMaps/AIRGoogleMap.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
// TODO: don't use MK region?
1818
@property (nonatomic, assign) MKCoordinateRegion initialRegion;
1919
@property (nonatomic, assign) MKCoordinateRegion region;
20+
@property (nonatomic, assign) NSString *customMapStyleString;
2021
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
2122
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;
2223
@property (nonatomic, copy) RCTBubblingEventBlock onMarkerPress;

‎ios/AirGoogleMaps/AIRGoogleMap.m

+12
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ - (void)setShowsCompass:(BOOL)showsCompass {
238238
self.settings.compassButton = showsCompass;
239239
}
240240

241+
- (void)setCustomMapStyleString:(NSString *)customMapStyleString {
242+
NSError *error;
243+
244+
GMSMapStyle *style = [GMSMapStyle styleWithJSONString:customMapStyleString error:&error];
245+
246+
if (!style) {
247+
NSLog(@"The style definition could not be loaded: %@", error);
248+
}
249+
250+
self.mapStyle = style;
251+
}
252+
241253
- (BOOL)showsCompass {
242254
return self.settings.compassButton;
243255
}

‎ios/AirGoogleMaps/AIRGoogleMapManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ - (UIView *)view
5656
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
5757
RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)
5858
RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL)
59+
RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString)
5960
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
6061
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
6162
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)

0 commit comments

Comments
 (0)
Please sign in to comment.