Center align image in a span

Reviewed By: achen1

Differential Revision: D7750114

fbshipit-source-id: 84b4eaa2da01ac9c49a569d37f7a32eab1e5aca8
This commit is contained in:
Himabindu Gadupudi 2018-04-26 14:17:09 -07:00 committed by Facebook Github Bot
parent de08f4ab6c
commit 2e7dbc82b3
1 changed files with 4 additions and 2 deletions

View File

@ -160,8 +160,10 @@ public class FrescoBasedReactTextInlineImageSpan extends TextInlineImageSpan {
canvas.save();
// Align to baseline by default
int transY = y - mDrawable.getBounds().bottom;
// Align to center
int fontHeight = (int)(paint.descent() - paint.ascent());
int centerY = y + (int)paint.descent() - fontHeight / 2;
int transY = centerY - (mDrawable.getBounds().bottom - mDrawable.getBounds().top) / 2;
canvas.translate(x, transY);
mDrawable.draw(canvas);