mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d602c51996
Summary: Simplify the TextInput measurement mechanism. Now, data only flows from JS->C++->Java and from Java->JS. C++ passes along AttributedStrings from JS if JS updates, and otherwise Java maintains the only source of truth. Previously we tried to keep all three in sync. This was complicated, slow, and even lead to some crashes. This feels a bit hacky but I believe it's the simplest way to achieve this short-term. Ideally, we would use something like `AttributedStringBox` and pass that to State from Java, but currently everything passed through the State system from Java must be serializable as `folly::dynamic`. So, instead, we just cache one Spannable per TextInput component and use ReactTag as the cache identifier for lookup. An interesting side-effect is that `measure` could race with TextInput updates, but the race condition favors measuring the latest text, not outdated values. Followups: - Can we do this without copying the EditText Spannable on every keystroke? Maybe this approach is too aggressive, but I don't want a background thread measuring a Spannable as it's being mutated. - Do we need to support measuring Attachments? - How can we clean up this API? It should work for now, but feels a little hacky. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D23290230 fbshipit-source-id: 832d2f397d30dfb17b77958af970d9c52a37e88b