Skip to content

Comments

Fix mis-use of PlatformContext.Empty#2548

Merged
m-sasha merged 8 commits intojb-mainfrom
m-sasha/fix-platformcontext-empty
Nov 4, 2025
Merged

Fix mis-use of PlatformContext.Empty#2548
m-sasha merged 8 commits intojb-mainfrom
m-sasha/fix-platformcontext-empty

Conversation

@m-sasha
Copy link

@m-sasha m-sasha commented Nov 3, 2025

Replace PlatformContext.Empty with PlatformContext.Base() and make it a regular superclass of most implementations.

Fixes https://youtrack.jetbrains.com/issue/CMP-9195

Testing

Added a unit test to make sure the input mode is reset between tests.

Release Notes

Fixes - Multiple Platforms

  • Fixed LocalInputModeManager.current.inputMode not being reset between tests.

@m-sasha m-sasha requested review from ASalavei and igordmn November 3, 2025 19:08
@igordmn
Copy link
Collaborator

igordmn commented Nov 3, 2025

Besides the name - LGTM

Copy link
Member

@MatkovIvan MatkovIvan left a comment

Choose a reason for hiding this comment

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

I'm ok with converting Empty object to class, but API shape/naming requires some polishing


public final class androidx/compose/ui/platform/PlatformContext$Companion {
public final fun getEmpty ()Landroidx/compose/ui/platform/PlatformContext;
public class androidx/compose/ui/platform/PlatformContext$Base : androidx/compose/ui/platform/PlatformContext {
Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't be in API dump - please make sure that proper opt-in is applied

Copy link
Author

Choose a reason for hiding this comment

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

What proper opt-in? Do you mean @InternalComposeUiApi annotation?

PlatformContext.Empty was in the API dump. Now PlatformContext.Base is in the API dump. Several other types scoped to PlatformContext are also in the API dump (RootForTestListener). If you think they shouldn't be, we can fix all of them in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

Please do it at least for new types in this PR.
Others might be done separately

Copy link
Author

Choose a reason for hiding this comment

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

Done


// This object must be stateless because it is used as a delegate in other ViewConfiguration
// implementations
object EmptyViewConfiguration : ViewConfiguration {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure that exposing it like this makes sense from API point of view. Previously it was a getter of specific implementation, but now it's an API itself.
Why it's an object inside PlatformContext interface?
Also, as API it requres KDoc now

Copy link
Author

Choose a reason for hiding this comment

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

It's all under @InternalComposeUiApi interface PlatformContext, so presumably it's internal compose API.
PlatformContext.Empty had no KDoc, many properties in PlatformContext have no KDoc.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's semi-public but still it's used for cross modules and cross platforms, so it's better to add clarifications for teammates.
It's not a requirement, but good practice

Copy link
Author

Choose a reason for hiding this comment

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

KDocs are needed for APIs that are intended to be used by the general public. For internal APIs it's not important whether they're used across modules. It's only important if there's something unusual that needs to be explained, and here there isn't - it's pattern used in many of other places, including 5 more times in this very file.

}

override val inputModeManager = DefaultInputModeManager()
open class Base : PlatformContext {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to declare it inside interface?
Also, missing KDoc

Copy link
Author

Choose a reason for hiding this comment

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

We don't need to, but I like that it's scoped to PlatformContext. In my opinion PlatformContext.Base is better than BasePlatformContext. It's more discoverable, and it doesn't pollute the global scope.

@m-sasha m-sasha force-pushed the m-sasha/fix-platformcontext-empty branch from 3eca6f2 to f2c6f34 Compare November 3, 2025 20:59
@m-sasha m-sasha requested review from MatkovIvan and igordmn November 4, 2025 09:37
@m-sasha m-sasha merged commit a54e0da into jb-main Nov 4, 2025
16 checks passed
@m-sasha m-sasha deleted the m-sasha/fix-platformcontext-empty branch November 4, 2025 13:11
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.

3 participants