25
25
import android .view .View ;
26
26
import androidx .annotation .Nullable ;
27
27
import androidx .core .graphics .ColorUtils ;
28
+ import androidx .core .util .Preconditions ;
29
+ import com .facebook .infer .annotation .Nullsafe ;
28
30
import com .facebook .react .common .annotations .VisibleForTesting ;
29
31
import com .facebook .react .modules .i18nmanager .I18nUtil ;
30
32
import com .facebook .react .uimanager .FloatUtil ;
49
51
* have a rectangular borders we allocate {@code mBorderWidthResult} and similar. When only
50
52
* background color is set we won't allocate any extra/unnecessary objects.
51
53
*/
54
+ @ Nullsafe (Nullsafe .Mode .LOCAL )
52
55
public class CSSBackgroundDrawable extends Drawable {
53
56
54
57
private static final int DEFAULT_BORDER_COLOR = Color .BLACK ;
@@ -190,7 +193,7 @@ public void getOutline(Outline outline) {
190
193
if (hasRoundedBorders ()) {
191
194
updatePath ();
192
195
193
- outline .setConvexPath (mPathForBorderRadiusOutline );
196
+ outline .setConvexPath (Preconditions . checkNotNull ( mPathForBorderRadiusOutline ) );
194
197
} else {
195
198
outline .setRect (getBounds ());
196
199
}
@@ -315,27 +318,27 @@ public int getColor() {
315
318
316
319
public Path borderBoxPath () {
317
320
updatePath ();
318
- return mOuterClipPathForBorderRadius ;
321
+ return Preconditions . checkNotNull ( mOuterClipPathForBorderRadius ) ;
319
322
}
320
323
321
324
public Path paddingBoxPath () {
322
325
updatePath ();
323
- return mInnerClipPathForBorderRadius ;
326
+ return Preconditions . checkNotNull ( mInnerClipPathForBorderRadius ) ;
324
327
}
325
328
326
329
private void drawRoundedBackgroundWithBorders (Canvas canvas ) {
327
330
updatePath ();
328
331
canvas .save ();
329
332
330
333
// Clip outer border
331
- canvas .clipPath (mOuterClipPathForBorderRadius , Region .Op .INTERSECT );
334
+ canvas .clipPath (borderBoxPath () , Region .Op .INTERSECT );
332
335
333
336
// Draws the View without its border first (with background color fill)
334
337
int useColor = ColorUtils .setAlphaComponent (mColor , getOpacity ());
335
338
if (Color .alpha (useColor ) != 0 ) { // color is not transparent
336
339
mPaint .setColor (useColor );
337
340
mPaint .setStyle (Paint .Style .FILL );
338
- canvas .drawPath (mBackgroundColorRenderPath , mPaint );
341
+ canvas .drawPath (Preconditions . checkNotNull ( mBackgroundColorRenderPath ) , mPaint );
339
342
}
340
343
341
344
final RectF borderWidth = getDirectionAwareBorderInsets ();
@@ -379,15 +382,15 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
379
382
mPaint .setColor (multiplyColorAlpha (borderColor , mAlpha ));
380
383
mPaint .setStyle (Paint .Style .STROKE );
381
384
mPaint .setStrokeWidth (fullBorderWidth );
382
- canvas .drawPath (mCenterDrawPath , mPaint );
385
+ canvas .drawPath (Preconditions . checkNotNull ( mCenterDrawPath ) , mPaint );
383
386
}
384
387
}
385
388
// In the case of uneven border widths/colors draw quadrilateral in each direction
386
389
else {
387
390
mPaint .setStyle (Paint .Style .FILL );
388
391
389
392
// Clip inner border
390
- canvas .clipPath (mInnerClipPathForBorderRadius , Region .Op .DIFFERENCE );
393
+ canvas .clipPath (paddingBoxPath () , Region .Op .DIFFERENCE );
391
394
392
395
final boolean isRTL = getLayoutDirection () == View .LAYOUT_DIRECTION_RTL ;
393
396
int colorStart = getBorderColor (Spacing .START );
@@ -427,20 +430,27 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
427
430
}
428
431
}
429
432
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 );
434
444
435
445
// mGapBetweenPaths is used to close the gap between the diagonal
436
446
// edges of the quadrilaterals on adjacent sides of the rectangle
437
447
if (borderWidth .left > 0 ) {
438
448
final float x1 = left ;
439
449
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 ;
444
454
final float x4 = left ;
445
455
final float y4 = bottom + mGapBetweenPaths ;
446
456
@@ -450,10 +460,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
450
460
if (borderWidth .top > 0 ) {
451
461
final float x1 = left - mGapBetweenPaths ;
452
462
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 ;
457
467
final float x4 = right + mGapBetweenPaths ;
458
468
final float y4 = top ;
459
469
@@ -463,10 +473,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
463
473
if (borderWidth .right > 0 ) {
464
474
final float x1 = right ;
465
475
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 ;
470
480
final float x4 = right ;
471
481
final float y4 = bottom + mGapBetweenPaths ;
472
482
@@ -476,10 +486,10 @@ private void drawRoundedBackgroundWithBorders(Canvas canvas) {
476
486
if (borderWidth .bottom > 0 ) {
477
487
final float x1 = left - mGapBetweenPaths ;
478
488
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 ;
483
493
final float x4 = right + mGapBetweenPaths ;
484
494
final float y4 = bottom ;
485
495
0 commit comments