mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
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.
This commit is contained in:
@ -896,6 +896,13 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
@Override
|
@Override
|
||||||
public void getOutline(@NonNull Outline outline) {
|
public void getOutline(@NonNull Outline outline) {
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
if (android.os.Build.VERSION.SDK_INT >= 21) {
|
||||||
|
outlineRectF.setEmpty();
|
||||||
|
outlineRectF.set(getBounds());
|
||||||
|
if (hasUniformBorderRadius()) {
|
||||||
|
outline.setRoundRect(getBounds(), borderTopLeftRadius);
|
||||||
|
} else {
|
||||||
|
// cliping with path is only support on API >= 33
|
||||||
|
// before it only works for rectangle, circle, or round rect
|
||||||
outlineBackgroundPath.reset();
|
outlineBackgroundPath.reset();
|
||||||
float[] backgroundRadii = {
|
float[] backgroundRadii = {
|
||||||
Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius),
|
Math.max(0, borderTopLeftRadius), Math.max(0, borderTopLeftRadius),
|
||||||
@ -903,8 +910,6 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius),
|
Math.max(0, borderBottomRightRadius), Math.max(0, borderBottomRightRadius),
|
||||||
Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius)
|
Math.max(0, borderBottomLeftRadius), Math.max(0, borderBottomLeftRadius)
|
||||||
};
|
};
|
||||||
outlineRectF.setEmpty();
|
|
||||||
outlineRectF.set(getBounds());
|
|
||||||
outlineBackgroundPath.addRoundRect(outlineRectF, backgroundRadii, Path.Direction.CW);
|
outlineBackgroundPath.addRoundRect(outlineRectF, backgroundRadii, Path.Direction.CW);
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
@ -913,7 +918,7 @@ public class BorderDrawable extends ColorDrawable implements BitmapOwner {
|
|||||||
} else {
|
} else {
|
||||||
outline.setConvexPath(outlineBackgroundPath);
|
outline.setConvexPath(outlineBackgroundPath);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("Method supported on API 21 or higher");
|
throw new IllegalStateException("Method supported on API 21 or higher");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user