From ff66b1bb8e37b924e7aff0b960d432024cfa0d66 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Thu, 28 Sep 2023 02:07:51 +0000 Subject: [PATCH] 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. --- .../nativescript/widgets/BorderDrawable.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java b/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java index d9fd9f914..ead3fd11d 100644 --- a/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java +++ b/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/BorderDrawable.java @@ -896,24 +896,29 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner { @Override public void getOutline(@NonNull Outline outline) { if (android.os.Build.VERSION.SDK_INT >= 21) { - outlineBackgroundPath.reset(); - float[] backgroundRadii = { - Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius), - Math.max(0, borderTopRightRadius), Math.max(0, borderTopRightRadius), - Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius), - Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius) - }; outlineRectF.setEmpty(); outlineRectF.set(getBounds()); - outlineBackgroundPath.addRoundRect(outlineRectF, backgroundRadii, Path.Direction.CW); - - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - // see setConvexPath notes - outline.setPath(outlineBackgroundPath); + if (hasUniformBorderRadius()) { + outline.setRoundRect(getBounds(), borderTopLeftRadius); } else { - outline.setConvexPath(outlineBackgroundPath); - } + // cliping with path is only support on API >= 33 + // before it only works for rectangle, circle, or round rect + outlineBackgroundPath.reset(); + float[] backgroundRadii = { + Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius), + Math.max(0, borderTopRightRadius), Math.max(0, borderTopRightRadius), + Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius), + Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius) + }; + outlineBackgroundPath.addRoundRect(outlineRectF, backgroundRadii, Path.Direction.CW); + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + // see setConvexPath notes + outline.setPath(outlineBackgroundPath); + } else { + outline.setConvexPath(outlineBackgroundPath); + } + } } else { throw new IllegalStateException("Method supported on API 21 or higher"); }