Skip to content

Commit 93c079b

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Mark CSSBackgroundDrawable as Nullsafe (facebook#44541)
Summary: Pull Request resolved: facebook#44541 Changelog: [Internal] Reviewed By: rshest Differential Revision: D57250750 fbshipit-source-id: 433213b83ebd8fba8d326434787a2d7e6cf1c626
1 parent e16faca commit 93c079b

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/CSSBackgroundDrawable.java

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.view.View;
2626
import androidx.annotation.Nullable;
2727
import androidx.core.graphics.ColorUtils;
28+
import androidx.core.util.Preconditions;
29+
import com.facebook.infer.annotation.Nullsafe;
2830
import com.facebook.react.common.annotations.VisibleForTesting;
2931
import com.facebook.react.modules.i18nmanager.I18nUtil;
3032
import com.facebook.react.uimanager.FloatUtil;
@@ -49,6 +51,7 @@
4951
* have a rectangular borders we allocate {@code mBorderWidthResult} and similar. When only
5052
* background color is set we won't allocate any extra/unnecessary objects.
5153
*/
54+
@Nullsafe(Nullsafe.Mode.LOCAL)
5255
public class CSSBackgroundDrawable extends Drawable {
5356

5457
private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
@@ -190,7 +193,7 @@ public void getOutline(Outline outline) {
190193
if (hasRoundedBorders()) {
191194
updatePath();
192195

193-
outline.setConvexPath(mPathForBorderRadiusOutline);
196+
outline.setConvexPath(Preconditions.checkNotNull(mPathForBorderRadiusOutline));
194197
} else {
195198
outline.setRect(getBounds());
196199
}
@@ -315,27 +318,27 @@ public int getColor() {
315318

316319
public Path borderBoxPath() {
317320
updatePath();
318-
return mOuterClipPathForBorderRadius;
321+
return Preconditions.checkNotNull(mOuterClipPathForBorderRadius);
319322
}
320323

321324
public Path paddingBoxPath() {
322325
updatePath();
323-
return mInnerClipPathForBorderRadius;
326+
return Preconditions.checkNotNull(mInnerClipPathForBorderRadius);
324327
}
325328

326329
private void drawRoundedBackgroundWithBorders(Canvas canvas) {
327330
updatePath();
328331
canvas.save();
329332

330333
// Clip outer border
331-
canvas.clipPath(mOuterClipPathForBorderRadius, Region.Op.INTERSECT);
334+
canvas.clipPath(borderBoxPath(), Region.Op.INTERSECT);
332335

333336
// Draws the View without its border first (with background color fill)
334337
int useColor = ColorUtils.setAlphaComponent(mColor, getOpacity());
335338
if (Color.alpha(useColor) != 0) { // color is not transparent
336339
mPaint.setColor(useColor);
337340
mPaint.setStyle(Paint.Style.FILL);
338-
canvas.drawPath(mBackgroundColorRenderPath, mPaint);
341+
canvas.drawPath(Preconditions.checkNotNull(mBackgroundColorRenderPath), mPaint);
339342
}
340343

341344
final RectF borderWidth = getDirectionAwareBorderInsets();
@@ -379,15 +382,15 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
379382
mPaint.setColor(multiplyColorAlpha(borderColor, mAlpha));
380383
mPaint.setStyle(Paint.Style.STROKE);
381384
mPaint.setStrokeWidth(fullBorderWidth);
382-
canvas.drawPath(mCenterDrawPath, mPaint);
385+
canvas.drawPath(Preconditions.checkNotNull(mCenterDrawPath), mPaint);
383386
}
384387
}
385388
// In the case of uneven border widths/colors draw quadrilateral in each direction
386389
else {
387390
mPaint.setStyle(Paint.Style.FILL);
388391

389392
// Clip inner border
390-
canvas.clipPath(mInnerClipPathForBorderRadius, Region.Op.DIFFERENCE);
393+
canvas.clipPath(paddingBoxPath(), Region.Op.DIFFERENCE);
391394

392395
final boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
393396
int colorStart = getBorderColor(Spacing.START);
@@ -427,20 +430,27 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
427430
}
428431
}
429432

430-
final float left = mOuterClipTempRectForBorderRadius.left;
431-
final float right = mOuterClipTempRectForBorderRadius.right;
432-
final float top = mOuterClipTempRectForBorderRadius.top;
433-
final float bottom = mOuterClipTempRectForBorderRadius.bottom;
433+
final RectF outerClipTempRect =
434+
Preconditions.checkNotNull(mOuterClipTempRectForBorderRadius);
435+
final float left = outerClipTempRect.left;
436+
final float right = outerClipTempRect.right;
437+
final float top = outerClipTempRect.top;
438+
final float bottom = outerClipTempRect.bottom;
439+
440+
final PointF innerTopLeftCorner = Preconditions.checkNotNull(mInnerTopLeftCorner);
441+
final PointF innerTopRightCorner = Preconditions.checkNotNull(mInnerTopRightCorner);
442+
final PointF innerBottomLeftCorner = Preconditions.checkNotNull(mInnerBottomLeftCorner);
443+
final PointF innerBottomRightCorner = Preconditions.checkNotNull(mInnerBottomRightCorner);
434444

435445
// mGapBetweenPaths is used to close the gap between the diagonal
436446
// edges of the quadrilaterals on adjacent sides of the rectangle
437447
if (borderWidth.left > 0) {
438448
final float x1 = left;
439449
final float y1 = top - mGapBetweenPaths;
440-
final float x2 = mInnerTopLeftCorner.x;
441-
final float y2 = mInnerTopLeftCorner.y - mGapBetweenPaths;
442-
final float x3 = mInnerBottomLeftCorner.x;
443-
final float y3 = mInnerBottomLeftCorner.y + mGapBetweenPaths;
450+
final float x2 = innerTopLeftCorner.x;
451+
final float y2 = innerTopLeftCorner.y - mGapBetweenPaths;
452+
final float x3 = innerBottomLeftCorner.x;
453+
final float y3 = innerBottomLeftCorner.y + mGapBetweenPaths;
444454
final float x4 = left;
445455
final float y4 = bottom + mGapBetweenPaths;
446456

@@ -450,10 +460,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
450460
if (borderWidth.top > 0) {
451461
final float x1 = left - mGapBetweenPaths;
452462
final float y1 = top;
453-
final float x2 = mInnerTopLeftCorner.x - mGapBetweenPaths;
454-
final float y2 = mInnerTopLeftCorner.y;
455-
final float x3 = mInnerTopRightCorner.x + mGapBetweenPaths;
456-
final float y3 = mInnerTopRightCorner.y;
463+
final float x2 = innerTopLeftCorner.x - mGapBetweenPaths;
464+
final float y2 = innerTopLeftCorner.y;
465+
final float x3 = innerTopRightCorner.x + mGapBetweenPaths;
466+
final float y3 = innerTopRightCorner.y;
457467
final float x4 = right + mGapBetweenPaths;
458468
final float y4 = top;
459469

@@ -463,10 +473,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
463473
if (borderWidth.right > 0) {
464474
final float x1 = right;
465475
final float y1 = top - mGapBetweenPaths;
466-
final float x2 = mInnerTopRightCorner.x;
467-
final float y2 = mInnerTopRightCorner.y - mGapBetweenPaths;
468-
final float x3 = mInnerBottomRightCorner.x;
469-
final float y3 = mInnerBottomRightCorner.y + mGapBetweenPaths;
476+
final float x2 = innerTopRightCorner.x;
477+
final float y2 = innerTopRightCorner.y - mGapBetweenPaths;
478+
final float x3 = innerBottomRightCorner.x;
479+
final float y3 = innerBottomRightCorner.y + mGapBetweenPaths;
470480
final float x4 = right;
471481
final float y4 = bottom + mGapBetweenPaths;
472482

@@ -476,10 +486,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
476486
if (borderWidth.bottom > 0) {
477487
final float x1 = left - mGapBetweenPaths;
478488
final float y1 = bottom;
479-
final float x2 = mInnerBottomLeftCorner.x - mGapBetweenPaths;
480-
final float y2 = mInnerBottomLeftCorner.y;
481-
final float x3 = mInnerBottomRightCorner.x + mGapBetweenPaths;
482-
final float y3 = mInnerBottomRightCorner.y;
489+
final float x2 = innerBottomLeftCorner.x - mGapBetweenPaths;
490+
final float y2 = innerBottomLeftCorner.y;
491+
final float x3 = innerBottomRightCorner.x + mGapBetweenPaths;
492+
final float y3 = innerBottomRightCorner.y;
483493
final float x4 = right + mGapBetweenPaths;
484494
final float y4 = bottom;
485495

0 commit comments

Comments
 (0)