Skip to content

Commit ff66b1b

Browse files
authored
fix(android): outline path is only supported on api >=33 (#10389)
Outline path is only supported on api >=33 but we can still get it to work for uniform border radius.
1 parent b6a5250 commit ff66b1b

File tree

1 file changed

+19
-14
lines changed
  • packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets

1 file changed

+19
-14
lines changed

packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -896,24 +896,29 @@ public Drawable getDrawable() {
896896
@Override
897897
public void getOutline(@NonNull Outline outline) {
898898
if (android.os.Build.VERSION.SDK_INT >= 21) {
899-
outlineBackgroundPath.reset();
900-
float[] backgroundRadii = {
901-
Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius),
902-
Math.max(0, borderTopRightRadius), Math.max(0, borderTopRightRadius),
903-
Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius),
904-
Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius)
905-
};
906899
outlineRectF.setEmpty();
907900
outlineRectF.set(getBounds());
908-
outlineBackgroundPath.addRoundRect(outlineRectF, backgroundRadii, Path.Direction.CW);
909-
910-
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
911-
// see setConvexPath notes
912-
outline.setPath(outlineBackgroundPath);
901+
if (hasUniformBorderRadius()) {
902+
outline.setRoundRect(getBounds(), borderTopLeftRadius);
913903
} else {
914-
outline.setConvexPath(outlineBackgroundPath);
915-
}
904+
// cliping with path is only support on API >= 33
905+
// before it only works for rectangle, circle, or round rect
906+
outlineBackgroundPath.reset();
907+
float[] backgroundRadii = {
908+
Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius),
909+
Math.max(0, borderTopRightRadius), Math.max(0, borderTopRightRadius),
910+
Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius),
911+
Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius)
912+
};
913+
outlineBackgroundPath.addRoundRect(outlineRectF, backgroundRadii, Path.Direction.CW);
916914

915+
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
916+
// see setConvexPath notes
917+
outline.setPath(outlineBackgroundPath);
918+
} else {
919+
outline.setConvexPath(outlineBackgroundPath);
920+
}
921+
}
917922
} else {
918923
throw new IllegalStateException("Method supported on API 21 or higher");
919924
}

0 commit comments

Comments
 (0)