Commit 5d898940 authored by Qiu Xiang's avatar Qiu Xiang

移除 Polyline opacity 接口

parent d68cec5a
...@@ -25,12 +25,6 @@ class AMapPolyline(context: ThemedReactContext) : ReactViewGroup(context) { ...@@ -25,12 +25,6 @@ class AMapPolyline(context: ThemedReactContext) : ReactViewGroup(context) {
polyline?.color = value polyline?.color = value
} }
var opacity: Float = 1f
set(value) {
field = value
polyline?.setTransparency(value)
}
var zIndex: Float = 0f var zIndex: Float = 0f
set(value) { set(value) {
field = value field = value
...@@ -75,7 +69,6 @@ class AMapPolyline(context: ThemedReactContext) : ReactViewGroup(context) { ...@@ -75,7 +69,6 @@ class AMapPolyline(context: ThemedReactContext) : ReactViewGroup(context) {
.useGradient(gradient) .useGradient(gradient)
.geodesic(geodesic) .geodesic(geodesic)
.setDottedLine(dashed) .setDottedLine(dashed)
.transparency(opacity)
.zIndex(zIndex)) .zIndex(zIndex))
} }
} }
...@@ -44,11 +44,6 @@ internal class AMapPolylineManager : ViewGroupManager<AMapPolyline>() { ...@@ -44,11 +44,6 @@ internal class AMapPolylineManager : ViewGroupManager<AMapPolyline>() {
polyline.zIndex = zIndex polyline.zIndex = zIndex
} }
@ReactProp(name = "opacity")
override fun setOpacity(polyline: AMapPolyline, opacity: Float) {
polyline.opacity = opacity
}
@ReactProp(name = "geodesic") @ReactProp(name = "geodesic")
fun setGeodesic(polyline: AMapPolyline, geodesic: Boolean) { fun setGeodesic(polyline: AMapPolyline, geodesic: Boolean) {
polyline.geodesic = geodesic polyline.geodesic = geodesic
......
...@@ -10,7 +10,6 @@ class Polyline extends Component { ...@@ -10,7 +10,6 @@ class Polyline extends Component {
width: PropTypes.number, width: PropTypes.number,
color: PropTypes.string, color: PropTypes.string,
zIndex: PropTypes.number, zIndex: PropTypes.number,
opacity: PropTypes.number,
/** /**
* 多段颜色 * 多段颜色
...@@ -59,9 +58,9 @@ class Polyline extends Component { ...@@ -59,9 +58,9 @@ class Polyline extends Component {
...Platform.select({ ...Platform.select({
android: { android: {
width: PixelRatio.getPixelSizeForLayoutSize(this.props.width), width: PixelRatio.getPixelSizeForLayoutSize(this.props.width),
colors: this.props.colors.map(processColor),
}, },
}), }),
colors: this.props.colors.map(processColor),
onPolylineClick: this._handle('onPress'), onPolylineClick: this._handle('onPress'),
} }
return <AMapPolyline {...props}/> return <AMapPolyline {...props}/>
......
...@@ -6,20 +6,19 @@ ...@@ -6,20 +6,19 @@
@implementation AMapPolyline { @implementation AMapPolyline {
MAMultiPolyline *_polyline; MAMultiPolyline *_polyline;
MAMultiColoredPolylineRenderer *_renderer; MAMultiColoredPolylineRenderer *_renderer;
CGFloat _width; CGFloat _width;
UIColor *_color; UIColor *_color;
NSArray *_colors; NSArray *_colors;
CGFloat _opacity;
BOOL _dashed; BOOL _dashed;
BOOL _gradient; BOOL _gradient;
} }
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
_polyline = [MAMultiPolyline polylineWithCoordinates:NULL count:0 drawStyleIndexes:NULL]; _polyline = [MAMultiPolyline polylineWithCoordinates:nil count:0 drawStyleIndexes:nil];
} }
return self; return self;
} }
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
for (NSUInteger i = 0; i < coordinates.count; i++) { for (NSUInteger i = 0; i < coordinates.count; i++) {
coords[i] = coordinates[i].coordinate; coords[i] = coordinates[i].coordinate;
} }
[_polyline setPolylineWithCoordinates:coords count:coordinates.count]; [_polyline setPolylineWithCoordinates:coords count:coordinates.count];
} }
...@@ -37,44 +36,38 @@ ...@@ -37,44 +36,38 @@
_renderer.lineWidth = width; _renderer.lineWidth = width;
} }
- (void)setOpacity:(CGFloat)opacity {
opacity = MAX(0.01, opacity); // 线段最低的opacity是0.01不能再小了,否则干掉多好。Android系统上默认为此逻辑。
_opacity = opacity;
_renderer.alpha = opacity;
}
- (void)setColor:(UIColor *)color { - (void)setColor:(UIColor *)color {
_color = color; _color = color;
_renderer.strokeColor = color; _renderer.strokeColor = color;
} }
- (void)setColors:(NSArray *)colors { - (void)setColors:(NSArray *)colors {
// process colors -> strokeColor |egg: [black, black, black, white, white, black] => [black, white, black] + [3, 5]| // colors -> strokeColors
// egg: [black, black, black, white, white, black] => [black, white, black] + [3, 5]
NSMutableArray *strokeColors = [[NSMutableArray alloc] init]; NSMutableArray *strokeColors = [[NSMutableArray alloc] init];
NSMutableArray *indexs = [[NSMutableArray alloc] init]; NSMutableArray *indexs = [[NSMutableArray alloc] init];
if (colors.count > 0) { if (colors.count > 0) {
UIColor *lastColor = [colors firstObject]; UIColor *lastColor = [colors firstObject];
[strokeColors addObject:lastColor]; [strokeColors addObject:lastColor];
for (NSUInteger index = 1; index < colors.count; index++) { for (NSUInteger index = 1; index < colors.count; index++) {
UIColor *color = colors[index]; UIColor *color = colors[index];
if (![color isEqual:lastColor]) { if (![color isEqual:lastColor]) {
[strokeColors addObject:color]; [strokeColors addObject:color];
[indexs addObject:@(index)]; // index is the NEXT color [indexs addObject:@(index)]; // index is the NEXT color
lastColor = color; lastColor = color;
} }
} }
if (strokeColors.count == 1) { if (strokeColors.count == 1) {
[indexs addObject:@(colors.count)]; [indexs addObject:@(colors.count)];
} }
} }
_colors = strokeColors; _colors = strokeColors;
_renderer.strokeColors = strokeColors; _renderer.strokeColors = strokeColors;
// change polyline // change polyline
[_polyline setDrawStyleIndexes:@[@(1), @(2)]]; [_polyline setDrawStyleIndexes:@[@(1), @(2)]];
} }
...@@ -101,12 +94,11 @@ ...@@ -101,12 +94,11 @@
if (_color == nil) { if (_color == nil) {
_color = UIColor.blackColor; _color = UIColor.blackColor;
} }
_renderer = [[MAMultiColoredPolylineRenderer alloc] initWithMultiPolyline:_polyline]; _renderer = [[MAMultiColoredPolylineRenderer alloc] initWithMultiPolyline:_polyline];
_renderer.lineWidth = _width; _renderer.lineWidth = _width;
_renderer.strokeColor = _color; _renderer.strokeColor = _color;
_renderer.strokeColors = _colors; _renderer.strokeColors = _colors;
_renderer.alpha = _opacity;
_renderer.lineDash = _dashed; _renderer.lineDash = _dashed;
_renderer.gradient = _gradient; _renderer.gradient = _gradient;
return _renderer; return _renderer;
......
...@@ -18,7 +18,6 @@ RCT_EXPORT_MODULE() ...@@ -18,7 +18,6 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_VIEW_PROPERTY(coordinates, CoordinateArray) RCT_EXPORT_VIEW_PROPERTY(coordinates, CoordinateArray)
RCT_EXPORT_VIEW_PROPERTY(width, CGFloat) RCT_EXPORT_VIEW_PROPERTY(width, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(opacity, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(color, UIColor) RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
RCT_EXPORT_VIEW_PROPERTY(dashed, BOOL) RCT_EXPORT_VIEW_PROPERTY(dashed, BOOL)
RCT_EXPORT_VIEW_PROPERTY(gradient, BOOL) RCT_EXPORT_VIEW_PROPERTY(gradient, BOOL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment