Skip to content

Conversation

@ASalavei
Copy link

@ASalavei ASalavei commented Dec 16, 2025

Use dedicated coroutine context with separate Job for compose scene.
Use nested coroutine scope tight to the Compose scene context for frame animations.
Make ComposeSceneMediator's lifetime tight to the context.

Fixes https://youtrack.jetbrains.com/issue/CMP-7727/Use-dedicated-coroutine-scopes-for-compose-scenes

Release Notes

N/A

@ASalavei ASalavei requested a review from svastven December 17, 2025 09:09
@ASalavei ASalavei assigned MatkovIvan and unassigned MatkovIvan Dec 17, 2025
@ASalavei ASalavei marked this pull request as ready for review December 17, 2025 09:12
private var activeStateListener: SceneActiveStateListener? = null
val composeCoroutineContext: CoroutineContext = coroutineContext + motionDurationScale

private var sceneJob: Job = Job().also {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this class doesn't operate with the scene directly, I think it's more correct to call it composeJob instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scene's lifetime tight to the sceneJob - the variable name highlights this fact. The composeJob is too generic imo.

Comment on lines +98 to +100
// The initial state of the container considered as "not active".
// The `initializeComposeScene` must be called to set the active `sceneJob`.
it.cancel()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it important? What goes wrong in the case of creating it during class initialization?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment explains it. This scope also used for running animations and other tasks outside the ComposeContainer. It's needed to prevent running any of them before the initialization.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says nothing about animations or reasoning in general

Copy link
Author

@ASalavei ASalavei Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's a good idea because comment will become outdated pretty soon as it isn't connected with the place of use directly.

@ASalavei ASalavei merged commit 743ae73 into jb-main Jan 14, 2026
25 of 26 checks passed
@ASalavei ASalavei deleted the andrei.salavei/dedicated-coroutine-scopes branch January 14, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants