File tree 4 files changed +28
-4
lines changed
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 {
400
400
}
401
401
}
402
402
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
+
403
415
_onMapReady ( ) {
404
- const { region, initialRegion, customMapStyle } = this . props ;
416
+ const { region, initialRegion } = this . props ;
405
417
if ( region ) {
406
418
this . map . setNativeProps ( { region } ) ;
407
419
} else if ( initialRegion ) {
408
420
this . map . setNativeProps ( { region : initialRegion } ) ;
409
421
}
410
- if ( customMapStyle ) {
411
- this . map . setNativeProps ( { customMapStyleString : JSON . stringify ( customMapStyle ) } ) ;
412
- }
422
+ this . _updateStyle ( ) ;
413
423
this . setState ( { isReady : true } ) ;
414
424
}
415
425
Original file line number Diff line number Diff line change 17
17
// TODO: don't use MK region?
18
18
@property (nonatomic , assign ) MKCoordinateRegion initialRegion;
19
19
@property (nonatomic , assign ) MKCoordinateRegion region;
20
+ @property (nonatomic , assign ) NSString *customMapStyleString;
20
21
@property (nonatomic , copy ) RCTBubblingEventBlock onPress;
21
22
@property (nonatomic , copy ) RCTBubblingEventBlock onLongPress;
22
23
@property (nonatomic , copy ) RCTBubblingEventBlock onMarkerPress;
Original file line number Diff line number Diff line change @@ -238,6 +238,18 @@ - (void)setShowsCompass:(BOOL)showsCompass {
238
238
self.settings .compassButton = showsCompass;
239
239
}
240
240
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
+
241
253
- (BOOL )showsCompass {
242
254
return self.settings .compassButton ;
243
255
}
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ - (UIView *)view
56
56
RCT_EXPORT_VIEW_PROPERTY(scrollEnabled, BOOL )
57
57
RCT_EXPORT_VIEW_PROPERTY(pitchEnabled, BOOL )
58
58
RCT_EXPORT_VIEW_PROPERTY(showsUserLocation, BOOL )
59
+ RCT_EXPORT_VIEW_PROPERTY(customMapStyleString, NSString )
59
60
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
60
61
RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
61
62
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
You can’t perform that action at this time.
0 commit comments