-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShaderBrush#createShader state reads do not invalidate Text composable #4903
ShaderBrush#createShader state reads do not invalidate Text composable #4903
Comments
Looks like we need to apply (androidx/androidx@1631196) to |
Unfortunately the fix from mentioned commit won't work for CMP because unlike Android we do not control |
😭 |
Adopted it with re-layouting in JetBrains/compose-multiplatform-core#1395 |
- Adopt androidx@1631196 change - Use `paragraph.updateForegroundPaint` instead of full rebuild where possible Fixes JetBrains/compose-multiplatform#4903 ## Testing Added `Android TextBrushDemo` in mpp demo <img width="1029" alt="Screenshot 2024-06-07 at 19 21 39" src="https://github.com/JetBrains/compose-multiplatform-core/assets/1836384/97d17949-e743-4774-ae55-cab664412091"> This should be tested by QA ## Release Notes ### Fixes - Multiple Platforms - Fix text `brush` animation and optimized updating some visual text properties (applying time is reduced up to 40%)
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Describe the bug
Brush instances created using the abstract
ShaderBrush
class, does not animate when applied on Text.Affected platforms
Only tested on;
Versions
To Reproduce
Steps to reproduce the behavior:
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/text/BrushDemo.kt;l=204-233
Expected behavior
Expecting text to have an animated brush coloring.
Additional context
Android handles this by creating the shader in a
derivedStateOf
. This way any state read that happens increateShader
invalidates the derived state and only re-runs the draw phase. Otherwise devs need to change the brush instance for every animation frame which can get very costly due to unnecessary recomposition.https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-text/src/androidMain/kotlin/androidx/compose/ui/text/platform/AndroidTextPaint.android.kt;l=111-143
The text was updated successfully, but these errors were encountered: