mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 16:04:38 +00:00
Improve text subtree advance calculation caching
This commit is contained in:
@@ -108,6 +108,9 @@ class TSpanView extends TextView {
|
||||
}
|
||||
|
||||
double getSubtreeTextChunksTotalAdvance(Paint paint) {
|
||||
if (!Double.isNaN(cachedAdvance)) {
|
||||
return cachedAdvance;
|
||||
}
|
||||
double advance = 0;
|
||||
|
||||
if (mContent == null) {
|
||||
@@ -118,6 +121,7 @@ class TSpanView extends TextView {
|
||||
advance += text.getSubtreeTextChunksTotalAdvance(paint);
|
||||
}
|
||||
}
|
||||
cachedAdvance = advance;
|
||||
return advance;
|
||||
}
|
||||
|
||||
@@ -125,6 +129,7 @@ class TSpanView extends TextView {
|
||||
final int length = line.length();
|
||||
|
||||
if (length == 0) {
|
||||
cachedAdvance = 0;
|
||||
return advance;
|
||||
}
|
||||
|
||||
@@ -149,7 +154,8 @@ class TSpanView extends TextView {
|
||||
paint.setLetterSpacing((float)(letterSpacing / (font.fontSize * mScale)));
|
||||
}
|
||||
|
||||
return paint.measureText(line);
|
||||
cachedAdvance = paint.measureText(line);
|
||||
return cachedAdvance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
|
||||
@@ -50,11 +50,15 @@ class TextView extends GroupView {
|
||||
if (mPath == null) {
|
||||
return;
|
||||
}
|
||||
cachedAdvance = Double.NaN;
|
||||
super.invalidate();
|
||||
clearChildCache();
|
||||
}
|
||||
|
||||
void clearCache() {
|
||||
cachedAdvance = Double.NaN;
|
||||
super.clearCache();
|
||||
}
|
||||
|
||||
@ReactProp(name = "textLength")
|
||||
public void setTextLength(Dynamic length) {
|
||||
mTextLength = SVGLength.from(length);
|
||||
|
||||
@@ -101,7 +101,7 @@ abstract public class VirtualView extends ReactViewGroup {
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
private void clearCache() {
|
||||
void clearCache() {
|
||||
canvasDiagonal = -1;
|
||||
canvasHeight = -1;
|
||||
canvasWidth = -1;
|
||||
|
||||
Reference in New Issue
Block a user