Skip to content

Commit

Permalink
Adds support to ios for the google maps styling
Browse files Browse the repository at this point in the history
Added the map styling to ios

Fixed the android build that broke

Fixed some styling issues
  • Loading branch information
alialamine committed Nov 22, 2016
1 parent db42a97 commit aef830b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
18 changes: 14 additions & 4 deletions components/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,16 +400,26 @@ class MapView extends React.Component {
}
}

componentDidMount() {
const { isReady } = this.state;
if (isReady) {
this._updateStyle();
}
}

_updateStyle() {
const { customMapStyle } = this.props;
this.map.setNativeProps({ customMapStyleString: JSON.stringify(customMapStyle) });
}

_onMapReady() {
const { region, initialRegion, customMapStyle } = this.props;
const { region, initialRegion } = this.props;
if (region) {
this.map.setNativeProps({ region });
} else if (initialRegion) {
this.map.setNativeProps({ region: initialRegion });
}
if (customMapStyle) {
this.map.setNativeProps({ customMapStyleString: JSON.stringify(customMapStyle) });
}
this._updateStyle();
this.setState({ isReady: true });
}

Expand Down
1 change: 1 addition & 0 deletions ios/AirGoogleMaps/AIRGoogleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// TODO: don't use MK region?
@property (nonatomic, assign) MKCoordinateRegion initialRegion;
@property (nonatomic, assign) MKCoordinateRegion region;
@property (nonatomic, assign) NSString *customMapStyleString;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@property (nonatomic, copy) RCTBubblingEventBlock onLongPress;
@property (nonatomic, copy) RCTBubblingEventBlock onMarkerPress;
Expand Down
12 changes: 12 additions & 0 deletions ios/AirGoogleMaps/AIRGoogleMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ - (void)setShowsCompass:(BOOL)showsCompass {
self.settings.compassButton = showsCompass;
}

- (void)setCustomMapStyleString:(NSString *)customMapStyleString {
NSError *error;

GMSMapStyle *style = [GMSMapStyle styleWithJSONString:customMapStyleString error:&error];

if (!style) {
NSLog(@"The style definition could not be loaded: %@", error);
}

self.mapStyle = style;
}

- (BOOL)showsCompass {
return self.settings.compassButton;
}
Expand Down
1 change: 1 addition & 0 deletions ios/AirGoogleMaps/AIRGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL)
RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString)
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
Expand Down

0 comments on commit aef830b

Please sign in to comment.