Skip to content

Commit

Permalink
Add handling of anti-aliasing for Circular images in IG
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D50793891

fbshipit-source-id: 106aba2e3706e0262f50b374c0981213025431a6
  • Loading branch information
AlexBalo authored and facebook-github-bot committed Oct 31, 2023
1 parent 9551d39 commit f6a801c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class ShapeCalculator {
return when {
roundingOptions == null -> RectShape(bounds)
roundingOptions.isCircular -> {
CircleShape(bounds.centerX(), bounds.centerY(), min(bounds.width(), bounds.height()) / 2f)
CircleShape(
bounds.centerX(),
bounds.centerY(),
min(bounds.width(), bounds.height()) / 2f,
roundingOptions.isAntiAliased)
}
roundingOptions.hasRoundedCorners() -> {
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ class RectShape(val rect: RectF) : Shape() {
override fun draw(canvas: Canvas, paint: Paint) = canvas.drawRect(rect, paint)
}

class CircleShape(val cx: Float, val cy: Float, val radius: Float) : Shape() {
override fun draw(canvas: Canvas, paint: Paint) = canvas.drawCircle(cx, cy, radius, paint)
class CircleShape(
private val cx: Float,
private val cy: Float,
private val radius: Float,
private val antiAliased: Boolean? = null
) : Shape() {
override fun draw(canvas: Canvas, paint: Paint) {
if (antiAliased != null) {
// Store the value for the anti-alias property this paint has
val paintAntiAliasValue = paint.isAntiAlias
// Temporarily apply anti-alias property for circle
paint.isAntiAlias = antiAliased
canvas.drawCircle(cx, cy, radius, paint)
// Restore previous value on the paint object to avoid collateral unexpected behaviours
paint.isAntiAlias = paintAntiAliasValue
} else {
canvas.drawCircle(cx, cy, radius, paint)
}
}
}

class RoundedRectShape(val rect: RectF, val rx: Float, val ry: Float) : Shape() {
Expand Down

0 comments on commit f6a801c

Please sign in to comment.