Redefine hashcode for AttributedString

Summary:
This diff changes the method to calculate the hash of an AttributedString (removing shadowNode and parentShadowNode from it).
This is necessary becuase otherwise hashcode of clonned parent keep changing in every state change, when the text doesnt change

With this change we are able to cache spannables in android properly

Reviewed By: shergin

Differential Revision: D13189110

fbshipit-source-id: c1f7372809ce98a5b4d091485cc15281a4ab5e1e
This commit is contained in:
David Vacca 2018-11-25 17:18:12 -08:00 committed by Facebook Github Bot
parent f341795824
commit 89f647d521
2 changed files with 2 additions and 5 deletions

View File

@ -164,6 +164,7 @@ public class TextLayoutManager {
synchronized (sSpannableCacheLock) {
preparedSpannableText = sSpannableCache.get(hash);
//TODO: T31905686 the hash does not guarantee equality of texts
if (preparedSpannableText != null) {
return preparedSpannableText;
}

View File

@ -89,11 +89,7 @@ struct hash<facebook::react::AttributedString::Fragment> {
size_t operator()(
const facebook::react::AttributedString::Fragment &fragment) const {
return std::hash<decltype(fragment.string)>{}(fragment.string) +
std::hash<decltype(fragment.textAttributes)>{}(
fragment.textAttributes) +
std::hash<decltype(fragment.shadowNode)>{}(fragment.shadowNode) +
std::hash<decltype(fragment.parentShadowNode)>{}(
fragment.parentShadowNode);
std::hash<decltype(fragment.textAttributes)>{}(fragment.textAttributes);
}
};