mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-18 12:12:15 +08:00
Cache CustomStyleSpan in RCTVirtualText
Summary: @public `RCTVirtualText` is creating a new `CustomStyleSpan` on every `applySpans()` call, which is not very efficient. We can cache and reuse unchanged `CustomStyleSpans` for efficiency. This patch is doing just that. Reviewed By: sriramramani Differential Revision: D2564366
This commit is contained in:
committed by
Ahmed El-Helw
parent
007318eb52
commit
fbe1b61fe1
@@ -17,16 +17,22 @@ import android.text.style.MetricAffectingSpan;
|
||||
|
||||
/* package */ final class FontStylingSpan extends MetricAffectingSpan {
|
||||
// text property
|
||||
private final double mTextColor;
|
||||
private final int mBackgroundColor;
|
||||
private double mTextColor = Double.NaN;
|
||||
private int mBackgroundColor;
|
||||
|
||||
// font properties
|
||||
private final int mFontSize;
|
||||
private final int mFontStyle;
|
||||
private final int mFontWeight;
|
||||
private final @Nullable String mFontFamily;
|
||||
private int mFontSize = -1;
|
||||
private int mFontStyle = -1;
|
||||
private int mFontWeight = -1;
|
||||
private @Nullable String mFontFamily;
|
||||
|
||||
FontStylingSpan(
|
||||
// whether or not mutation is allowed.
|
||||
private boolean mFrozen = false;
|
||||
|
||||
FontStylingSpan() {
|
||||
}
|
||||
|
||||
private FontStylingSpan(
|
||||
double textColor,
|
||||
int backgroundColor,
|
||||
int fontSize,
|
||||
@@ -41,6 +47,72 @@ import android.text.style.MetricAffectingSpan;
|
||||
mFontFamily = fontFamily;
|
||||
}
|
||||
|
||||
/* package */ FontStylingSpan mutableCopy() {
|
||||
return new FontStylingSpan(
|
||||
mTextColor,
|
||||
mBackgroundColor,
|
||||
mFontSize,
|
||||
mFontStyle,
|
||||
mFontWeight,
|
||||
mFontFamily);
|
||||
}
|
||||
|
||||
/* package */ boolean isFrozen() {
|
||||
return mFrozen;
|
||||
}
|
||||
|
||||
/* package */ void freeze() {
|
||||
mFrozen = true;
|
||||
}
|
||||
|
||||
/* package */ double getTextColor() {
|
||||
return mTextColor;
|
||||
}
|
||||
|
||||
/* package */ void setTextColor(double textColor) {
|
||||
mTextColor = textColor;
|
||||
}
|
||||
|
||||
/* package */ int getBackgroundColor() {
|
||||
return mBackgroundColor;
|
||||
}
|
||||
|
||||
/* package */ void setBackgroundColor(int backgroundColor) {
|
||||
mBackgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
/* package */ int getFontSize() {
|
||||
return mFontSize;
|
||||
}
|
||||
|
||||
/* package */ void setFontSize(int fontSize) {
|
||||
mFontSize = fontSize;
|
||||
}
|
||||
|
||||
/* package */ int getFontStyle() {
|
||||
return mFontStyle;
|
||||
}
|
||||
|
||||
/* package */ void setFontStyle(int fontStyle) {
|
||||
mFontStyle = fontStyle;
|
||||
}
|
||||
|
||||
/* package */ int getFontWeight() {
|
||||
return mFontWeight;
|
||||
}
|
||||
|
||||
/* package */ void setFontWeight(int fontWeight) {
|
||||
mFontWeight = fontWeight;
|
||||
}
|
||||
|
||||
/* package */ @Nullable String getFontFamily() {
|
||||
return mFontFamily;
|
||||
}
|
||||
|
||||
/* package */ void setFontFamily(@Nullable String fontFamily) {
|
||||
mFontFamily = fontFamily;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDrawState(TextPaint ds) {
|
||||
if (!Double.isNaN(mTextColor)) {
|
||||
|
||||
Reference in New Issue
Block a user