react-native-windows 0.82.0-preview.8 → 0.82.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/Libraries/Components/Switch/Switch.windows.js +1 -1
  2. package/Microsoft.ReactNative/ComponentView.idl +2 -0
  3. package/Microsoft.ReactNative/Composition.Input.idl +7 -0
  4. package/Microsoft.ReactNative/CompositionComponentView.idl +3 -0
  5. package/Microsoft.ReactNative/CompositionSwitcher.idl +8 -1
  6. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +18 -0
  7. package/Microsoft.ReactNative/Fabric/ComponentView.h +9 -0
  8. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.cpp +12 -0
  9. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.h +15 -0
  10. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp +15 -0
  11. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +75 -0
  12. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +1 -0
  13. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +161 -17
  14. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +4 -0
  15. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +56 -82
  16. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +7 -4
  17. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +46 -8
  18. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +6 -0
  19. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +33 -0
  20. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +17 -0
  21. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +45 -22
  22. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +3 -0
  23. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +42 -15
  24. package/PropertySheets/CIBuildOptimizations.props +29 -0
  25. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  26. package/PropertySheets/WinUI.props +1 -1
  27. package/README.md +1 -1
  28. package/Scripts/NuGetRestoreForceEvaluateAllSolutions.ps1 +5 -11
  29. package/Scripts/OfficeReact.Win32.nuspec +0 -11
  30. package/Scripts/rnw-dependencies.ps1 +15 -1
  31. package/Shared/Networking/WinRTWebSocketResource.cpp +5 -4
  32. package/package.json +6 -6
@@ -14,6 +14,7 @@
14
14
  #include <winrt/Windows.UI.Composition.h>
15
15
  #include "CompositionContextHelper.h"
16
16
  #include "RootComponentView.h"
17
+ #include "ScrollViewComponentView.h"
17
18
 
18
19
  #include "Composition.ContentIslandComponentView.g.cpp"
19
20
 
@@ -49,6 +50,14 @@ void ContentIslandComponentView::OnMounted() noexcept {
49
50
  .as<winrt::Microsoft::UI::Composition::ContainerVisual>());
50
51
  m_childSiteLink.ActualSize({m_layoutMetrics.frame.size.width, m_layoutMetrics.frame.size.height});
51
52
 
53
+ // Issue #15557: Set initial LocalToParentTransformMatrix synchronously before Connect.
54
+ // This fixes popup position being wrong even without scrolling.
55
+ // Note: getClientRect() returns physical pixels, but LocalToParentTransformMatrix expects DIPs.
56
+ auto clientRect = getClientRect();
57
+ float scaleFactor = m_layoutMetrics.pointScaleFactor;
58
+ m_childSiteLink.LocalToParentTransformMatrix(winrt::Windows::Foundation::Numerics::make_float4x4_translation(
59
+ static_cast<float>(clientRect.left) / scaleFactor, static_cast<float>(clientRect.top) / scaleFactor, 0.0f));
60
+
52
61
  m_navigationHost = winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteLink(m_childSiteLink);
53
62
 
54
63
  m_navigationHostDepartFocusRequestedToken =
@@ -80,12 +89,34 @@ void ContentIslandComponentView::OnMounted() noexcept {
80
89
  strongThis->ParentLayoutChanged();
81
90
  }
82
91
  }));
92
+
93
+ // Issue #15557: Register for ViewChanged on parent ScrollViews to update transform
94
+ // when scroll position changes, ensuring correct XAML popup positioning.
95
+ if (auto scrollView = view.try_as<winrt::Microsoft::ReactNative::Composition::ScrollViewComponentView>()) {
96
+ auto token =
97
+ scrollView.ViewChanged([wkThis = get_weak()](const winrt::IInspectable &, const winrt::IInspectable &) {
98
+ if (auto strongThis = wkThis.get()) {
99
+ strongThis->ParentLayoutChanged();
100
+ }
101
+ });
102
+ m_viewChangedSubscriptions.push_back({scrollView, token});
103
+ }
104
+
83
105
  view = view.Parent();
84
106
  }
85
107
  }
86
108
 
87
109
  void ContentIslandComponentView::OnUnmounted() noexcept {
88
110
  m_layoutMetricChangedRevokers.clear();
111
+
112
+ // Issue #15557: Unsubscribe from parent ScrollView events
113
+ for (auto &subscription : m_viewChangedSubscriptions) {
114
+ if (auto scrollView = subscription.scrollView.get()) {
115
+ scrollView.ViewChanged(subscription.token);
116
+ }
117
+ }
118
+ m_viewChangedSubscriptions.clear();
119
+
89
120
  if (m_navigationHostDepartFocusRequestedToken && m_navigationHost) {
90
121
  m_navigationHost.DepartFocusRequested(m_navigationHostDepartFocusRequestedToken);
91
122
  m_navigationHostDepartFocusRequestedToken = {};
@@ -93,21 +124,25 @@ void ContentIslandComponentView::OnUnmounted() noexcept {
93
124
  }
94
125
 
95
126
  void ContentIslandComponentView::ParentLayoutChanged() noexcept {
96
- if (m_layoutChangePosted)
97
- return;
98
-
99
- m_layoutChangePosted = true;
100
- ReactContext().UIDispatcher().Post([wkThis = get_weak()]() {
101
- if (auto strongThis = wkThis.get()) {
102
- auto clientRect = strongThis->getClientRect();
103
-
104
- strongThis->m_childSiteLink.LocalToParentTransformMatrix(
105
- winrt::Windows::Foundation::Numerics::make_float4x4_translation(
106
- static_cast<float>(clientRect.left), static_cast<float>(clientRect.top), 0.0f));
107
-
108
- strongThis->m_layoutChangePosted = false;
109
- }
110
- });
127
+ // Issue #15557: Update transform synchronously to ensure correct popup position
128
+ // when user clicks. Async updates via UIDispatcher().Post() were causing the
129
+ // popup to open with stale transform values.
130
+ //
131
+ // Note: The original async approach was for batching notifications during layout passes.
132
+ // However, LocalToParentTransformMatrix is a cheap call (just sets a matrix), and
133
+ // synchronous updates are required to ensure correct popup position when clicked.
134
+ //
135
+ // getClientRect() returns values in physical pixels (scaled by pointScaleFactor),
136
+ // but LocalToParentTransformMatrix expects logical pixels (DIPs). We need to divide
137
+ // by the scale factor to convert.
138
+ auto clientRect = getClientRect();
139
+ float scaleFactor = m_layoutMetrics.pointScaleFactor;
140
+
141
+ float x = static_cast<float>(clientRect.left) / scaleFactor;
142
+ float y = static_cast<float>(clientRect.top) / scaleFactor;
143
+
144
+ m_childSiteLink.LocalToParentTransformMatrix(
145
+ winrt::Windows::Foundation::Numerics::make_float4x4_translation(x, y, 0.0f));
111
146
  }
112
147
 
113
148
  winrt::Windows::Foundation::IInspectable ContentIslandComponentView::CreateAutomationProvider() noexcept {
@@ -171,24 +206,6 @@ ContentIslandComponentView::~ContentIslandComponentView() noexcept {
171
206
  m_navigationHost.DepartFocusRequested(m_navigationHostDepartFocusRequestedToken);
172
207
  m_navigationHostDepartFocusRequestedToken = {};
173
208
  }
174
- if (m_childSiteLink) {
175
- if (m_fragmentRootAutomationProviderRequestedToken) {
176
- m_childSiteLink.FragmentRootAutomationProviderRequested(m_fragmentRootAutomationProviderRequestedToken);
177
- m_fragmentRootAutomationProviderRequestedToken = {};
178
- }
179
- if (m_parentAutomationProviderRequestedToken) {
180
- m_childSiteLink.ParentAutomationProviderRequested(m_parentAutomationProviderRequestedToken);
181
- m_parentAutomationProviderRequestedToken = {};
182
- }
183
- if (m_nextSiblingAutomationProviderRequestedToken) {
184
- m_childSiteLink.NextSiblingAutomationProviderRequested(m_nextSiblingAutomationProviderRequestedToken);
185
- m_nextSiblingAutomationProviderRequestedToken = {};
186
- }
187
- if (m_previousSiblingAutomationProviderRequestedToken) {
188
- m_childSiteLink.PreviousSiblingAutomationProviderRequested(m_previousSiblingAutomationProviderRequestedToken);
189
- m_previousSiblingAutomationProviderRequestedToken = {};
190
- }
191
- }
192
209
  if (m_islandToConnect) {
193
210
  m_islandToConnect.Close();
194
211
  }
@@ -230,56 +247,13 @@ void ContentIslandComponentView::prepareForRecycle() noexcept {
230
247
  }
231
248
 
232
249
  void ContentIslandComponentView::ConfigureChildSiteLinkAutomation() noexcept {
233
- // This automation mode must be set before connecting the child ContentIsland.
234
- // It puts the child content into a mode where it won't own its own framework root. Instead, the child island's
235
- // automation peers will use the same framework root as the automation peer of this ContentIslandComponentView.
236
- m_childSiteLink.AutomationOption(winrt::Microsoft::UI::Content::ContentAutomationOptions::FragmentBased);
237
-
238
- // These events are raised in response to the child ContentIsland asking for providers.
239
- // For example, the ContentIsland.FragmentRootAutomationProvider property will return
240
- // the provider we provide here in FragmentRootAutomationProviderRequested.
241
-
242
- // We capture "this" as a raw pointer because ContentIslandComponentView doesn't currently support weak ptrs.
243
- // It's safe because we disconnect these events in the destructor.
244
-
245
- m_fragmentRootAutomationProviderRequestedToken = m_childSiteLink.FragmentRootAutomationProviderRequested(
246
- [this](
247
- const winrt::Microsoft::UI::Content::IContentSiteAutomation &,
248
- const winrt::Microsoft::UI::Content::ContentSiteAutomationProviderRequestedEventArgs &args) {
249
- // The child island's fragment tree doesn't have its own fragment root.
250
- // Here's how we can provide the correct fragment root to the child's UIA logic.
251
- winrt::com_ptr<IRawElementProviderFragmentRoot> fragmentRoot{nullptr};
252
- auto uiaProvider = this->EnsureUiaProvider();
253
- uiaProvider.as<IRawElementProviderFragment>()->get_FragmentRoot(fragmentRoot.put());
254
- args.AutomationProvider(fragmentRoot.as<IInspectable>());
255
- args.Handled(true);
256
- });
257
-
258
- m_parentAutomationProviderRequestedToken = m_childSiteLink.ParentAutomationProviderRequested(
259
- [this](
260
- const winrt::Microsoft::UI::Content::IContentSiteAutomation &,
261
- const winrt::Microsoft::UI::Content::ContentSiteAutomationProviderRequestedEventArgs &args) {
262
- auto uiaProvider = this->EnsureUiaProvider();
263
- args.AutomationProvider(uiaProvider);
264
- args.Handled(true);
265
- });
266
-
267
- m_nextSiblingAutomationProviderRequestedToken = m_childSiteLink.NextSiblingAutomationProviderRequested(
268
- [](const winrt::Microsoft::UI::Content::IContentSiteAutomation &,
269
- const winrt::Microsoft::UI::Content::ContentSiteAutomationProviderRequestedEventArgs &args) {
270
- // The ContentIsland will always be the one and only child of this node, so it won't have siblings.
271
- args.AutomationProvider(nullptr);
272
- args.Handled(true);
273
- });
274
-
275
- m_previousSiblingAutomationProviderRequestedToken = m_childSiteLink.PreviousSiblingAutomationProviderRequested(
276
- [](const winrt::Microsoft::UI::Content::IContentSiteAutomation &,
277
- const winrt::Microsoft::UI::Content::ContentSiteAutomationProviderRequestedEventArgs &args) {
278
- // The ContentIsland will always be the one and only child of this node, so it won't have siblings.
279
- args.AutomationProvider(nullptr);
280
- args.Handled(true);
281
- });
250
+ // Use FrameworkBased to let the XamlIsland manage its own framework-level accessibility tree
251
+ // and raise focus events naturally. This tells the system that the child island has its own
252
+ // framework (WinUI/XAML) that manages automation.
253
+ m_childSiteLink.AutomationOption(winrt::Microsoft::UI::Content::ContentAutomationOptions::FrameworkBased);
282
254
 
255
+ // When using FrameworkBased mode, we don't register automation callbacks - let the XamlIsland handle its own UIA
256
+ // tree.
283
257
  if (m_innerAutomationProvider) {
284
258
  m_innerAutomationProvider->SetChildSiteLink(m_childSiteLink);
285
259
  }
@@ -68,12 +68,15 @@ struct ContentIslandComponentView : ContentIslandComponentViewT<ContentIslandCom
68
68
  winrt::Microsoft::UI::Input::InputFocusNavigationHost m_navigationHost{nullptr};
69
69
  winrt::event_token m_navigationHostDepartFocusRequestedToken{};
70
70
 
71
+ // Issue #15557: Store ViewChanged subscriptions to parent ScrollViews for transform updates
72
+ struct ViewChangedSubscription {
73
+ winrt::weak_ref<winrt::Microsoft::ReactNative::Composition::ScrollViewComponentView> scrollView;
74
+ winrt::event_token token;
75
+ };
76
+ std::vector<ViewChangedSubscription> m_viewChangedSubscriptions;
77
+
71
78
  // Automation
72
79
  void ConfigureChildSiteLinkAutomation() noexcept;
73
- winrt::event_token m_fragmentRootAutomationProviderRequestedToken{};
74
- winrt::event_token m_parentAutomationProviderRequestedToken{};
75
- winrt::event_token m_nextSiblingAutomationProviderRequestedToken{};
76
- winrt::event_token m_previousSiblingAutomationProviderRequestedToken{};
77
80
  };
78
81
 
79
82
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -548,6 +548,7 @@ void ParagraphComponentView::ClearSelection() noexcept {
548
548
  m_selectionStart = std::nullopt;
549
549
  m_selectionEnd = std::nullopt;
550
550
  m_isSelecting = false;
551
+ m_isWordSelecting = false;
551
552
  if (hadSelection) {
552
553
  // Clears selection highlight
553
554
  DrawText();
@@ -598,7 +599,13 @@ void ParagraphComponentView::OnPointerPressed(
598
599
 
599
600
  if (isDoubleClick) {
600
601
  SelectWordAtPosition(*charPosition);
601
- m_isSelecting = false;
602
+ if (m_selectionStart && m_selectionEnd) {
603
+ m_isWordSelecting = true;
604
+ m_wordAnchorStart = *m_selectionStart;
605
+ m_wordAnchorEnd = *m_selectionEnd;
606
+ m_isSelecting = true;
607
+ CapturePointer(args.Pointer());
608
+ }
602
609
  } else {
603
610
  // Single-click: start drag selection
604
611
  m_selectionStart = charPosition;
@@ -640,10 +647,28 @@ void ParagraphComponentView::OnPointerMoved(
640
647
  facebook::react::Point localPt{position.X, position.Y};
641
648
  std::optional<int32_t> charPosition = GetClampedTextPosition(localPt);
642
649
 
643
- if (charPosition && charPosition != m_selectionEnd) {
644
- m_selectionEnd = charPosition;
645
- DrawText();
646
- args.Handled(true);
650
+ if (charPosition) {
651
+ if (m_isWordSelecting) {
652
+ // Extend selection by whole words
653
+ auto [wordStart, wordEnd] = GetWordBoundariesAtPosition(*charPosition);
654
+
655
+ if (*charPosition < m_wordAnchorStart) {
656
+ m_selectionStart = wordStart;
657
+ m_selectionEnd = m_wordAnchorEnd;
658
+ } else if (*charPosition >= m_wordAnchorEnd) {
659
+ m_selectionStart = m_wordAnchorStart;
660
+ m_selectionEnd = wordEnd;
661
+ } else {
662
+ m_selectionStart = m_wordAnchorStart;
663
+ m_selectionEnd = m_wordAnchorEnd;
664
+ }
665
+ DrawText();
666
+ args.Handled(true);
667
+ } else if (charPosition != m_selectionEnd) {
668
+ m_selectionEnd = charPosition;
669
+ DrawText();
670
+ args.Handled(true);
671
+ }
647
672
  }
648
673
  }
649
674
 
@@ -667,6 +692,7 @@ void ParagraphComponentView::OnPointerReleased(
667
692
  }
668
693
 
669
694
  m_isSelecting = false;
695
+ m_isWordSelecting = false;
670
696
 
671
697
  ReleasePointerCapture(args.Pointer());
672
698
 
@@ -691,6 +717,7 @@ void ParagraphComponentView::OnPointerCaptureLost() noexcept {
691
717
  // Pointer capture was lost stop any active selection drag
692
718
  if (m_isSelecting) {
693
719
  m_isSelecting = false;
720
+ m_isWordSelecting = false;
694
721
 
695
722
  if (!m_selectionStart || !m_selectionEnd || *m_selectionStart == *m_selectionEnd) {
696
723
  m_selectionStart = std::nullopt;
@@ -741,12 +768,17 @@ void ParagraphComponentView::CopySelectionToClipboard() noexcept {
741
768
  winrt::Windows::ApplicationModel::DataTransfer::Clipboard::SetContent(dataPackage);
742
769
  }
743
770
 
744
- void ParagraphComponentView::SelectWordAtPosition(int32_t charPosition) noexcept {
771
+ std::pair<int32_t, int32_t> ParagraphComponentView::GetWordBoundariesAtPosition(int32_t charPosition) noexcept {
745
772
  const std::wstring utf16Text{facebook::react::WindowsTextLayoutManager::GetTransformedText(m_attributedStringBox)};
746
773
  const int32_t textLength = static_cast<int32_t>(utf16Text.length());
747
774
 
748
- if (utf16Text.empty() || charPosition < 0 || charPosition >= textLength) {
749
- return;
775
+ if (utf16Text.empty() || charPosition < 0) {
776
+ return {0, 0};
777
+ }
778
+
779
+ charPosition = std::min(charPosition, textLength - 1);
780
+ if (charPosition < 0) {
781
+ return {0, 0};
750
782
  }
751
783
 
752
784
  int32_t wordStart = charPosition;
@@ -779,6 +811,12 @@ void ParagraphComponentView::SelectWordAtPosition(int32_t charPosition) noexcept
779
811
  }
780
812
  }
781
813
 
814
+ return {wordStart, wordEnd};
815
+ }
816
+
817
+ void ParagraphComponentView::SelectWordAtPosition(int32_t charPosition) noexcept {
818
+ auto [wordStart, wordEnd] = GetWordBoundariesAtPosition(charPosition);
819
+
782
820
  if (wordEnd > wordStart) {
783
821
  SetSelection(wordStart, wordEnd);
784
822
  DrawText();
@@ -98,6 +98,7 @@ struct ParagraphComponentView : ParagraphComponentViewT<ParagraphComponentView,
98
98
  void CopySelectionToClipboard() noexcept;
99
99
 
100
100
  void SelectWordAtPosition(int32_t charPosition) noexcept;
101
+ std::pair<int32_t, int32_t> GetWordBoundariesAtPosition(int32_t charPosition) noexcept;
101
102
 
102
103
  void ShowContextMenu() noexcept;
103
104
 
@@ -114,6 +115,11 @@ struct ParagraphComponentView : ParagraphComponentViewT<ParagraphComponentView,
114
115
  std::optional<int32_t> m_selectionEnd;
115
116
  bool m_isSelecting{false};
116
117
 
118
+ // Double click + drag selection
119
+ bool m_isWordSelecting{false};
120
+ int32_t m_wordAnchorStart{0};
121
+ int32_t m_wordAnchorEnd{0};
122
+
117
123
  // Double-click detection
118
124
  std::chrono::steady_clock::time_point m_lastClickTime{};
119
125
  std::optional<int32_t> m_lastClickPosition;
@@ -6,6 +6,7 @@
6
6
 
7
7
  #include "ScrollViewComponentView.h"
8
8
 
9
+ #include <Fabric/ComponentView.h>
9
10
  #include <Utils/ValueUtils.h>
10
11
 
11
12
  #pragma warning(push)
@@ -19,6 +20,8 @@
19
20
  #include <AutoDraw.h>
20
21
  #include <Fabric/DWriteHelpers.h>
21
22
  #include <unicode.h>
23
+ #include <functional>
24
+ #include "ContentIslandComponentView.h"
22
25
  #include "JSValueReader.h"
23
26
  #include "RootComponentView.h"
24
27
 
@@ -884,6 +887,13 @@ void ScrollViewComponentView::updateContentVisualSize() noexcept {
884
887
 
885
888
  void ScrollViewComponentView::prepareForRecycle() noexcept {}
886
889
 
890
+ void ScrollViewComponentView::updateChildrenClippingPath(
891
+ facebook::react::LayoutMetrics const & /*layoutMetrics*/,
892
+ const facebook::react::ViewProps & /*viewProps*/) noexcept {
893
+ // No-op: ScrollView mounts children into m_scrollVisual (not Visual()),
894
+ // and scroll visuals inherently clip their content.
895
+ }
896
+
887
897
  /*
888
898
  ScrollViewComponentView::ScrollInteractionTrackerOwner::ScrollInteractionTrackerOwner(
889
899
  ScrollViewComponentView *outer)
@@ -1325,6 +1335,10 @@ winrt::Microsoft::ReactNative::Composition::Experimental::IVisual ScrollViewComp
1325
1335
  m_allowNextScrollNoMatterWhat = false;
1326
1336
  }
1327
1337
  }
1338
+
1339
+ // Issue #15557: Notify listeners that scroll position has changed,
1340
+ // so ContentIslandComponentView can update LocalToParentTransformMatrix
1341
+ FireViewChanged();
1328
1342
  });
1329
1343
 
1330
1344
  m_scrollBeginDragRevoker = m_scrollVisual.ScrollBeginDrag(
@@ -1332,6 +1346,9 @@ winrt::Microsoft::ReactNative::Composition::Experimental::IVisual ScrollViewComp
1332
1346
  [this](
1333
1347
  winrt::IInspectable const & /*sender*/,
1334
1348
  winrt::Microsoft::ReactNative::Composition::Experimental::IScrollPositionChangedArgs const &args) {
1349
+ // Issue #15557: Notify listeners that scroll position has changed
1350
+ FireViewChanged();
1351
+
1335
1352
  m_allowNextScrollNoMatterWhat = true; // Ensure next scroll event is recorded, regardless of throttle
1336
1353
  updateStateWithContentOffset();
1337
1354
  auto eventEmitter = GetEventEmitter();
@@ -1478,4 +1495,20 @@ void ScrollViewComponentView::updateShowsVerticalScrollIndicator(bool value) noe
1478
1495
  void ScrollViewComponentView::updateDecelerationRate(float value) noexcept {
1479
1496
  m_scrollVisual.SetDecelerationRate({value, value, value});
1480
1497
  }
1498
+
1499
+ // Issue #15557: Notify listeners that scroll position has changed.
1500
+ // ContentIslandComponentView subscribes to this to update LocalToParentTransformMatrix.
1501
+ void ScrollViewComponentView::FireViewChanged() noexcept {
1502
+ m_viewChangedEvent(*this, nullptr);
1503
+ }
1504
+
1505
+ // Issue #15557: Event accessors for ViewChanged
1506
+ winrt::event_token ScrollViewComponentView::ViewChanged(
1507
+ winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable> const &handler) noexcept {
1508
+ return m_viewChangedEvent.add(handler);
1509
+ }
1510
+
1511
+ void ScrollViewComponentView::ViewChanged(winrt::event_token const &token) noexcept {
1512
+ m_viewChangedEvent.remove(token);
1513
+ }
1481
1514
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -118,6 +118,18 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
118
118
  double getVerticalSize() noexcept;
119
119
  double getHorizontalSize() noexcept;
120
120
 
121
+ // Issue #15557: Event accessors for ViewChanged (used by ContentIslandComponentView for transform update)
122
+ winrt::event_token ViewChanged(
123
+ winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable> const &handler) noexcept;
124
+ void ViewChanged(winrt::event_token const &token) noexcept;
125
+
126
+ protected:
127
+ // ScrollView mounts children into m_scrollVisual (not Visual()), and scroll visuals
128
+ // inherently clip their content, so we skip the children container clipping logic.
129
+ void updateChildrenClippingPath(
130
+ facebook::react::LayoutMetrics const &layoutMetrics,
131
+ const facebook::react::ViewProps &viewProps) noexcept override;
132
+
121
133
  private:
122
134
  void updateDecelerationRate(float value) noexcept;
123
135
  void updateContentVisualSize() noexcept;
@@ -129,6 +141,8 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
129
141
  bool scrollRight(float delta, bool animate) noexcept;
130
142
  void updateBackgroundColor(const facebook::react::SharedColor &color) noexcept;
131
143
  void updateStateWithContentOffset() noexcept;
144
+ // Issue #15557: Notify listeners that scroll position has changed
145
+ void FireViewChanged() noexcept;
132
146
  facebook::react::ScrollViewEventEmitter::Metrics getScrollMetrics(
133
147
  facebook::react::SharedViewEventEmitter const &eventEmitter,
134
148
  winrt::Microsoft::ReactNative::Composition::Experimental::IScrollPositionChangedArgs const &args) noexcept;
@@ -160,6 +174,9 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
160
174
  bool m_allowNextScrollNoMatterWhat{false};
161
175
  std::chrono::steady_clock::time_point m_lastScrollEventTime{};
162
176
  std::shared_ptr<facebook::react::ScrollViewShadowNode::ConcreteState const> m_state;
177
+
178
+ // Issue #15557: Event for notifying listeners when scroll position changes
179
+ winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>> m_viewChangedEvent;
163
180
  };
164
181
 
165
182
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -186,6 +186,7 @@ struct CompTextHost : public winrt::implements<CompTextHost, ITextHost> {
186
186
 
187
187
  auto pt = m_outer->getClientOffset();
188
188
  m_outer->m_caretVisual.Position({x - pt.x, y - pt.y});
189
+ m_outer->m_caretPosition = {x, y};
189
190
  return true;
190
191
  }
191
192
 
@@ -696,17 +697,10 @@ void WindowsTextInputComponentView::OnPointerPressed(
696
697
  }
697
698
 
698
699
  if (m_textServices && msg) {
699
- if (msg == WM_RBUTTONUP && !windowsTextInputProps().contextMenuHidden) {
700
- ShowContextMenu(position);
701
- args.Handled(true);
702
- } else if (msg == WM_RBUTTONUP && windowsTextInputProps().contextMenuHidden) {
703
- args.Handled(true);
704
- } else {
705
- LRESULT lresult;
706
- DrawBlock db(*this);
707
- auto hr = m_textServices->TxSendMessage(msg, static_cast<WPARAM>(wParam), static_cast<LPARAM>(lParam), &lresult);
708
- args.Handled(hr != S_FALSE);
709
- }
700
+ LRESULT lresult;
701
+ DrawBlock db(*this);
702
+ auto hr = m_textServices->TxSendMessage(msg, static_cast<WPARAM>(wParam), static_cast<LPARAM>(lParam), &lresult);
703
+ args.Handled(hr != S_FALSE);
710
704
  }
711
705
 
712
706
  // Emits the OnPressIn event
@@ -768,10 +762,18 @@ void WindowsTextInputComponentView::OnPointerReleased(
768
762
  }
769
763
 
770
764
  if (m_textServices && msg) {
771
- LRESULT lresult;
772
- DrawBlock db(*this);
773
- auto hr = m_textServices->TxSendMessage(msg, static_cast<WPARAM>(wParam), static_cast<LPARAM>(lParam), &lresult);
774
- args.Handled(hr != S_FALSE);
765
+ // Show context menu on right button release (standard Windows behavior)
766
+ if (msg == WM_RBUTTONUP && !windowsTextInputProps().contextMenuHidden) {
767
+ ShowContextMenu(LocalToScreen(position));
768
+ args.Handled(true);
769
+ } else if (msg == WM_RBUTTONUP) {
770
+ // Context menu is hidden - don't mark as handled, let app add custom behavior
771
+ } else {
772
+ LRESULT lresult;
773
+ DrawBlock db(*this);
774
+ auto hr = m_textServices->TxSendMessage(msg, static_cast<WPARAM>(wParam), static_cast<LPARAM>(lParam), &lresult);
775
+ args.Handled(hr != S_FALSE);
776
+ }
775
777
  }
776
778
 
777
779
  // Emits the OnPressOut event
@@ -1225,8 +1227,11 @@ void WindowsTextInputComponentView::updateState(
1225
1227
  if (m_mostRecentEventCount == m_state->getData().mostRecentEventCount) {
1226
1228
  m_comingFromState = true;
1227
1229
  auto &fragments = m_state->getData().attributedStringBox.getValue().getFragments();
1228
- UpdateText(fragments.size() ? fragments[0].string : "");
1229
-
1230
+ {
1231
+ // DrawBlock defers DrawText() until after UpdateText completes
1232
+ DrawBlock db(*this);
1233
+ UpdateText(fragments.size() ? fragments[0].string : "");
1234
+ }
1230
1235
  m_comingFromState = false;
1231
1236
  }
1232
1237
  }
@@ -1375,7 +1380,7 @@ void WindowsTextInputComponentView::EmitOnScrollEvent() noexcept {
1375
1380
  }
1376
1381
 
1377
1382
  void WindowsTextInputComponentView::OnSelectionChanged(LONG start, LONG end) noexcept {
1378
- if (m_eventEmitter && !m_comingFromState /* && !m_comingFromJS ?? */) {
1383
+ if (m_eventEmitter && !m_comingFromState && !m_comingFromJS) {
1379
1384
  auto emitter = std::static_pointer_cast<const facebook::react::WindowsTextInputEventEmitter>(m_eventEmitter);
1380
1385
  facebook::react::WindowsTextInputEventEmitter::OnSelectionChange onSelectionChangeArgs;
1381
1386
  onSelectionChangeArgs.selection.start = start;
@@ -1879,6 +1884,21 @@ void WindowsTextInputComponentView::updateSpellCheck(bool enable) noexcept {
1879
1884
  m_textServices->TxSendMessage(EM_SETLANGOPTIONS, IMF_SPELLCHECKING, enable ? newLangOptions : 0, &lresult));
1880
1885
  }
1881
1886
 
1887
+ void WindowsTextInputComponentView::OnContextMenuKey(
1888
+ const winrt::Microsoft::ReactNative::Composition::Input::ContextMenuKeyEventArgs &args) noexcept {
1889
+ // Handle context menu key event (SHIFT+F10 or Context Menu key)
1890
+ if (!windowsTextInputProps().contextMenuHidden) {
1891
+ // m_caretPosition is stored from TxSetCaretPos in RichEdit client rect space (physical pixels).
1892
+ // LocalToScreen expects logical (DIP) coordinates, so divide by pointScaleFactor.
1893
+ auto screenPt = LocalToScreen(winrt::Windows::Foundation::Point{
1894
+ static_cast<float>(m_caretPosition.x) / m_layoutMetrics.pointScaleFactor,
1895
+ static_cast<float>(m_caretPosition.y) / m_layoutMetrics.pointScaleFactor});
1896
+ ShowContextMenu(screenPt);
1897
+ args.Handled(true);
1898
+ }
1899
+ // If contextMenuHidden, don't mark as handled - let app handle it
1900
+ }
1901
+
1882
1902
  void WindowsTextInputComponentView::ShowContextMenu(const winrt::Windows::Foundation::Point &position) noexcept {
1883
1903
  HMENU menu = CreatePopupMenu();
1884
1904
  if (!menu)
@@ -1898,13 +1918,16 @@ void WindowsTextInputComponentView::ShowContextMenu(const winrt::Windows::Founda
1898
1918
  AppendMenuW(menu, MF_STRING | (canPaste ? 0 : MF_GRAYED), 3, L"Paste");
1899
1919
  AppendMenuW(menu, MF_STRING | (!isEmpty && !isReadOnly ? 0 : MF_GRAYED), 4, L"Select All");
1900
1920
 
1901
- POINT cursorPos;
1902
- GetCursorPos(&cursorPos);
1903
-
1904
1921
  HWND hwnd = GetActiveWindow();
1905
1922
 
1906
1923
  int cmd = TrackPopupMenu(
1907
- menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_NONOTIFY, cursorPos.x, cursorPos.y, 0, hwnd, NULL);
1924
+ menu,
1925
+ TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_NONOTIFY,
1926
+ static_cast<int>(position.X),
1927
+ static_cast<int>(position.Y),
1928
+ 0,
1929
+ hwnd,
1930
+ NULL);
1908
1931
 
1909
1932
  if (cmd == 1) { // Cut
1910
1933
  m_textServices->TxSendMessage(WM_CUT, 0, 0, &res);
@@ -67,6 +67,8 @@ struct WindowsTextInputComponentView
67
67
  void OnKeyUp(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
68
68
  void OnCharacterReceived(const winrt::Microsoft::ReactNative::Composition::Input::CharacterReceivedRoutedEventArgs
69
69
  &args) noexcept override;
70
+ void OnContextMenuKey(
71
+ const winrt::Microsoft::ReactNative::Composition::Input::ContextMenuKeyEventArgs &args) noexcept override;
70
72
  void onMounted() noexcept override;
71
73
 
72
74
  std::optional<std::string> getAccessiblityValue() noexcept override;
@@ -146,6 +148,7 @@ struct WindowsTextInputComponentView
146
148
  DWORD m_propBitsMask{0};
147
149
  DWORD m_propBits{0};
148
150
  HCURSOR m_hcursor{nullptr};
151
+ POINT m_caretPosition{0, 0};
149
152
  std::chrono::steady_clock::time_point m_lastClickTime{};
150
153
  std::vector<facebook::react::CompWindowsTextInputSubmitKeyEventsStruct> m_submitKeyEvents;
151
154
  };