react-native-windows
react-native-windows copied to clipboard
Fix WinUI 3 crash when using keyboard due to KeyboardEventHandler using unsupported class
Description
Per WinAppSDK the CoreWindow class is unsupported. It's used in KeyboardEventHandler for calling GetKeyState, which the docs provide an alternative:
Instead of the GetKeyState method, use the InputKeyboardSource.GetKeyStateForCurrentThread method provided by WinUI 3 instead.
This PR makes that change.
Type of Change
- Bug fix (non-breaking change which fixes an issue)
Why
Resolves #8063
Screenshots
Before (crashes):
After (no crash):
Testing
To test, launch WinUI 3 app with RNW and press any key.
Microsoft Reviewers: Open in CodeFlow
this will likely need to be looked at again to handle multi-threading
@asklar What's the threading concern? Shouldn't it be safe to call GetKeyStateForCurrentThread on any thread?
@asklar What's the threading concern? Shouldn't it be safe to call GetKeyStateForCurrentThread on any thread?
+1 - please clarify. If you're referring to the possibility that each WinAppSDK window may be running on a different thread, this change is the least of our concerns :). The PaperUIManager needs an overhaul to support switching UIManager operations (like createView, updateView, manageChildren, etc.) to the correct thread based on the root tag for the view in question (at least, this is how we did this in RNW v0.59 and earlier).
And actually, since this functionality occurs in the PreviewKeyDown or KeyDown routed events, to @lyahdav's point, we probably won't need to look at this again to handle multi-threading, because presumably the events will be bubbled on the appropriate thread.
/azp run
Azure Pipelines successfully started running 1 pipeline(s).
Looks like merging is blocked on our end because of license/cla. @lyahdav You might need to close and reopen to retrigger the license/cla to run or it may need you to resign the cla I think the token might have been updated recently.
I just closed and reopened and I think it's blocked for the same reason. How do I resign the cla?
Yea looks like merging is still blocked. This happened on Helen's PR as well here https://github.com/microsoft/react-native-windows/pull/10673. Maybe try commenting this: @microsoft-github-policy-service agree company="Meta" and then closing and opening again.
@microsoft-github-policy-service agree company="Meta"
Just tried that, same issue
@chiaramooney should we just abandon these faulty PRs and create new ones or is there something you can do on your end to bypass the CLI check?
@rozele @lyahdav Doesn't look like there is a workaround available on my end, so maybe let'[s just redo the PR and then link this one so we can track the comments on this one. According to Jon the github app that does signing changed last month, so PR's have gone wonky.
Recreated in https://github.com/microsoft/react-native-windows/pull/10859, closing this one.