Fix XAML popup positioning and light dismiss in ScrollView (#15557)#15564
Fix XAML popup positioning and light dismiss in ScrollView (#15557)#15564Nitin-100 wants to merge 19 commits intomicrosoft:mainfrom
Conversation
…#15557) - Add SetXamlRoot() API on ContentIslandComponentView for 3rd party XAML components - Add DismissPopups() using VisualTreeHelper.GetOpenPopupsForXamlRoot() - Fire LayoutMetricsChanged on scroll to update popup positions - Dismiss child ContentIsland popups when scroll begins - Add ComboBox sample component demonstrating the pattern - Add xamlPopupBug test sample for playground-composition
sundaramramaswamy
left a comment
There was a problem hiding this comment.
Please address comments.
…#15557) - Set LocalToParentTransformMatrix synchronously before Connect() to fix initial position - Fire LayoutMetricsChanged on scroll to update position after scrolling - Add DismissPopupsRequest event for 3P components to implement light dismiss - Update ComboBox sample to use event-based approach (core remains XAML-agnostic)
Issue microsoft#15557: Fix popup positioning for XAML controls in ScrollView Bug 1 (Position Fix): - Convert getClientRect() physical pixels to DIPs by dividing by pointScaleFactor - LocalToParentTransformMatrix expects logical pixels (DIPs), not physical pixels - Update transform synchronously instead of async to avoid race conditions - Set initial transform in OnMounted() before Connect() Bug 2 (Light Dismiss Fix): - Add DismissPopupsRequest event for 3P components to handle popup dismissal - ScrollView fires event when scroll begins via DismissChildContentIslandPopups() - Core remains XAML-agnostic - 3P components handle their own popups
sundaramramaswamy
left a comment
There was a problem hiding this comment.
Please revert formatting changes.
f0d7eb5 to
e8cfe99
Compare
vnext/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp
Show resolved
Hide resolved
vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp
Outdated
Show resolved
Hide resolved
|
Assuming LocalToParentTransformMatrix is pretty cheap, the LocalToParentTransformMatrix changes look good. The light dismiss logic seems more wrong. This looks like we need additional hosting APIs from ContentIslands. ContentIslands should provide APIs to handle this kind of communication, and Xaml / RNW should talk to the new API. Xaml content islands should not have to know about RNW APIs - it breaks the ContentIsland encapsulation. |
vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp
Outdated
Show resolved
Hide resolved
vnext/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp
Show resolved
Hide resolved
|
@acoates-ms I have addressed all comments, please review it. |
* docs: fix broken markdown links * Address reviewer feedback * Remove obsolete docs and clean conflict markers * Delete managedCodeGen.md --------- Co-authored-by: Protik Biswas <protikbiswas@microsoft.com> Co-authored-by: Vineeth <66076509+vineethkuttan@users.noreply.github.com>
* Use automationoption as frameworkbased for childsite * Change files * remove tokens associated with fragment based
LocalToParentTransformMatrix: Yes, it's a cheap call - just sets a 4x4 matrix value. Confirmed working correctly. Light dismiss architecture: I agree this isn't ideal from an encapsulation perspective. I've implemented an event-based approach that keeps RNW core XAML-agnostic:
The 3rd party XAML component subscribes to You're right that ideally ContentIsland platform should provide this natively - perhaps via For now, this workaround unblocks the immediate customer scenario while maintaining XAML-agnostic core code. |
505103b to
db01f95
Compare
| m_layoutMetrics.frame.size.height}, | ||
| m_layoutMetrics.pointScaleFactor}; | ||
|
|
||
| m_layoutMetricsChangedEvent( |
There was a problem hiding this comment.
Firing a fake LayoutMetricsChanged event when the LayoutMetrics didn't change, seems wrong.
Instead, the ContentIslandComponentView could explicitly check for any scrollviews in the tree here:
ScrollViewComponentView should expose an ViewChanged event, similar to Xaml's ScrollViewer.
|
|
||
| // Issue #15557: Event fired when a parent ScrollView starts scrolling. | ||
| // 3rd party XAML components should subscribe to this event to dismiss any open popups. | ||
| event Windows.Foundation.EventHandler<IInspectable> DismissPopupsRequest; |
There was a problem hiding this comment.
I'd rather not expose events that we hope will be provided by content islands in the future. XamlComponents can do all of this external to RNW. They can register for the scroll events on all parent ScrollView's in their OnMount callbacks.
There was a problem hiding this comment.
XAML component has NO visibility into RNW tree
A 3rd party XAML control (like ComboBox) running inside ContentIsland cannot "walk up the tree to find ScrollViews" because:
-It only knows about XAML APIs
-ScrollViewComponentView is a C++ class in RNW, not a XAML control
-There's no way for XAML code to discover or subscribe to RNW's ComponentViews
ContentIsland API has NO scroll events
ContentIslandComponentView is the BRIDGE
It has access to:
-The RNW component tree (can walk up to find ScrollViewComponentViews)
-The XAML content (via Connect())
-This is why the event must be exposed here
The DismissPopupsRequest event is the minimal API surface needed. If ContentIsland adds scroll-related dismiss APIs in the future, we can deprecate this event.
There was a problem hiding this comment.
ContentIslandComponentView shouldn't know anything about XAML either.
In your example, ComboBoxComponentView is the component that knows about both RNW and Xaml. It can do the tree walk on mount to find the scrollviews, and register for scroll events.
Fix XAML popup positioning and light dismiss in ScrollView (#15557)
Description
This PR fixes Issue #15557 - "Pop-ups of Xaml controls need positioning and dismissal"
When XAML controls with popups (like ComboBox, DatePicker, TimePicker) are hosted inside a React Native ScrollView via
ContentIslandComponentView, two bugs occur:Root Cause Analysis
Bug 1: Popup Position
ContentIslandComponentViewusesChildSiteLink.LocalToParentTransformMatrixfor popup positioninggetClientRect()returns values in physical pixels (scaled bypointScaleFactor), butLocalToParentTransformMatrixexpects logical pixels (DIPs)UIDispatcher().Post(), causing race conditions where popup opened with stale transform valuesConnect(), causing wrong position even without scrollingBug 2: Light Dismiss on Scroll
Solution
Bug 1 Fix: Popup Position After Scroll
getClientRect()values bypointScaleFactorbefore settingLocalToParentTransformMatrixUIDispatcher().Post()wrapper - update transform immediatelyLocalToParentTransformMatrixinOnMounted()beforeConnect()ScrollViewComponentViewfiresLayoutMetricsChangedevent when scroll position changesBug 2 Fix: Light Dismiss on Scroll (Optimized)
DismissPopupsRequestevent toContentIslandComponentViewScrollBeginDragevent toScrollViewComponentViewOnMounted(),ContentIslandComponentViewwalks up the tree once and registers forScrollBeginDragon all parentScrollViewComponentViewinstancesScrollViewComponentViewfires itsScrollBeginDragevent, which notifies only the registeredContentIslandComponentViewinstancesDismissPopupsRequestand dismiss their own popupsFiles Changed
Core Fix (vnext/Microsoft.ReactNative/)
Fabric/Composition/ContentIslandComponentView.cpp- DIP conversion, sync updates, register for parent ScrollView events during mountFabric/Composition/ContentIslandComponentView.h- Store scroll subscriptionsFabric/Composition/ScrollViewComponentView.cpp- Fire LayoutMetricsChanged on scroll, expose ScrollBeginDrag eventFabric/Composition/ScrollViewComponentView.h- ScrollBeginDrag eventCompositionComponentView.idl- Added DismissPopupsRequest event to ContentIslandComponentView, ScrollBeginDrag event to ScrollViewComponentViewTesting
XamlPopupReprosample in Playground##Screenshot
testingFix.mp4