Skip to content
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

fix pointerHoverIcon: update icon when it's changed conditionally #231

Merged
merged 3 commits into from
Jun 7, 2022

Conversation

eymar
Copy link
Collaborator

@eymar eymar commented Jun 3, 2022

@eymar eymar requested a review from igordmn June 3, 2022 14:08
// Create and chain a new instance of a dumbModifier for every new icon.
// This forces the LayoutNode to requestRelayout, leading to a synthetic event being dispatched
// and then handled here in pointerInput below, and then applying the icon to the pointerIconService.
val dumbModifier = remember(icon) { object : Modifier.Element {} }
Copy link
Collaborator

Choose a reason for hiding this comment

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

This uses implementation details of the how relayout happens. In the future there can be an optimisation to not perform relayout on new empty modifiers.

What if we tell explicitly, that we need a new synthetic event?

SideEffect {
   pointerIconService.refresh()
}

override val pointerIconService = object : PointerIconService {
    override var current: PointerIcon = PointerIconDefaults.Default

    fun refresh() = pointerPositionUpdater.onLayout() // better to rename onLayout to `needUpdate`, because now we call it not only on layout
}

Also, if it is not complicated, better to write a test to this behaviour.

Copy link
Collaborator Author

@eymar eymar Jun 6, 2022

Choose a reason for hiding this comment

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

done.
I decided to use DisposableEffect(key = icon) instead of a SideEffect, to avoid requesting the update for every recomposition.

We also can add DisposableEffect conditionally: only when a component is hovered: if (isHovered) DisapobleEffect.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We also can add DisposableEffect conditionally: only when a component is hovered: if (isHovered) DisapobleEffect.

Great idea ). Let's do this way

@eymar eymar merged commit 6dcd1fd into jb-main Jun 7, 2022
@eymar eymar deleted the pointer_hover_icon branch June 7, 2022 09:36
eymar added a commit that referenced this pull request Jun 27, 2022
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
eymar added a commit that referenced this pull request Jun 28, 2022
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
igordmn pushed a commit that referenced this pull request Aug 18, 2022
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
igordmn pushed a commit that referenced this pull request Aug 18, 2022
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
eymar added a commit that referenced this pull request Oct 26, 2022
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
eymar added a commit that referenced this pull request Nov 16, 2022
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
eymar added a commit that referenced this pull request Jan 13, 2023
* fix pointerHoverIcon: update icon when it's changed conditionally

JetBrains/compose-multiplatform#2091

* add tests

* add DisposableEffect conditionally - only when a component is hovered

Co-authored-by: Oleksandr Karpovich <oleksandr.karpovich@jetbrains.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants