microsoft / microsoft/react-native-windows
Breakup XamlUIService into separate APIs
Nobody has claimed this yet.
- 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.
- It was originally created in https://github.com/microsoft/react-native-windows/commit/2809c9a14a68cdbaa4b735b189197b5692af0d53 to handle looking up tags from elements.
- Then we added an option to get a singleton XamlRoot in https://github.com/microsoft/react-native-windows/commit/f52d4942a42ed75d6fa92594897d2f3d7db1b7d7
- Then we added options to set the HWND in https://github.com/microsoft/react-native-windows/commit/bdd23dc452f4167769e3166513524f263fd3cda0
- The an accessibility workaround in https://github.com/microsoft/react-native-windows/commit/2dfb964e57020226828867f816bd31cff25814b8
- There is a proposed addition for getting the React tag and ReactRootView here: https://github.com/microsoft/react-native-windows/pull/10403
- 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:
XamlUIServicecan 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)
- A per root view
ReactWindowServicecould 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);
- A service for the AccessibilityInfoModule,
AccessibilityInfoService:
AccessibilityInfoService ReactContext::AccessibilityInfoService();
void AccessibilityInfoService::AccessibleRoot(xaml::FrameworkElement root);
xaml::FrameworkElement AccessibilityInfoService::AccessibleRoot();
- An API for event dispatching,
EventDispatcher:
EventDispatcher ReactContext::EventDispatcher()
void EventDispatcher::DispatchEvent(...)
// Does not exist yet, but would be useful
void EventDispatcher::DispatchCoalescedEvent(...)
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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