-
Notifications
You must be signed in to change notification settings - Fork 27
Animations: Remove "phrases" and sync markdown UI elements with text #42
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.halilibo.richtext.ui | ||
|
|
||
| import androidx.compose.animation.core.animateFloatAsState | ||
| import androidx.compose.animation.core.tween | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.State | ||
| import androidx.compose.runtime.mutableFloatStateOf | ||
| import androidx.compose.runtime.remember | ||
| import com.halilibo.richtext.ui.string.MarkdownAnimationState | ||
| import com.halilibo.richtext.ui.string.RichTextRenderOptions | ||
|
|
||
| @Composable | ||
| internal fun rememberMarkdownFade( | ||
| richTextRenderOptions: RichTextRenderOptions, | ||
| markdownAnimationState: MarkdownAnimationState, | ||
| ): State<Float> { | ||
| val targetAlpha = remember { | ||
| mutableFloatStateOf(if (richTextRenderOptions.animate) 0f else 1f) | ||
| } | ||
| LaunchedEffect(Unit) { | ||
| targetAlpha.value = 1f | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this code was just moved, but we would skip a recomposition step by using a simple |
||
| } | ||
| val alpha = animateFloatAsState( | ||
| targetAlpha.value, | ||
| tween( | ||
| durationMillis = richTextRenderOptions.textFadeInMs, | ||
| delayMillis = markdownAnimationState.toDelayMs(), | ||
| ) | ||
| ) | ||
| LaunchedEffect(Unit) { | ||
| markdownAnimationState.addAnimation(richTextRenderOptions) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to unregister it?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addAnimation only ticks the delay counter up, we don't need to unregister it globally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha |
||
| } | ||
| return alpha | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using .graphicsLayer { } block to defer animated value reads to the draw phase would improve perf