mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +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,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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user