Make canvas focused when Compose handles pointer events#2796
Conversation
Shagen Ogandzhanian (Schahen)
left a comment
There was a problem hiding this comment.
I'm worried (because we introduce more logic rather then reduce logic) but failed to come up with scenario where this breaks )
| addTypedEvent<FocusEvent>("focus") { event -> | ||
| canvasFocused = true | ||
| } | ||
|
|
||
| addTypedEvent<FocusEvent>("blur") { event -> | ||
| canvasFocused = false | ||
| } | ||
|
|
||
| state.globalEvents.addDisposableEvent("focus") { | ||
| archComponentsOwner.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME) | ||
| } |
There was a problem hiding this comment.
why don't you use already existing listeners?
There was a problem hiding this comment.
Do you mean state.globalEvents.addDisposableEvent("focus") ?
The global listener is listening on the window. But addTypedEvent<FocusEvent>("focus") adds a listener to the canvas.
In this case I need to know if a canvas is focused or not.
| // iOS Safari doesn't request focus when the page is shown, | ||
| // and the lifecycle doesn't trigger ON_RESUME. | ||
| // so, we decided to handle every touch | ||
| archComponentsOwner.lifecycle.currentState = Lifecycle.State.RESUMED |
There was a problem hiding this comment.
don't forget to handle this as well
There was a problem hiding this comment.
Do you mean to handle Touch Events?
There was a problem hiding this comment.
I mean Safari doesn't requests focus sometimes
This reverts commit c31fceb
…rains#2796)" (JetBrains#2867) This reverts commit c31fceb ## Release Notes N/A
Fixes https://youtrack.jetbrains.com/issue/CMP-9797
In 8d814d7 we started to
preventDefaultmouse events processed by Compose.preventDefaultprevents a browser from focusing the canvas - that's why ESC stopped working.Fixes https://youtrack.jetbrains.com/issue/CMP-9797/Web-Dialogs-Popups-dont-close-on-the-first-attempt-when-pressing-Esc
Testing
This should be tested by QA
Release Notes
Fixes - Web