forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Move the effects and synthetic events dispatching to after the draw phase in the render loop. #1260
Merged
Conversation
This file contains 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
…hase in the render loop.
… no longer valid and others are in RenderPhasesTest
… deprecated `ComposeScene`.
… send synthetic events, as that now happens automatically via recomposer.hasPendingWork
igordmn
approved these changes
Apr 11, 2024
MatkovIvan
approved these changes
Apr 11, 2024
igordmn
added a commit
that referenced
this pull request
Apr 24, 2024
Fixes JetBrains/compose-multiplatform#4681 The issue was because of this situation: - the parent RenderNodeLayer is drawn and cached it's `picture` - the child RenderNodeLayer isn't drawn, but `invalidate` is called the child's `invalidate` should invalidate parent layer unconditionally, but we called it only if the child was drawn (picture != null), which is incorrect. It is a regression after #1260, but it just revealed the bug, not introduced it. ## Testing - new added tests fail before, work after the fix - the issue is no longer reproducible This should be tested by QA ## Release Notes > Fixes - Multiple Platforms - _(prerelease fix)_ Fix frozen composition with pager and text field
igordmn
added a commit
that referenced
this pull request
Apr 25, 2024
Fixes JetBrains/compose-multiplatform#4681 The issue was because of this situation: - the parent RenderNodeLayer is drawn and cached it's `picture` - the child RenderNodeLayer isn't drawn, but `invalidate` is called `invalidate` should have updated the parent layer (removing the `picture` cache), but didn't do that as we do that conditionally. Now `invalidate` invalidates the parent layer unconditionally. It is a regression after #1260, but it just revealed the bug, didn't introduce it. ## Testing - new added tests fail before, work after the fix - the issue is no longer reproducible This should be tested by QA ## Release Notes > Fixes - Multiple Platforms - _(prerelease fix)_ Fix frozen composition with pager and text field
igordmn
added a commit
that referenced
this pull request
Jan 13, 2025
The changes were added to avoid input lag during scrolling on hoverable items: #188 But after that we introduced another change - flush all effects before each frame (#1260): ``` BaseComposeScene { override fun render(canvas: Canvas, nanoTime: Long) { recomposer.performScheduledEffects() ... } } ``` This makes the first fix not needed. ## Testing ``` import androidx.compose.foundation.background import androidx.compose.foundation.hoverable import androidx.compose.foundation.interaction.HoverInteraction import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.window.singleWindowApplication fun main() { singleWindowApplication { Test() } } @composable private fun Test() { LazyColumn { items((0..200).toList()) { val interactionSource = remember { MutableInteractionSource() } var hovered by remember { mutableStateOf(false) } LaunchedEffect(interactionSource) { interactionSource.interactions.collect { interaction -> when (interaction) { is HoverInteraction.Enter -> hovered = true is HoverInteraction.Exit -> hovered = false } } } Text( it.toString(), Modifier .background(if (hovered) Color.Blue else Color.White) .hoverable(interactionSource) .height(20.dp) .fillMaxWidth() ) } } } ``` Scroll without moving - see that latency of hovers didn't change compared to the jb-main state
igordmn
added a commit
that referenced
this pull request
Jan 13, 2025
Reverted to https://github.com/androidx/androidx/blob/6c04a79c5c3a5fdb6d5221eb344fe1ed98227957/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Hoverable.kt#L89 The changes were added to avoid input lag during scrolling on hoverable items: #188 But after that we introduced another change - flush all effects before each frame (#1260): ``` BaseComposeScene { override fun render(canvas: Canvas, nanoTime: Long) { recomposer.performScheduledEffects() ... } } ``` This makes the first fix not needed. ## Testing ``` import androidx.compose.foundation.background import androidx.compose.foundation.hoverable import androidx.compose.foundation.interaction.HoverInteraction import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.window.singleWindowApplication fun main() { singleWindowApplication { Test() } } @composable private fun Test() { LazyColumn { items((0..200).toList()) { val interactionSource = remember { MutableInteractionSource() } var hovered by remember { mutableStateOf(false) } LaunchedEffect(interactionSource) { interactionSource.interactions.collect { interaction -> when (interaction) { is HoverInteraction.Enter -> hovered = true is HoverInteraction.Exit -> hovered = false } } } Text( it.toString(), Modifier .background(if (hovered) Color.Blue else Color.White) .hoverable(interactionSource) .height(20.dp) .fillMaxWidth() ) } } } ``` Scroll without moving - see that latency of hovers didn't change compared to the jb-main state ## Release Notes N/A
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.
While investigating this, we've discovered that
LazyColumn
moves its elements synchronously when scrolled (only if the scrolling causes new items to become visible).Additionally, we currently run coroutines launched in a composition's
rememberCoroutineScope
between the layout and draw phases (due to #1034 and our desire to send the synthetic events before the draw phase, to avoid a one-frame delay when scrolling a list that highlights the item under the mouse).Together these two create a problem (visible in the video linked above) because when the
LazyColumn
is scrolled from a launched coroutine, it moves its element to the position where they would normally appear only on the next frame, which causes a visible "jump".Proposed Changes
After much consideration (with @igordmn) we decided to strictly adhere to the ordering of the phases as they are done on Android:
render
completes).render
completes.render
) scheduled composition effects.render
) scheduled synthetic events.Testing
Test: Tested the "jumpy" lazy column manually, and added unit tests to verify the order of the render phases.
The manual test:
This PR should be verified by QA.
Issues Fixed
Possibly fixes JetBrains/compose-multiplatform#4438