-
Notifications
You must be signed in to change notification settings - Fork 82
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
Re-show the tooltip on mouse-move following a click in TooltipArea. #1209
Conversation
if (job?.isActive == true) { // Don't restart the job if it's already active | ||
return | ||
} |
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 is needed because this function is now potentially called on every mouse-move, and we don't want to restart the timer.
if (!isVisible && !it.buttons.areAnyPressed) { | ||
startShowing() | ||
} |
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 fixes the case of press -> exit -> enter
Previously we would re-show the tooltip.
...ndation/foundation/src/desktopMain/kotlin/androidx/compose/foundation/TooltipArea.desktop.kt
Show resolved
Hide resolved
if (!isVisible && !it.buttons.areAnyPressed) { | ||
startShowing() | ||
} |
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.
Re-show the tooltip on mouse-move (but no buttons pressed).
08b6919
to
f61ed34
Compare
private suspend fun PointerInputScope.detectDown(onDown: (Offset) -> Unit) { | ||
while (true) { | ||
awaitPointerEventScope { | ||
val event = awaitPointerEvent(PointerEventPass.Initial) | ||
val down = event.changes.find { it.changedToDown() } | ||
if (down != null) { | ||
onDown(down.position) | ||
} | ||
} | ||
} | ||
} | ||
|
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.
Not sure why this was needed, and in any case it's buggy - you're supposed to put the while
inside the awaitPointerEventScope
.
@@ -121,6 +120,7 @@ fun TooltipArea( | |||
|
|||
fun hide() { | |||
job?.cancel() | |||
job = null |
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.
Because why not.
.pointerInput(Unit) { | ||
detectDown { | ||
hide() | ||
} | ||
.onPointerEvent(PointerEventType.Press, pass = PointerEventPass.Initial) { | ||
hide() |
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.
Not sure why there was a need for a custom implementation here.
f61ed34
to
a0c3171
Compare
detectDown { | ||
hide() | ||
} | ||
.onPointerEvent(PointerEventType.Press, pass = PointerEventPass.Initial) { |
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.
Why do we need Initial
instead of the main pass here?
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.
I don't know, but it was in the code already, so I decided not to change it just in case.
The tooltip is currently hidden when the
TooltipArea
is pressed, and it remains hidden until mouse exit and re-enter.This is a problem for widgets that have more than one mouse interaction per hover session, e.g. a text field.
Proposed Changes
See my comments for explanations why each change was made.
Testing
Test: Added several unit tests.
Issues Fixed
Fixes: JetBrains/compose-multiplatform#4515