Skip to content

Commit 9c1eaef

Browse files
committed
Fix extreme TextInput slowness on Android
This reverts 5898817 "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a controlled TextInput after some text is first added, then deleted, further interaction with the TextInput becomes extremely slow. Fixes #19126.
1 parent 4aeefa5 commit 9c1eaef

File tree

8 files changed

+0
-194
lines changed

8 files changed

+0
-194
lines changed

RNTester/js/TextExample.android.js

-39
Original file line numberDiff line numberDiff line change
@@ -360,45 +360,6 @@ class TextExample extends React.Component<{}> {
360360
magnetic potentialities rather than client-focused interfaces.
361361
</Text>
362362
</RNTesterBlock>
363-
<RNTesterBlock title="Letter Spacing">
364-
<View>
365-
<Text style={{letterSpacing: 0}}>letterSpacing = 0</Text>
366-
<Text style={{letterSpacing: 2, marginTop: 5}}>
367-
letterSpacing = 2
368-
</Text>
369-
<Text style={{letterSpacing: 9, marginTop: 5}}>
370-
letterSpacing = 9
371-
</Text>
372-
<View style={{flexDirection: 'row'}}>
373-
<Text
374-
style={{
375-
fontSize: 12,
376-
letterSpacing: 2,
377-
backgroundColor: 'fuchsia',
378-
marginTop: 5,
379-
}}>
380-
With size and background color
381-
</Text>
382-
</View>
383-
<Text style={{letterSpacing: -1, marginTop: 5}}>
384-
letterSpacing = -1
385-
</Text>
386-
<Text
387-
style={{
388-
letterSpacing: 3,
389-
backgroundColor: '#dddddd',
390-
marginTop: 5,
391-
}}>
392-
[letterSpacing = 3]
393-
<Text style={{letterSpacing: 0, backgroundColor: '#bbbbbb'}}>
394-
[Nested letterSpacing = 0]
395-
</Text>
396-
<Text style={{letterSpacing: 6, backgroundColor: '#eeeeee'}}>
397-
[Nested letterSpacing = 6]
398-
</Text>
399-
</Text>
400-
</View>
401-
</RNTesterBlock>
402363
<RNTesterBlock title="Empty Text">
403364
<Text />
404365
</RNTesterBlock>

RNTester/js/TextExample.ios.js

-25
Original file line numberDiff line numberDiff line change
@@ -583,34 +583,9 @@ exports.examples = [
583583
<Text style={{letterSpacing: 9, marginTop: 5}}>
584584
letterSpacing = 9
585585
</Text>
586-
<View style={{flexDirection: 'row'}}>
587-
<Text
588-
style={{
589-
fontSize: 12,
590-
letterSpacing: 2,
591-
backgroundColor: 'fuchsia',
592-
marginTop: 5,
593-
}}>
594-
With size and background color
595-
</Text>
596-
</View>
597586
<Text style={{letterSpacing: -1, marginTop: 5}}>
598587
letterSpacing = -1
599588
</Text>
600-
<Text
601-
style={{
602-
letterSpacing: 3,
603-
backgroundColor: '#dddddd',
604-
marginTop: 5,
605-
}}>
606-
[letterSpacing = 3]
607-
<Text style={{letterSpacing: 0, backgroundColor: '#bbbbbb'}}>
608-
[Nested letterSpacing = 0]
609-
</Text>
610-
<Text style={{letterSpacing: 6, backgroundColor: '#eeeeee'}}>
611-
[Nested letterSpacing = 6]
612-
</Text>
613-
</Text>
614589
</View>
615590
);
616591
},

RNTester/js/TextInputExample.android.js

-25
Original file line numberDiff line numberDiff line change
@@ -576,31 +576,6 @@ exports.examples = [
576576
);
577577
},
578578
},
579-
{
580-
title: 'letterSpacing',
581-
render: function() {
582-
return (
583-
<View>
584-
<TextInput
585-
style={[styles.singleLine, {letterSpacing: 0}]}
586-
placeholder="letterSpacing = 0"
587-
/>
588-
<TextInput
589-
style={[styles.singleLine, {letterSpacing: 2}]}
590-
placeholder="letterSpacing = 2"
591-
/>
592-
<TextInput
593-
style={[styles.singleLine, {letterSpacing: 9}]}
594-
placeholder="letterSpacing = 9"
595-
/>
596-
<TextInput
597-
style={[styles.singleLine, {letterSpacing: -1}]}
598-
placeholder="letterSpacing = -1"
599-
/>
600-
</View>
601-
);
602-
},
603-
},
604579
{
605580
title: 'Passwords',
606581
render: function() {

ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewProps.java

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public class ViewProps {
8888
public static final String FONT_STYLE = "fontStyle";
8989
public static final String FONT_FAMILY = "fontFamily";
9090
public static final String LINE_HEIGHT = "lineHeight";
91-
public static final String LETTER_SPACING = "letterSpacing";
9291
public static final String NEEDS_OFFSCREEN_ALPHA_COMPOSITING = "needsOffscreenAlphaCompositing";
9392
public static final String NUMBER_OF_LINES = "numberOfLines";
9493
public static final String ELLIPSIZE_MODE = "ellipsizeMode";

ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLetterSpacingSpan.java

-51
This file was deleted.

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

-20
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,6 @@ private static void buildSpannedFromShadowNode(
118118
new SetSpanOperation(
119119
start, end, new BackgroundColorSpan(textShadowNode.mBackgroundColor)));
120120
}
121-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
122-
if (textShadowNode.mLetterSpacing != Float.NaN) {
123-
ops.add(new SetSpanOperation(
124-
start,
125-
end,
126-
new CustomLetterSpacingSpan(textShadowNode.mLetterSpacing)));
127-
}
128-
}
129121
if (textShadowNode.mFontSize != UNSET) {
130122
ops.add(new SetSpanOperation(start, end, new AbsoluteSizeSpan(textShadowNode.mFontSize)));
131123
}
@@ -236,7 +228,6 @@ private static int parseNumericFontWeight(String fontWeightString) {
236228
}
237229

238230
protected float mLineHeight = Float.NaN;
239-
protected float mLetterSpacing = Float.NaN;
240231
protected boolean mIsColorSet = false;
241232
protected boolean mAllowFontScaling = true;
242233
protected int mColor;
@@ -247,7 +238,6 @@ private static int parseNumericFontWeight(String fontWeightString) {
247238
protected int mFontSize = UNSET;
248239
protected float mFontSizeInput = UNSET;
249240
protected float mLineHeightInput = UNSET;
250-
protected float mLetterSpacingInput = Float.NaN;
251241
protected int mTextAlign = Gravity.NO_GRAVITY;
252242
protected int mTextBreakStrategy =
253243
(Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ? 0 : Layout.BREAK_STRATEGY_HIGH_QUALITY;
@@ -366,22 +356,12 @@ public void setLineHeight(float lineHeight) {
366356
markUpdated();
367357
}
368358

369-
@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = Float.NaN)
370-
public void setLetterSpacing(float letterSpacing) {
371-
mLetterSpacingInput = letterSpacing;
372-
mLetterSpacing = mAllowFontScaling
373-
? PixelUtil.toPixelFromSP(mLetterSpacingInput)
374-
: PixelUtil.toPixelFromDIP(mLetterSpacingInput);
375-
markUpdated();
376-
}
377-
378359
@ReactProp(name = ViewProps.ALLOW_FONT_SCALING, defaultBoolean = true)
379360
public void setAllowFontScaling(boolean allowFontScaling) {
380361
if (allowFontScaling != mAllowFontScaling) {
381362
mAllowFontScaling = allowFontScaling;
382363
setFontSize(mFontSizeInput);
383364
setLineHeight(mLineHeightInput);
384-
setLetterSpacing(mLetterSpacingInput);
385365
markUpdated();
386366
}
387367
}

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java

-25
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import android.widget.EditText;
3434
import com.facebook.infer.annotation.Assertions;
3535
import com.facebook.react.bridge.ReactContext;
36-
import com.facebook.react.uimanager.PixelUtil;
3736
import com.facebook.react.uimanager.UIManagerModule;
3837
import com.facebook.react.views.text.CustomStyleSpan;
3938
import com.facebook.react.views.text.ReactTagSpan;
@@ -82,7 +81,6 @@ public class ReactEditText extends EditText {
8281
private final InternalKeyListener mKeyListener;
8382
private boolean mDetectScrollMovement = false;
8483
private boolean mOnKeyPress = false;
85-
private float mLetterSpacingPt = 0;
8684

8785
private ReactViewBackgroundManager mReactBackgroundManager;
8886

@@ -634,29 +632,6 @@ public void setBorderStyle(@Nullable String style) {
634632
mReactBackgroundManager.setBorderStyle(style);
635633
}
636634

637-
public void setLetterSpacingPt(float letterSpacingPt) {
638-
mLetterSpacingPt = letterSpacingPt;
639-
updateLetterSpacing();
640-
}
641-
642-
@Override
643-
public void setTextSize (float size) {
644-
super.setTextSize(size);
645-
updateLetterSpacing();
646-
}
647-
648-
@Override
649-
public void setTextSize (int unit, float size) {
650-
super.setTextSize(unit, size);
651-
updateLetterSpacing();
652-
}
653-
654-
protected void updateLetterSpacing() {
655-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
656-
setLetterSpacing(PixelUtil.toPixelFromSP(mLetterSpacingPt) / getTextSize());
657-
}
658-
}
659-
660635
/**
661636
* This class will redirect *TextChanged calls to the listeners only in the case where the text
662637
* is changed by the user, and not explicitly set by JS.

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

-8
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,6 @@ public void setOnKeyPress(final ReactEditText view, boolean onKeyPress) {
314314
view.setOnKeyPress(onKeyPress);
315315
}
316316

317-
// Sets the letter spacing as an absolute point size.
318-
// This extra handling, on top of what ReactBaseTextShadowNode already does, is required for the
319-
// correct display of spacing in placeholder (hint) text.
320-
@ReactProp(name = ViewProps.LETTER_SPACING, defaultFloat = 0)
321-
public void setLetterSpacing(ReactEditText view, float letterSpacing) {
322-
view.setLetterSpacingPt(letterSpacing);
323-
}
324-
325317
@ReactProp(name = "placeholder")
326318
public void setPlaceholder(ReactEditText view, @Nullable String placeholder) {
327319
view.setHint(placeholder);

0 commit comments

Comments
 (0)