Fix incorrect hit testing on text when layout reused #52692
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
D77341994 added a global cache for Facsimile layouts, where we will reuse an existing
android.text.Layout
, andSpannable
, if one already existed for a same AttributedString, under same layout constraints. An error here, is that we consider a layout reusable, even when shadow views are different, which means there may be different react tags in the underlying AttributedString.This leaks into the layout itself, and means that if a layout is reused, we can hit test against a stale/incorrect react tag.
The solution to allow reuse here, is to avoid embedding react tag directly into the
android.text.Layout
structure. Instead, we replace references to react tags, with a fragment index, and embed the list of fragment indices in each PreparedLayout. We can hide this "cleverness" within the boundary ofTextLayoutManager
, such that an invalidPreparedLayout
is never allowed to escape.Changelog: [Internal]
Differential Revision: D78516079