mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-28 04:55:12 +00:00
fix(android): deprecation warning in TSpanView
This commit is contained in:
@@ -142,28 +142,10 @@ class TSpanView extends TextView {
|
||||
break;
|
||||
}
|
||||
|
||||
StaticLayout layout;
|
||||
boolean includeFontPadding = true;
|
||||
SpannableString text = new SpannableString(mContent);
|
||||
final double width = PropHelper.fromRelative(mInlineSize, canvas.getWidth(), 0, mScale, fontSize);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
layout = new StaticLayout(
|
||||
text,
|
||||
tp,
|
||||
(int)width,
|
||||
align,
|
||||
1.f,
|
||||
0.f,
|
||||
includeFontPadding);
|
||||
} else {
|
||||
layout = StaticLayout.Builder.obtain(text, 0, text.length(), tp, (int)width)
|
||||
.setAlignment(align)
|
||||
.setLineSpacing(0.f, 1.f)
|
||||
.setIncludePad(includeFontPadding)
|
||||
.setBreakStrategy(Layout.BREAK_STRATEGY_HIGH_QUALITY)
|
||||
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL)
|
||||
.build();
|
||||
}
|
||||
StaticLayout layout = getStaticLayout(tp, align, includeFontPadding, text, (int) width);
|
||||
|
||||
int lineAscent = layout.getLineAscent(0);
|
||||
|
||||
@@ -177,6 +159,28 @@ class TSpanView extends TextView {
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private StaticLayout getStaticLayout(TextPaint tp, Layout.Alignment align, boolean includeFontPadding, SpannableString text, int width) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
return new StaticLayout(
|
||||
text,
|
||||
tp,
|
||||
width,
|
||||
align,
|
||||
1.f,
|
||||
0.f,
|
||||
includeFontPadding);
|
||||
} else {
|
||||
return StaticLayout.Builder.obtain(text, 0, text.length(), tp, width)
|
||||
.setAlignment(align)
|
||||
.setLineSpacing(0.f, 1.f)
|
||||
.setIncludePad(includeFontPadding)
|
||||
.setBreakStrategy(Layout.BREAK_STRATEGY_HIGH_QUALITY)
|
||||
.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_NORMAL)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements visual to logical order converter.
|
||||
|
||||
Reference in New Issue
Block a user