mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(android): prevent clipped font icons on Android (#10858)
This commit is contained in:
@ -181,13 +181,14 @@ export class ImageSource implements ImageSourceDefinition {
|
|||||||
const textBounds = new android.graphics.Rect();
|
const textBounds = new android.graphics.Rect();
|
||||||
paint.getTextBounds(source, 0, source.length, textBounds);
|
paint.getTextBounds(source, 0, source.length, textBounds);
|
||||||
|
|
||||||
const textWidth = textBounds.width();
|
const padding = 1;
|
||||||
const textHeight = textBounds.height();
|
const textWidth = textBounds.width() + padding * 2;
|
||||||
|
const textHeight = textBounds.height() + padding * 2;
|
||||||
if (textWidth > 0 && textHeight > 0) {
|
if (textWidth > 0 && textHeight > 0) {
|
||||||
const bitmap = android.graphics.Bitmap.createBitmap(textWidth, textHeight, android.graphics.Bitmap.Config.ARGB_8888);
|
const bitmap = android.graphics.Bitmap.createBitmap(textWidth, textHeight, android.graphics.Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
const canvas = new android.graphics.Canvas(bitmap);
|
const canvas = new android.graphics.Canvas(bitmap);
|
||||||
canvas.drawText(source, -textBounds.left, -textBounds.top, paint);
|
canvas.drawText(source, -textBounds.left + padding, -textBounds.top + padding, paint);
|
||||||
|
|
||||||
return new ImageSource(bitmap);
|
return new ImageSource(bitmap);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user