Fix TouchEvents on text after state changes

Summary:
This diff fixes a bug that produces TouchEvents on text to stop working after a react state has happened.
An easy way to reproduce this is opening a YellowBox, minimizing it and trying to open it again

Reviewed By: shergin

Differential Revision: D13198663

fbshipit-source-id: 19b08818bbff8014ab8227b3db1119edc4193389
This commit is contained in:
David Vacca 2018-11-27 11:48:58 -08:00 committed by Facebook Github Bot
parent d3f3bfa2a5
commit 00681c3660

View File

@ -50,7 +50,7 @@ public class TextLayoutManager {
private static final int spannableCacheSize = 100;
private static final Object sSpannableCacheLock = new Object();
private static LruCache<Double, Spannable> sSpannableCache = new LruCache<>(spannableCacheSize);
private static LruCache<String, Spannable> sSpannableCache = new LruCache<>(spannableCacheSize);
private static void buildSpannableFromFragment(
Context context,
@ -159,12 +159,11 @@ public class TextLayoutManager {
Context context,
ReadableMap attributedString) {
Double hash = attributedString.getDouble("hash");
Spannable preparedSpannableText;
String attributedStringPayload = attributedString.toString();
synchronized (sSpannableCacheLock) {
preparedSpannableText = sSpannableCache.get(hash);
//TODO: T31905686 the hash does not guarantee equality of texts
preparedSpannableText = sSpannableCache.get(attributedStringPayload);
//TODO: T31905686 implement proper equality of attributedStrings
if (preparedSpannableText != null) {
return preparedSpannableText;
}
@ -172,7 +171,7 @@ public class TextLayoutManager {
preparedSpannableText = createSpannableFromAttributedString(context, attributedString);
synchronized (sSpannableCacheLock) {
sSpannableCache.put(hash, preparedSpannableText);
sSpannableCache.put(attributedStringPayload, preparedSpannableText);
}
return preparedSpannableText;
}