Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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": "Rework modal implementation to use public APIs",
"packageName": "react-native-windows",
"email": "30809111+acoates-ms@users.noreply.github.com",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions vnext/Microsoft.ReactNative/CompositionComponentView.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "ViewProps.idl";
import "Composition.Input.idl";
import "CompositionSwitcher.idl";
import "IReactContext.idl";
import "ReactNativeIsland.idl";

#include "DocString.h"

Expand Down Expand Up @@ -110,6 +111,8 @@ namespace Microsoft.ReactNative.Composition
[default_interface]
runtimeclass RootComponentView : ViewComponentView {
Microsoft.ReactNative.ComponentView GetFocusedComponent();

Microsoft.ReactNative.ReactNativeIsland ReactNativeIsland { get; };
};

[experimental]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <Fabric/Composition/CompositionViewComponentView.h>
#include <Fabric/Composition/DebuggingOverlayComponentView.h>
#include <Fabric/Composition/ImageComponentView.h>
#include <Fabric/Composition/Modal/WindowsModalHostViewComponentView.h>
#include <Fabric/Composition/Modal/WindowsModalHostViewShadowNode.h>
#include <Fabric/Composition/ParagraphComponentView.h>
#include <Fabric/Composition/RootComponentView.h>
#include <Fabric/Composition/ScrollViewComponentView.h>
Expand Down Expand Up @@ -59,9 +57,6 @@ ComponentViewDescriptor const &ComponentViewRegistry::dequeueComponentViewWithCo
} else if (componentHandle == facebook::react::ImageShadowNode::Handle()) {
view = winrt::Microsoft::ReactNative::Composition::implementation::ImageComponentView::Create(
compContext, tag, m_context);
} else if (componentHandle == facebook::react::WindowsModalHostViewShadowNode::Handle()) {
Comment thread
TatianaKapos marked this conversation as resolved.
view = winrt::Microsoft::ReactNative::Composition::implementation::WindowsModalHostComponentView::Create(
compContext, tag, m_context);
} else if (componentHandle == facebook::react::WindowsTextInputShadowNode::Handle()) {
view = winrt::Microsoft::ReactNative::Composition::implementation::WindowsTextInputComponentView::Create(
compContext, tag, m_context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ HRESULT __stdcall CompositionDynamicAutomationProvider::GetPatternProvider(PATTE
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(strongView)->props());
if (props == nullptr)
return UIA_E_ELEMENTNOTAVAILABLE;
auto accessibilityRole =
props->accessibilityRole.empty() ? compositionView->DefaultControlType() : props->accessibilityRole;
// Invoke control pattern is used to support controls that do not maintain state
// when activated but rather initiate or perform a single, unambiguous action.
if (patternId == UIA_InvokePatternId && (props->onAccessibilityTap)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ struct CompositionInputKeyboardSource : winrt::implements<

CompositionEventHandler::CompositionEventHandler(
const winrt::Microsoft::ReactNative::ReactContext &context,
const winrt::Microsoft::ReactNative::ReactNativeIsland &reactNativeIsland,
const int fragmentTag)
: m_fragmentTag(fragmentTag), m_context(context), m_wkRootView(reactNativeIsland) {}
const winrt::Microsoft::ReactNative::ReactNativeIsland &reactNativeIsland)
: m_context(context), m_wkRootView(reactNativeIsland) {}

void CompositionEventHandler::Initialize() noexcept {
#ifdef USE_WINUI3
Expand Down Expand Up @@ -365,6 +364,9 @@ void CompositionEventHandler::onPointerWheelChanged(
facebook::react::Point ptLocal;
facebook::react::Point ptScaled = {static_cast<float>(position.X), static_cast<float>(position.Y)};

// In the case of a sub rootview, we may have a non-zero origin. hitTest takes a pt in the parent coords, so we
// need to apply the current origin
ptScaled += RootComponentView().layoutMetrics().frame.origin;
auto tag = RootComponentView().hitTest(ptScaled, ptLocal);

if (tag == -1)
Expand Down Expand Up @@ -977,6 +979,11 @@ void CompositionEventHandler::getTargetPointerArgs(
tag = -1;

ptScaled = {position.X, position.Y};

// In the case of a sub rootview, we may have a non-zero origin. hitTest takes a pt in the parent coords, so we need
// to apply the current origin
ptScaled += RootComponentView().layoutMetrics().frame.origin;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment says the hitTest pt is taken in parent coordinates and we're incorporating the origin in the subrootview (separate window) for it hit test... for the other lines I was thinking "should this origin be incorporated inside hitTest instead of called before it, if it's the RootComponentView()'s layoutMetrics?" ... then saw the if(capturedPointers) { ... } that's more curious. When do we have m_capturedPointers vs not?

Is the underlying type of facebook::react::Point a float? Considering the implications of different DPI on different displays which can do curious things in some contexts


if (std::find(m_capturedPointers.begin(), m_capturedPointers.end(), pointerId) != m_capturedPointers.end()) {
assert(m_pointerCapturingComponentTag != -1);
tag = m_pointerCapturingComponentTag;
Expand All @@ -989,30 +996,7 @@ void CompositionEventHandler::getTargetPointerArgs(
ptLocal.y = ptScaled.y - (clientRect.top / strongRootView.ScaleFactor());
}
} else {
if (m_fragmentTag == -1) {
tag = RootComponentView().hitTest(ptScaled, ptLocal);
return;
}

// check if the fragment tag exists
if (!fabricuiManager->GetViewRegistry().findComponentViewWithTag(m_fragmentTag)) {
return;
}

auto fagmentView = fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(m_fragmentTag).view;
auto fagmentchildren = fagmentView.Children();

// call the hitTest with the fargment as the RootComponent
for (auto index = fagmentchildren.Size(); index > 0; index--) {
auto childView = fagmentchildren.GetAt(index - 1);
auto targetTag =
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(childView)->hitTest(
ptScaled, ptLocal);
if (targetTag != -1) {
tag = targetTag;
break;
}
}
tag = RootComponentView().hitTest(ptScaled, ptLocal);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class CompositionEventHandler : public std::enable_shared_from_this<CompositionE
public:
CompositionEventHandler(
const winrt::Microsoft::ReactNative::ReactContext &context,
const winrt::Microsoft::ReactNative::ReactNativeIsland &ReactNativeIsland,
const int fragmentTag);
const winrt::Microsoft::ReactNative::ReactNativeIsland &ReactNativeIsland);
virtual ~CompositionEventHandler();

void Initialize() noexcept;
Expand Down Expand Up @@ -152,7 +151,6 @@ class CompositionEventHandler : public std::enable_shared_from_this<CompositionE

std::map<PointerId, ActiveTouch> m_activeTouches; // iOS is map of touch event args to ActiveTouch..?
PointerId m_touchId = 0;
int m_fragmentTag = -1;

std::map<PointerId, std::vector<ReactTaggedView>> m_currentlyHoveredViewsPerPointer;
winrt::weak_ref<winrt::Microsoft::ReactNative::ReactNativeIsland> m_wkRootView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ bool ComponentView::CapturePointer(const winrt::Microsoft::ReactNative::Composit
if (!root)
return false;

auto rootView{uiManager->GetReactNativeIsland(root->Tag())};
auto rootView{root->ReactNativeIsland()};
if (!rootView) {
return false;
}
Expand All @@ -487,7 +487,7 @@ void ComponentView::ReleasePointerCapture(
if (!root)
return;

auto rootView{uiManager->GetReactNativeIsland(root->Tag())};
auto rootView{root->ReactNativeIsland()};
if (!rootView) {
return;
}
Expand Down Expand Up @@ -913,10 +913,13 @@ bool ComponentView::anyHitTestHelper(
if (auto index = m_children.Size()) {
do {
index--;
targetTag = winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(m_children.GetAt(index))
->hitTest(ptContent, localPt);
if (targetTag != -1) {
return true;
auto child =
Comment thread
acoates-ms marked this conversation as resolved.
Outdated
winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(m_children.GetAt(index));
if (child->rootComponentView() == rootComponentView()) {
targetTag = child->hitTest(ptContent, localPt);
if (targetTag != -1) {
return true;
}
}
} while (index != 0);
}
Expand Down Expand Up @@ -1330,7 +1333,7 @@ winrt::Microsoft::ReactNative::ComponentView lastDeepChild(
}

// Walks the tree calling the function fn on each node.
// If fn returns true, then walkTree stops itterating over the tree, and returns true.
// If fn returns true, then walkTree stops iterating over the tree, and returns true.
// If the tree walk completes without fn returning true, then walkTree returns false.
bool walkTree(
const winrt::Microsoft::ReactNative::ComponentView &view,
Expand Down
13 changes: 11 additions & 2 deletions vnext/Microsoft.ReactNative/Fabric/Composition/FocusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,17 @@ winrt::Microsoft::ReactNative::implementation::ComponentView *NavigateFocusHelpe
[reason, &toFocus](::winrt::Microsoft::ReactNative::implementation::ComponentView &v) noexcept
-> bool { return (toFocus = NavigateFocusHelper(v, reason)); };

if (view.runOnChildren(reason == winrt::Microsoft::ReactNative::FocusNavigationReason::First, fn)) {
return toFocus;
// Do not iterate through sub rootviews when looking for somewhere to put focus.
// If the root view is focusable, we can set focus directly on that, and it can put focus in the appropriate place.
Comment thread
acoates-ms marked this conversation as resolved.
Outdated
if (view.Children().Size()) {
auto firstChild = view.Children().GetAt(0);
if (view.rootComponentView() ==
winrt::get_self<::winrt::Microsoft::ReactNative::implementation::ComponentView>(firstChild)
->rootComponentView()) {
if (view.runOnChildren(reason == winrt::Microsoft::ReactNative::FocusNavigationReason::First, fn)) {
return toFocus;
}
}
}

if (reason == winrt::Microsoft::ReactNative::FocusNavigationReason::Last) {
Expand Down

This file was deleted.

Loading