Skip to content

Commit 99c42cd

Browse files
satori-ytolstoguzovrborn
authored andcommitted
Added support of lineDashPattern polyline prop to iOS Google Maps (react-native-maps#2243)
1 parent a4e6478 commit 99c42cd

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/ios/AirGoogleMaps/AIRGoogleMapPolyline.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@property (nonatomic, strong) UIColor *strokeColor;
2222
@property (nonatomic, assign) double strokeWidth;
2323
@property (nonatomic, assign) UIColor *fillColor;
24+
@property (nonatomic, strong) NSArray<NSNumber *> *lineDashPattern;
2425
@property (nonatomic, assign) BOOL geodesic;
2526
@property (nonatomic, assign) NSString *title;
2627
@property (nonatomic, assign) int zIndex;

lib/ios/AirGoogleMaps/AIRGoogleMapPolyline.m

+28-1
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ -(void)setCoordinates:(NSArray<AIRMapCoordinate *> *)coordinates
3232
[path addCoordinate:coordinates[i].coordinate];
3333
}
3434

35-
_polyline.path = path;
35+
_polyline.path = path;
36+
37+
[self configureStyleSpansIfNeeded];
3638
}
3739

3840
-(void)setStrokeColor:(UIColor *)strokeColor
3941
{
4042
_strokeColor = strokeColor;
4143
_polyline.strokeColor = strokeColor;
44+
[self configureStyleSpansIfNeeded];
4245
}
4346

4447
-(void)setStrokeWidth:(double)strokeWidth
@@ -53,6 +56,11 @@ -(void)setFillColor:(UIColor *)fillColor
5356
_polyline.spans = @[[GMSStyleSpan spanWithColor:fillColor]];
5457
}
5558

59+
- (void)setLineDashPattern:(NSArray<NSNumber *> *)lineDashPattern {
60+
_lineDashPattern = lineDashPattern;
61+
[self configureStyleSpansIfNeeded];
62+
}
63+
5664
-(void)setGeodesic:(BOOL)geodesic
5765
{
5866
_geodesic = geodesic;
@@ -81,4 +89,23 @@ - (void)setOnPress:(RCTBubblingEventBlock)onPress {
8189
_polyline.onPress = onPress;
8290
}
8391

92+
- (void)configureStyleSpansIfNeeded {
93+
if (!_strokeColor || !_lineDashPattern || !_polyline.path) {
94+
return;
95+
}
96+
97+
BOOL isLine = YES;
98+
NSMutableArray *styles = [[NSMutableArray alloc] init];
99+
for (NSInteger i = 0; i < _lineDashPattern.count; i++) {
100+
if (isLine) {
101+
[styles addObject:[GMSStrokeStyle solidColor:_strokeColor]];
102+
} else {
103+
[styles addObject:[GMSStrokeStyle solidColor:[UIColor clearColor]]];
104+
}
105+
isLine = !isLine;
106+
}
107+
108+
_polyline.spans = GMSStyleSpans(_polyline.path, styles, _lineDashPattern, kGMSLengthRhumb);
109+
}
110+
84111
@end

lib/ios/AirGoogleMaps/AIRGoogleMapPolylineManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ - (UIView *)view
3434
RCT_EXPORT_VIEW_PROPERTY(fillColor, UIColor)
3535
RCT_EXPORT_VIEW_PROPERTY(strokeColor, UIColor)
3636
RCT_EXPORT_VIEW_PROPERTY(strokeWidth, double)
37+
RCT_EXPORT_VIEW_PROPERTY(lineDashPattern, NSArray)
3738
RCT_EXPORT_VIEW_PROPERTY(geodesic, BOOL)
3839
RCT_EXPORT_VIEW_PROPERTY(zIndex, int)
3940
RCT_EXPORT_VIEW_PROPERTY(tappable, BOOL)

0 commit comments

Comments
 (0)