diff --git a/change/@office-iss-react-native-win32-6b1b9c92-50ad-4985-89ba-4f2505aa825c.json b/change/@office-iss-react-native-win32-6b1b9c92-50ad-4985-89ba-4f2505aa825c.json new file mode 100644 index 00000000000..1546119c3e3 --- /dev/null +++ b/change/@office-iss-react-native-win32-6b1b9c92-50ad-4985-89ba-4f2505aa825c.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Fix PaperUIManager (port from windows)", + "packageName": "@office-iss/react-native-win32", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/change/react-native-windows-3701d914-c1cc-48f7-b2ad-e84229318968.json b/change/react-native-windows-3701d914-c1cc-48f7-b2ad-e84229318968.json new file mode 100644 index 00000000000..484cd7c0a12 --- /dev/null +++ b/change/react-native-windows-3701d914-c1cc-48f7-b2ad-e84229318968.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Dont use CoreWindow to determine key state", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/@office-iss/react-native-win32/src-win/Libraries/ReactNative/PaperUIManager.win32.js b/packages/@office-iss/react-native-win32/src-win/Libraries/ReactNative/PaperUIManager.win32.js index 8adf3cc1a13..3e727658be2 100644 --- a/packages/@office-iss/react-native-win32/src-win/Libraries/ReactNative/PaperUIManager.win32.js +++ b/packages/@office-iss/react-native-win32/src-win/Libraries/ReactNative/PaperUIManager.win32.js @@ -98,7 +98,9 @@ const UIManagerJS: UIManagerJSInterface = { }; // [Windows The spread operator doesn't work on JSI turbomodules, so use this instead -for (const propName of Object.getOwnPropertyNames(NativeUIManager)) { +for (const propName of Object.getOwnPropertyNames( + Object.getPrototypeOf(NativeUIManager), +)) { // $FlowFixMe UIManagerJS[propName] = NativeUIManager[propName]; } diff --git a/vnext/Desktop.DLL/react-native-win32.x64.def b/vnext/Desktop.DLL/react-native-win32.x64.def index 6cea08ac3de..f48a896cc9d 100644 --- a/vnext/Desktop.DLL/react-native-win32.x64.def +++ b/vnext/Desktop.DLL/react-native-win32.x64.def @@ -80,6 +80,7 @@ YGConfigGetUseWebDefaults YGConfigIsExperimentalFeatureEnabled YGConfigNew YGConfigSetContext +YGConfigSetErrata YGConfigSetExperimentalFeatureEnabled YGConfigSetLogger YGConfigSetPointScaleFactor diff --git a/vnext/Desktop.DLL/react-native-win32.x86.def b/vnext/Desktop.DLL/react-native-win32.x86.def index fd82e2729b3..f2e6b10eedb 100644 --- a/vnext/Desktop.DLL/react-native-win32.x86.def +++ b/vnext/Desktop.DLL/react-native-win32.x86.def @@ -80,6 +80,7 @@ _YGConfigGetUseWebDefaults@4 _YGConfigIsExperimentalFeatureEnabled@8 _YGConfigNew@0 _YGConfigSetContext@8 +_YGConfigSetErrata@8 _YGConfigSetExperimentalFeatureEnabled@12 _YGConfigSetLogger@8 _YGConfigSetPointScaleFactor@8 diff --git a/vnext/Desktop/module.g.cpp b/vnext/Desktop/module.g.cpp index 375bbb814c2..1c37550b495 100644 --- a/vnext/Desktop/module.g.cpp +++ b/vnext/Desktop/module.g.cpp @@ -21,6 +21,7 @@ void* winrt_make_Microsoft_ReactNative_ReactNotificationServiceHelper(); void* winrt_make_Microsoft_ReactNative_ReactPropertyBagHelper(); void* winrt_make_Microsoft_ReactNative_ReactViewOptions(); void* winrt_make_Microsoft_ReactNative_RedBoxHelper(); +void* winrt_make_Microsoft_ReactNative_QuirkSettings(); void* winrt_make_facebook_react_NativeLogEventSource(); void* winrt_make_facebook_react_NativeTraceEventSource(); @@ -105,6 +106,11 @@ void* __stdcall winrt_get_activation_factory([[maybe_unused]] std::wstring_view return winrt_make_Microsoft_ReactNative_RedBoxHelper(); } + if (requal(name, L"Microsoft.ReactNative.QuirkSettings")) + { + return winrt_make_Microsoft_ReactNative_QuirkSettings(); + } + if (requal(name, L"facebook.react.NativeLogEventSource")) { return winrt_make_facebook_react_NativeLogEventSource(); diff --git a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp index c817834193a..53f9537b38b 100644 --- a/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp @@ -1589,10 +1589,43 @@ facebook::react::Tag ViewComponentView::hitTest( return -1; } +inline winrt::Windows::System::VirtualKey GetLeftOrRightModifiedKey( + const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source, + winrt::Windows::System::VirtualKey leftKey, + winrt::Windows::System::VirtualKey rightKey) { + return (source.GetKeyState(leftKey) == winrt::Windows::UI::Core::CoreVirtualKeyStates::Down) ? leftKey : rightKey; +} + +std::string CodeFromVirtualKey( + const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source, + winrt::Windows::System::VirtualKey virtualKey) { + int key = static_cast(virtualKey); + + if (isdigit(key)) { + return "Digit" + std::string(1, static_cast(key)); + } else if (isupper(key)) { + return "Key" + std::string(1, static_cast(key)); + } else { + // Override the virtual key if it's modified key of Control, Shift or Menu + if (virtualKey == winrt::Windows::System::VirtualKey::Control) { + virtualKey = GetLeftOrRightModifiedKey( + source, winrt::Windows::System::VirtualKey::LeftControl, winrt::Windows::System::VirtualKey::RightControl); + } else if (virtualKey == winrt::Windows::System::VirtualKey::Shift) { + virtualKey = GetLeftOrRightModifiedKey( + source, winrt::Windows::System::VirtualKey::LeftShift, winrt::Windows::System::VirtualKey::RightShift); + } else if (virtualKey == winrt::Windows::System::VirtualKey::Menu) { + virtualKey = GetLeftOrRightModifiedKey( + source, winrt::Windows::System::VirtualKey::LeftMenu, winrt::Windows::System::VirtualKey::RightMenu); + } + } + + return ::Microsoft::ReactNative::GetOrUnidentifiedCode(virtualKey); +} + void ViewComponentView::OnKeyDown( const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source, const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept { - auto eventCode = ::Microsoft::ReactNative::CodeFromVirtualKey(args.Key()); + auto eventCode = CodeFromVirtualKey(source, args.Key()); bool fShift = source.GetKeyState(winrt::Windows::System::VirtualKey::Shift) != winrt::Windows::UI::Core::CoreVirtualKeyStates::None; bool fAlt = source.GetKeyState(winrt::Windows::System::VirtualKey::Menu) != @@ -1631,7 +1664,7 @@ void ViewComponentView::OnKeyDown( void ViewComponentView::OnKeyUp( const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source, const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept { - auto eventCode = ::Microsoft::ReactNative::CodeFromVirtualKey(args.Key()); + auto eventCode = CodeFromVirtualKey(source, args.Key()); bool fShift = source.GetKeyState(winrt::Windows::System::VirtualKey::Shift) != winrt::Windows::UI::Core::CoreVirtualKeyStates::None; bool fAlt = source.GetKeyState(winrt::Windows::System::VirtualKey::Menu) != diff --git a/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.cpp b/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.cpp index f1c461acc68..b495caef0d2 100644 --- a/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.cpp +++ b/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.cpp @@ -348,6 +348,14 @@ static const std::string GetOrUnidentified( return "Unidentified"; } +const std::string GetOrUnidentifiedCode(winrt::Windows::System::VirtualKey virtualKey) { + return GetOrUnidentified(virtualKey, g_virtualKeyToCode); +} + +const std::string GetOrUnidentifiedKey(winrt::Windows::System::VirtualKey virtualKey) { + return GetOrUnidentified(virtualKey, g_virtualKeyToKey); +} + std::string FromVirtualKey(winrt::Windows::System::VirtualKey virtualKey, bool fShift, bool fCaps) { int vk = static_cast(virtualKey); @@ -362,7 +370,7 @@ std::string FromVirtualKey(winrt::Windows::System::VirtualKey virtualKey, bool f return std::string{c}; } - return GetOrUnidentified(virtualKey, g_virtualKeyToKey); + return GetOrUnidentifiedKey(virtualKey); } bool IsModifiedKeyPressed(winrt::CoreWindow const &coreWindow, winrt::Windows::System::VirtualKey virtualKey) { @@ -410,7 +418,7 @@ std::string CodeFromVirtualKey(winrt::Windows::System::VirtualKey virtualKey) { } } - return GetOrUnidentified(virtualKey, g_virtualKeyToCode); + return GetOrUnidentifiedCode(virtualKey); } } // namespace Microsoft::ReactNative diff --git a/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.h b/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.h index 30b4372db7e..2da6aadd3e4 100644 --- a/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.h +++ b/vnext/Microsoft.ReactNative/Utils/KeyboardUtils.h @@ -12,4 +12,7 @@ bool IsModifiedKeyPressed(winrt::CoreWindow const &coreWindow, winrt::Windows::S std::string FromVirtualKey(winrt::Windows::System::VirtualKey virtualKey, bool fShift, bool fCaps); std::string CodeFromVirtualKey(winrt::Windows::System::VirtualKey virtualKey); -} // namespace Microsoft::ReactNative \ No newline at end of file +const std::string GetOrUnidentifiedCode(winrt::Windows::System::VirtualKey virtualKey); +const std::string GetOrUnidentifiedKey(winrt::Windows::System::VirtualKey virtualKey); + +} // namespace Microsoft::ReactNative