File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed
Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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;
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ - (UIView *)view
5656RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL )
5757RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL )
5858RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL )
59+ RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString )
5960RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
6061RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
6162RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
You can’t perform that action at this time.
0 commit comments