Skip to content

Commit

Permalink
Fix TouchEvents on text after state changes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdvacca authored and facebook-github-bot committed Nov 27, 2018
1 parent d3f3bfa commit 00681c3
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -159,20 +159,19 @@ protected static Spannable getOrCreateSpannableForText(
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;
}
}

preparedSpannableText = createSpannableFromAttributedString(context, attributedString);
synchronized (sSpannableCacheLock) {
sSpannableCache.put(hash, preparedSpannableText);
sSpannableCache.put(attributedStringPayload, preparedSpannableText);
}
return preparedSpannableText;
}
Expand Down

0 comments on commit 00681c3

Please sign in to comment.