Skip to content

Commit 2a5cda4

Browse files
gnpriceSamuel Nelson
authored and
Samuel Nelson
committed
Fix extreme TextInput slowness on Android
Because NaN is special, the `!=` version of this condition will always be true -- even if `mLetterSpacing` is also `Float.NaN`, which is its default value. It should instead be `!Float.isNaN(...)`. The effect of the broken condition is that every text shadow node will create a `CustomLetterSpacingSpan` around its contents, even when the `letterSpacing` prop was never set. Empirically, that in turn causes facebook#19126: in a controlled TextInput after some text is first added, then deleted, further interaction with the TextInput becomes extremely slow. Perhaps we're somehow ending up with large numbers of these shadow nodes (that sounds like a bug in itself, but I guess it's normally low-impact); then this code would have caused them each to generate more work to do. In any case, fixing this condition causes that issue to disappear. The affected logic was introduced between v0.54 and v0.55, in facebook#17398 aka 5898817 "Implement letterSpacing on Android >= 5.0". Fixes facebook#19126.
1 parent 370bcff commit 2a5cda4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static void buildSpannedFromShadowNode(
119119
start, end, new BackgroundColorSpan(textShadowNode.mBackgroundColor)));
120120
}
121121
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
122-
if (textShadowNode.mLetterSpacing != Float.NaN) {
122+
if (!Float.isNaN(textShadowNode.mLetterSpacing)) {
123123
ops.add(new SetSpanOperation(
124124
start,
125125
end,

0 commit comments

Comments
 (0)