Skip to content

Commit

Permalink
Explicitly measure relative to the root XAML element (#10665)
Browse files Browse the repository at this point in the history
* Explicitly measure relative to the root XAML element

Previously, `measureInWindow` measured relative to
`xaml::Window::Current().Content()`, which is null for XAML Islands
applications. Calling `TransformToVisual` with a null argument measures
relative to the root XAML content, which is equivalent to
`xaml::Window::Current().Content()` for the foreground window. The main
difference is that this API will now measure correctly for React Native
windows that are not in the foreground.

* Change files
  • Loading branch information
rozele committed Oct 6, 2022
1 parent 3ef3a98 commit 0a18b3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Explicitly measure relative to the root XAML element",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
4 changes: 3 additions & 1 deletion vnext/Microsoft.ReactNative/Modules/NativeUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,9 @@ void NativeUIManager::measureInWindow(
ShadowNodeBase &node = static_cast<ShadowNodeBase &>(shadowNode);

if (auto view = node.GetView().try_as<xaml::FrameworkElement>()) {
auto windowTransform = view.TransformToVisual(xaml::Window::Current().Content());
// When supplied with nullptr, TransformToVisual will return the position
// relative to the root XAML element.
auto windowTransform = view.TransformToVisual(nullptr);
auto positionInWindow = windowTransform.TransformPoint({0, 0});

m_context.JSDispatcher().Post(
Expand Down

0 comments on commit 0a18b3d

Please sign in to comment.