Add support for animated effects on spans of text#56702
Closed
andrewdacenko wants to merge 2 commits intofacebook:mainfrom
Closed
Add support for animated effects on spans of text#56702andrewdacenko wants to merge 2 commits intofacebook:mainfrom
andrewdacenko wants to merge 2 commits intofacebook:mainfrom
Conversation
… isolation (facebook#56688) Summary: `PreparedLayoutTextView` can receive shared `PreparedLayout` instances from a C++ LRU cache. Multiple views rendering identical text share the same `Layout` → `Spannable` → span objects. Stateless spans are fine to share, but stateful spans like `SpoilerEffectSpan` (particles, dismiss state) would have one view's tap-dismiss corrupt all other views sharing that layout. Introduces a `StatefulSpan` marker interface whose presence tells `PreparedLayoutTextView` to clone the spannable with fresh span instances. The Layout is reused via a delegating subclass (`MutableSpannableLayout`) that passes the cloned Spannable to `Layout`'s protected constructor and delegates all line metrics to the original. The mutable Spannable can be useful for spans which affect display, but do not alter existing layout calculations. No StaticLayout rebuild needed. Performance: Only views with stateful spans pay the cost. `getSpans()` is O(spans), `SpannableString` copy is O(text+spans). Views without `StatefulSpan` are completely unchanged. Changelog: [internal] Reviewed By: alanleedev Differential Revision: D97415850
Summary: Adds `AnimatedEffectSpan`, a new span type for animated effects drawn on top of text in `PreparedLayoutTextView`. Unlike `DrawCommandSpan` which provides static `onPreDraw`/`onDraw` hooks, `AnimatedEffectSpan` supports animation via a `requestAnimationFrame`-style API where the span receives a time delta each frame and returns whether it wants another frame. Key design decisions: - Independent from `DrawCommandSpan` — does not subclass it - Does not implement `UpdateAppearance` — animated effects don't affect text measurement or paint state - Implements `ReactSpan` for integration with RN's span management - Annotated `UnstableReactNativeAPI` — callers must opt in - Zero overhead for non-animated text: delta computation and frame scheduling only happen when animated spans exist - Frame timing resets on visibility changes and view recycling to prevent delta spikes Changelog: [Internal] Reviewed By: alanleedev Differential Revision: D97399151
|
@andrewdacenko has exported this pull request. If you are a Meta employee, you can view the originating Diff in D97399151. |
Collaborator
|
This pull request was successfully merged by @andrewdacenko in 71a0d5d When will my fix make it into a release? | How to file a pick request? |
|
This pull request has been merged in 71a0d5d. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Adds
AnimatedEffectSpan, a new span type for animated effects drawn on topof text in
PreparedLayoutTextView. UnlikeDrawCommandSpanwhich providesstatic
onPreDraw/onDrawhooks,AnimatedEffectSpansupports animation viaa
requestAnimationFrame-style API where the span receives a time delta eachframe and returns whether it wants another frame.
Key design decisions:
DrawCommandSpan— does not subclass itUpdateAppearance— animated effects don't affect text measurement or paint stateReactSpanfor integration with RN's span managementUnstableReactNativeAPI— callers must opt inChangelog: [Internal]
Reviewed By: alanleedev
Differential Revision: D97399151