react-native-windows icon indicating copy to clipboard operation
react-native-windows copied to clipboard

Fix WinUI 3 crash when using keyboard due to KeyboardEventHandler using unsupported class

Open lyahdav opened this issue 2 years ago • 3 comments

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): image

After (no crash): image

Testing

To test, launch WinUI 3 app with RNW and press any key.

Microsoft Reviewers: Open in CodeFlow

lyahdav avatar Sep 16 '22 22:09 lyahdav

this will likely need to be looked at again to handle multi-threading

asklar avatar Sep 20 '22 01:09 asklar

@asklar What's the threading concern? Shouldn't it be safe to call GetKeyStateForCurrentThread on any thread?

lyahdav avatar Sep 20 '22 21:09 lyahdav

@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.

rozele avatar Sep 21 '22 03:09 rozele

/azp run

AgneLukoseviciute avatar Oct 06 '22 21:10 AgneLukoseviciute

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Oct 06 '22 21:10 azure-pipelines[bot]

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.

chiaramooney avatar Nov 02 '22 23:11 chiaramooney

I just closed and reopened and I think it's blocked for the same reason. How do I resign the cla?

lyahdav avatar Nov 03 '22 00:11 lyahdav

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.

chiaramooney avatar Nov 03 '22 22:11 chiaramooney

@microsoft-github-policy-service agree company="Meta"

lyahdav avatar Nov 03 '22 22:11 lyahdav

Just tried that, same issue

lyahdav avatar Nov 03 '22 22:11 lyahdav

@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 avatar Nov 04 '22 21:11 rozele

@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.

chiaramooney avatar Nov 07 '22 21:11 chiaramooney

Recreated in https://github.com/microsoft/react-native-windows/pull/10859, closing this one.

lyahdav avatar Nov 10 '22 22:11 lyahdav