microsoft / microsoft/react-native-windows

Breakup XamlUIService into separate APIs

Open
#10,430 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Agenda enhancement Needs: Dev Design Partner: Facebook Workstream: Component Parity
Dominant language
C++
Stars
17.3k
Forks
1.2k
Avg merge
1d 13h
Merged PRs (30d)
33

Description

Summary

It feels like over time, XamlUIService has become a bit of a dumping ground for various APIs.

  1. It was originally created in https://github.com/microsoft/react-native-windows/commit/2809c9a14a68cdbaa4b735b189197b5692af0d53 to handle looking up tags from elements.
  2. Then we added an option to get a singleton XamlRoot in https://github.com/microsoft/react-native-windows/commit/f52d4942a42ed75d6fa92594897d2f3d7db1b7d7
  3. Then we added options to set the HWND in https://github.com/microsoft/react-native-windows/commit/bdd23dc452f4167769e3166513524f263fd3cda0
  4. The an accessibility workaround in https://github.com/microsoft/react-native-windows/commit/2dfb964e57020226828867f816bd31cff25814b8
  5. There is a proposed addition for getting the React tag and ReactRootView here: https://github.com/microsoft/react-native-windows/pull/10403
  6. And another proposal for adding a mechanism to invoke nested Yoga layout here: https://github.com/microsoft/react-native-windows/pull/10237

It feels like we should separate concerns a bit here and expose a few new APIs:

  1. XamlUIService can remain as a translation layer between XAML views and the React shadow tree to fill the gap of missing shadow nodes in the exposed ABI, e.g.:
void XamlUIService::GetElementFromTag(int64_t tag)
void XamlUIService::GetReactTag(xaml::DependencyObject view)
ReactRootView XamlUIService::GetReactRootView(xaml::DependencyObject view)
  1. A per root view ReactWindowService could be added to ReactRootView to handle things like getting / setting the HWND, getting / setting the XamlRoot, getting / setting the accessibility root, etc.
ReactWindowService ReactRootView::WindowService()
void ReactWindowService::XamlRoot(XamlRoot root);
XamlRoot ReactWindowService::XamlRoot();
void ReactWindowService::HWND(int64_t);
uint64_t ReactWindowService::HWND();
// Do not exist yet, but would be needed to feed scale factors to Yoga
double ReactWindowService::ScaleFactor();
void ReactWindowService::ScaleFactor(double scaleFactor);
  1. A service for the AccessibilityInfoModule, AccessibilityInfoService:
AccessibilityInfoService ReactContext::AccessibilityInfoService();
void AccessibilityInfoService::AccessibleRoot(xaml::FrameworkElement root);
xaml::FrameworkElement AccessibilityInfoService::AccessibleRoot();
  1. An API for event dispatching, EventDispatcher:
EventDispatcher ReactContext::EventDispatcher()
void EventDispatcher::DispatchEvent(...)
// Does not exist yet, but would be useful
void EventDispatcher::DispatchCoalescedEvent(...)
  1. An API for UIManager, UIManagerService:
UIManagerService ReactContext::UIManagerService()
void UIManagerService::UpdateYogaLayout(int64_t tag);
// Does not exist yet, but would expose public surfaces for functionality in iOS/Android
void UIManagerService::AddOnBatchCompleteListener(...);
Motivation

Separation of concerns for the collection of methods exposed in XamlUIService.

Basic Example

No response

Open Questions

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing XamlUIService and the linked commits and proposals for ReactRootView, nested Yoga layout, and related APIs. Done means agreeing on service boundaries and migrating the relevant responsibilities without leaving XamlUIService as a dumping ground; the issue names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, react
Domain
desktop
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.