-
Notifications
You must be signed in to change notification settings - Fork 100
Call Modifier.onGloballyPositioned
when window moves
#2163
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
Call Modifier.onGloballyPositioned
when window moves
#2163
Conversation
I don't think that it should be a part of |
I agree it's maybe weaker than BREAKING CHANGE, but it's still something to be aware of. We don't have a suitable category, so I preferred to warn users rather than say nothing.
It's a new value you can receive when calling |
...e/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/PlatformWindowContext.desktop.kt
Outdated
Show resolved
Hide resolved
*/ | ||
private inline fun withLocationOnScreenOrUnspecified( | ||
component: Component, | ||
block: (locationOnScreen: Offset) -> Offset |
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.
It's the last action in the function. There is no reason to introduce another lambda instead of just returning location on screen for the component
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 I understand what you mean. Without a lambda it would not be possible to directly return Offset.Unspecified
from the calling function without checking the return value of the helper function.
* @see PlatformContext.convertLocalToScreenPosition | ||
* @see PlatformContext.convertScreenToLocalPosition | ||
*/ | ||
fun invalidatePositionOnScreen() |
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.
Do we really need a new API here? It seems calling invalidatePositionInWindow
should work just fine here. So having two functions with the same effect is confusing from public contract POV. Narrowing set of invalidation is an implementation detail, sot sure that it's actually worth it.
If you don't like explicit InWindow
mentioning in the name we probably can rename it to something like
invalidateLocalCoordinates
or so. It should look better than two methods.
🤔 but on another hand it might make sense. So I'm not really sure 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.
Position in window and position on screen are categorically different, as evidenced by the fact that we forgot to even consider changes in position on screen as important for the scene.
So I disagree that it's an implementation detail.
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/node/RootNodeOwner.skiko.kt
Outdated
Show resolved
Hide resolved
We do. "Migration Notes" is exactly what you're looking for. |
Changed to Migration Notes |
When the window moves or becomes iconified/deiconified, call
Modifier.onGloballyPositioned
.Fixes https://youtrack.jetbrains.com/issue/CMP-8337/Modifier.onGloballyPositioned-should-be-called-when-window-is-moved
Testing
Tested manually with
and also added unit tests.
This should be tested by QA
Release Notes
Fixes - Desktop
Modifier.onGloballyPositioned
will be called.Migration Notes - Desktop
LayoutCoordinates.positionOnScreen()
) will returnOffset.Unspecified
.