Skip to content
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

Root view panel #12372

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Create RootViewPanel",
"packageName": "react-native-windows",
"email": "lyahdav@users.noreply.github.com",
"dependentChangeType": "patch"
}
13 changes: 12 additions & 1 deletion vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="ReactHost\JSCallInvokerScheduler.h" />
<ClInclude Include="RootViewPanel.h">
<DependentUpon>RootViewPanel.idl</DependentUpon>
<SubType>Code</SubType>
</ClInclude>
<ClInclude Include="Utils\ShadowNodeTypeUtils.h" />
<ClInclude Include="Utils\BatchingEventEmitter.h" />
<ClInclude Include="DevMenuControl.h">
Expand Down Expand Up @@ -428,6 +432,10 @@
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="CoreApp.cpp" />
<ClCompile Include="RootViewPanel.cpp">
<DependentUpon>RootViewPanel.idl</DependentUpon>
<SubType>Code</SubType>
</ClCompile>
<ClCompile Include="Utils\BatchingEventEmitter.cpp" />
<ClCompile Include="CxxReactUWP\JSBigString.cpp" />
<ClCompile Include="DevMenuControl.cpp">
Expand Down Expand Up @@ -586,6 +594,9 @@
<Midl Include="ReactRootView.idl">
<SubType>Designer</SubType>
</Midl>
<Midl Include="RootViewPanel.idl">
<SubType>Designer</SubType>
</Midl>
<Midl Include="XamlHelper.idl" />
<Midl Include="ReactPointerEventArgs.idl" />
</ItemGroup>
Expand Down Expand Up @@ -676,4 +687,4 @@
</ClCompile>
</ItemGroup>
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@
<Midl Include="DocString.idl" />
<Midl Include="DesktopWindowMessage.idl" />
<Midl Include="ReactPointerEventArgs.idl" />
<Midl Include="RootViewPanel.idl" />
</ItemGroup>
<ItemGroup>
<None Include="microsoft.reactnative.def" />
Expand Down Expand Up @@ -769,4 +770,4 @@
<Page Include="DevMenuControl.xaml" />
<Page Include="CoreAppPage.xaml" />
</ItemGroup>
</Project>
</Project>
56 changes: 56 additions & 0 deletions vnext/Microsoft.ReactNative/RootViewPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include "pch.h"

#include "RootViewPanel.h"

#include <IReactContext.h>
#include <Modules/NativeUIManager.h>
#include <Modules/PaperUIManagerModule.h>
#include <QuirkSettings.h>
#include <ReactHost/MsoUtils.h>
#include <UI.Xaml.Input.h>
#include <UI.Xaml.Media.Media3D.h>
#include <Utils/Helpers.h>
#include <dispatchQueue/dispatchQueue.h>
#include <winrt/Windows.UI.Core.h>
#include "ReactNativeHost.h"
#include "ReactViewInstance.h"
#include "TouchEventHandler.h"
#include "Views/ShadowNodeBase.h"
#include "XamlUtils.h"

// Needed for latest versions of C++/WinRT
#if __has_include("RootViewPanel.g.cpp")
#include "RootViewPanel.g.cpp"
#endif

namespace winrt::Microsoft::ReactNative::implementation {

RootViewPanel::RootViewPanel(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept {
winrt::Microsoft::ReactNative::ReactContext reactContextImpl = reactContext;
auto contextSelf =
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactContext>(reactContextImpl.Handle());

m_touchEventHandler = std::make_shared<::Microsoft::ReactNative::TouchEventHandler>(contextSelf->GetInner());
m_touchEventHandler->AddTouchHandlers(*this);
m_previewKeyboardEventHandlerOnRoot =
std::make_shared<::Microsoft::ReactNative::PreviewKeyboardEventHandlerOnRoot>(contextSelf->GetInner());
m_previewKeyboardEventHandlerOnRoot->hook(*this);
}

RootViewPanel::~RootViewPanel() noexcept {
if (m_touchEventHandler) {
m_touchEventHandler->RemoveTouchHandlers();
}

if (m_previewKeyboardEventHandlerOnRoot) {
m_previewKeyboardEventHandlerOnRoot->unhook();
}

// Clear members with a dependency on the reactInstance
m_touchEventHandler.reset();
}

} // namespace winrt::Microsoft::ReactNative::implementation
31 changes: 31 additions & 0 deletions vnext/Microsoft.ReactNative/RootViewPanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#pragma once

#include "RootViewPanel.g.h"

#include "Views/KeyboardEventHandler.h"
#include "Views/ViewPanel.h"

namespace Microsoft::ReactNative {
class TouchEventHandler;
class PreviewKeyboardEventHandlerOnRoot;
} // namespace Microsoft::ReactNative

namespace winrt::Microsoft::ReactNative::implementation {

struct RootViewPanel : RootViewPanelT<RootViewPanel, ViewPanel> {
RootViewPanel(winrt::Microsoft::ReactNative::IReactContext reactContext) noexcept;
~RootViewPanel() noexcept;

private:
std::shared_ptr<::Microsoft::ReactNative::TouchEventHandler> m_touchEventHandler;
std::shared_ptr<::Microsoft::ReactNative::PreviewKeyboardEventHandlerOnRoot> m_previewKeyboardEventHandlerOnRoot;
};

} // namespace winrt::Microsoft::ReactNative::implementation

namespace winrt::Microsoft::ReactNative::factory_implementation {
struct RootViewPanel : RootViewPanelT<RootViewPanel, implementation::RootViewPanel> {};
} // namespace winrt::Microsoft::ReactNative::factory_implementation
18 changes: 18 additions & 0 deletions vnext/Microsoft.ReactNative/RootViewPanel.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import "ViewPanel.idl";
import "IReactContext.idl";
#include "DocString.h"

namespace Microsoft.ReactNative
{
[default_interface]
[webhosthidden]
DOC_STRING("A XAML component that manages keyboard/touch inputs.")
runtimeclass RootViewPanel : ViewPanel
{
DOC_STRING("Creates a new instance of @RootViewPanel")
RootViewPanel(IReactContext reactContext);
}
} // namespace Microsoft. ReactNative
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/Views/cppwinrt/ViewPanel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.ReactNative
{
[default_interface]
[webhosthidden]
runtimeclass ViewPanel : XAML_NAMESPACE.Controls.Grid
unsealed runtimeclass ViewPanel : XAML_NAMESPACE.Controls.Grid
{
// Constructors
ViewPanel();
Expand Down