Skip to content

Commit

Permalink
[Fix] IOS will crash and change the gradient in Android.
Browse files Browse the repository at this point in the history
[Cause] The app crashes in IOS because the default ratio is 0.0.

[Solution] Set the ratio default value to 1.0.
  • Loading branch information
boris committed Jul 13, 2021
1 parent b6a9d5c commit 8439076
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static Bitmap withSos(Bitmap avatar, float density) {
Canvas canvas = new Canvas(output);

Paint shadowPaint = new Paint();
shadowPaint.setShadowLayer(40.0f, 0.f, 0.f, Color.RED);
shadowPaint.setShadowLayer(20.0f, 0.f, 0.f, Color.RED);
shadowPaint.setColor(Color.RED);
RectF rectF = new RectF(new Rect(shadowSize + offset, shadowSize + offset, avatar.getWidth() + shadowSize - offset, avatar.getWidth() + shadowSize - offset));
canvas.drawOval(rectF, shadowPaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ - (void)onMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSNumber* rideStatus = extra[@"rideStatus"];
if (!rideStatus) rideStatus = [NSNumber numberWithInt:0];
NSNumber* ratio = extra[@"ratio"];
if (!ratio) ratio = [NSNumber numberWithFloat:0.0];
if (!ratio) ratio = [NSNumber numberWithFloat:1.0];
UIImage* image;
if (path != nil && path != [NSNull null]) {
image = [_markerIconPainter getUIImageFromPath:path ratio:ratio];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,35 @@ - (UIImage*) withSos:(UIImage *)avatar ratio:(NSNumber *)ratio {
CGPoint center = CGPointMake(iconSize / 2, iconSize / 2);
float radius = iconSize / 2;
CGRect ellipseRect = CGRectMake(0, 0, iconSize, iconSize);

UIGraphicsBeginImageContextWithOptions(CGSizeMake(iconSize, iconSize), NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();

CGFloat colors[] = {
1.0, 0.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.1,
1.0, 0.0, 0.0, 0.15,
1.0, 0.0, 0.0, 0.2,
1.0, 0.0, 0.0, 0.25,
1.0, 0.0, 0.0, 0.3,
1.0, 0.0, 0.0, 0.8,
1.0, 0.0, 0.0, 0.31,
1.0, 0.0, 0.0, 0.32,
1.0, 0.0, 0.0, 0.33,
1.0, 0.0, 0.0, 0.65,
1.0, 0.0, 0.0, 0.7,
};
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradientref = CGGradientCreateWithColorComponents(colorSpaceRef, colors, NULL, 2);
CGGradientRef gradientref = CGGradientCreateWithColorComponents(colorSpaceRef, colors, NULL, 11);
CGContextAddEllipseInRect(context, ellipseRect);
CGContextClip(context);

CGContextDrawRadialGradient(context, gradientref, center, radius, center, radius - shadowSize, kCGGradientDrawsAfterEndLocation);

[avatar drawInRect:CGRectMake(shadowSize, shadowSize, avatar.size.width, avatar.size.height)];

UIImage* view = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return view;
}

Expand Down

0 comments on commit 8439076

Please sign in to comment.