-
Notifications
You must be signed in to change notification settings - Fork 63
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
Conversation
// 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 {} } |
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.
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.
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.
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.
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.
We also can add DisposableEffect conditionally: only when a component is hovered: if (isHovered) DisapobleEffect.
Great idea ). Let's do this way
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
fixes JetBrains/compose-multiplatform#2091