react-native-windows 0.75.1 → 0.75.2

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 (53) hide show
  1. package/Microsoft.ReactNative/ComponentView.idl +33 -32
  2. package/Microsoft.ReactNative/Composition.Input.idl +2 -0
  3. package/Microsoft.ReactNative/CompositionComponentView.idl +43 -24
  4. package/Microsoft.ReactNative/Fabric/AbiEventEmitter.cpp +21 -0
  5. package/Microsoft.ReactNative/Fabric/AbiEventEmitter.h +23 -0
  6. package/Microsoft.ReactNative/Fabric/AbiShadowNode.cpp +7 -0
  7. package/Microsoft.ReactNative/Fabric/AbiShadowNode.h +3 -0
  8. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +318 -59
  9. package/Microsoft.ReactNative/Fabric/ComponentView.h +155 -33
  10. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.cpp +2 -2
  11. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +3 -0
  12. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.cpp +25 -7
  13. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.h +22 -4
  14. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +43 -0
  15. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +6 -1
  16. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +147 -119
  17. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +4 -8
  18. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +97 -101
  19. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +28 -52
  20. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +133 -0
  21. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +61 -0
  22. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +1 -2
  23. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +1 -4
  24. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +1 -2
  25. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +1 -6
  26. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +0 -1
  27. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +108 -18
  28. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +33 -5
  29. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +57 -1
  30. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +6 -0
  31. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +8 -2
  32. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +2 -0
  33. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +195 -182
  34. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +1 -3
  35. package/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.cpp +16 -4
  36. package/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.h +3 -3
  37. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +12 -17
  38. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +4 -11
  39. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +19 -0
  40. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +4 -0
  41. package/Microsoft.ReactNative/Fabric/Composition/UnimplementedNativeViewComponentView.cpp +1 -2
  42. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +10 -7
  43. package/Microsoft.ReactNative/Fabric/WindowsComponentDescriptorRegistry.cpp +1 -3
  44. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.cpp +20 -1
  45. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.h +3 -0
  46. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +13 -3
  47. package/Microsoft.ReactNative/IReactViewComponentBuilder.idl +57 -4
  48. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -0
  49. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  50. package/PropertySheets/WinUI.props +1 -1
  51. package/Shared/Shared.vcxitems +7 -0
  52. package/just-task.js +1 -1
  53. package/package.json +3 -3
@@ -31,46 +31,12 @@
31
31
 
32
32
  namespace winrt::Microsoft::ReactNative::Composition::implementation {
33
33
 
34
- CreateCompositionComponentViewArgs::CreateCompositionComponentViewArgs(
35
- const winrt::Microsoft::ReactNative::IReactContext &reactContext,
36
- facebook::react::Tag tag,
37
- const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compositionContext)
38
- : base_type(reactContext, tag), m_compositionContext(compositionContext){};
39
-
40
- winrt::Microsoft::UI::Composition::Compositor CreateCompositionComponentViewArgs::Compositor() const noexcept {
41
- return winrt::Microsoft::ReactNative::Composition::CompositionUIService::GetCompositor(ReactContext().Properties());
42
- }
43
-
44
- winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext
45
- CreateCompositionComponentViewArgs::CompositionContext() const noexcept {
46
- return m_compositionContext;
47
- }
48
-
49
- ComponentViewFeatures CreateCompositionComponentViewArgs::Features() const noexcept {
50
- return m_features;
51
- }
52
-
53
- void CreateCompositionComponentViewArgs::Features(ComponentViewFeatures value) noexcept {
54
- m_features = value;
55
- }
56
-
57
- ComponentView::ComponentView(const winrt::Microsoft::ReactNative::Composition::CreateCompositionComponentViewArgs &args)
58
- : ComponentView(
59
- winrt::get_self<
60
- winrt::Microsoft::ReactNative::Composition::implementation::CreateCompositionComponentViewArgs>(args)
61
- ->CompositionContext(),
62
- args.Tag(),
63
- args.ReactContext(),
64
- args.Features(),
65
- true) {}
66
-
67
34
  ComponentView::ComponentView(
68
35
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
69
36
  facebook::react::Tag tag,
70
37
  winrt::Microsoft::ReactNative::ReactContext const &reactContext,
71
- ComponentViewFeatures flags,
72
- bool customControl)
73
- : base_type(tag, reactContext, customControl), m_compContext(compContext), m_flags(flags) {
38
+ ComponentViewFeatures flags)
39
+ : base_type(tag, reactContext), m_compContext(compContext), m_flags(flags) {
74
40
  m_outerVisual = compContext.CreateSpriteVisual(); // TODO could be a raw ContainerVisual if we had a
75
41
  // CreateContainerVisual in ICompositionContext
76
42
  m_focusVisual = compContext.CreateFocusVisual();
@@ -105,14 +71,18 @@ void ComponentView::onThemeChanged() noexcept {
105
71
 
106
72
  base_type::onThemeChanged();
107
73
 
108
- if (m_customComponent) {
109
- // Review is it expected that I need this cast to call overridden methods?
110
- winrt::Microsoft::ReactNative::Composition::ComponentView outer(*this);
111
- outer.OnThemeChanged();
74
+ if (m_themeChangedEvent) {
75
+ m_themeChangedEvent(*this, *this);
112
76
  }
113
77
  }
114
78
 
115
- void ComponentView::OnThemeChanged() noexcept {}
79
+ winrt::event_token ComponentView::ThemeChanged(
80
+ winrt::Windows::Foundation::EventHandler<winrt::IInspectable> const &handler) noexcept {
81
+ return m_themeChangedEvent.add(handler);
82
+ }
83
+ void ComponentView::ThemeChanged(winrt::event_token const &token) noexcept {
84
+ m_themeChangedEvent.remove(token);
85
+ }
116
86
 
117
87
  void ComponentView::Theme(const winrt::Microsoft::ReactNative::Composition::Theme &value) noexcept {
118
88
  theme(winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::Theme>(value));
@@ -170,10 +140,8 @@ void ComponentView::updateLayoutMetrics(
170
140
  updateBorderLayoutMetrics(layoutMetrics, *viewProps());
171
141
  }
172
142
 
173
- m_layoutMetrics = layoutMetrics;
174
- UpdateCenterPropertySet();
175
-
176
143
  base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
144
+ UpdateCenterPropertySet();
177
145
  }
178
146
 
179
147
  const facebook::react::LayoutMetrics &ComponentView::layoutMetrics() const noexcept {
@@ -277,6 +245,7 @@ void ComponentView::StartBringIntoView(
277
245
 
278
246
  void ComponentView::updateEventEmitter(facebook::react::EventEmitter::Shared const &eventEmitter) noexcept {
279
247
  m_eventEmitter = std::static_pointer_cast<facebook::react::ViewEventEmitter const>(eventEmitter);
248
+ base_type::updateEventEmitter(eventEmitter);
280
249
  }
281
250
 
282
251
  void ComponentView::HandleCommand(
@@ -294,7 +263,8 @@ void ComponentView::HandleCommand(
294
263
  }
295
264
  return;
296
265
  }
297
- assert(false); // Unhandled command
266
+
267
+ base_type::HandleCommand(commandName, args);
298
268
  }
299
269
 
300
270
  bool ComponentView::CapturePointer(const winrt::Microsoft::ReactNative::Composition::Input::Pointer &pointer) noexcept {
@@ -1323,6 +1293,21 @@ void ComponentView::updateAccessibilityProps(
1323
1293
 
1324
1294
  winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
1325
1295
  m_uiaProvider, UIA_HelpTextPropertyId, oldViewProps.accessibilityHint, newViewProps.accessibilityHint);
1296
+
1297
+ winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
1298
+ m_uiaProvider,
1299
+ UIA_PositionInSetPropertyId,
1300
+ oldViewProps.accessibilityPosInSet,
1301
+ newViewProps.accessibilityPosInSet);
1302
+
1303
+ winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
1304
+ m_uiaProvider, UIA_SizeOfSetPropertyId, oldViewProps.accessibilitySetSize, newViewProps.accessibilitySetSize);
1305
+
1306
+ winrt::Microsoft::ReactNative::implementation::UpdateUiaProperty(
1307
+ m_uiaProvider,
1308
+ UIA_LiveSettingPropertyId,
1309
+ oldViewProps.accessibilityLiveRegion,
1310
+ newViewProps.accessibilityLiveRegion);
1326
1311
  }
1327
1312
 
1328
1313
  std::optional<std::string> ComponentView::getAcccessiblityValue() noexcept {
@@ -1337,6 +1322,14 @@ bool ComponentView::getAcccessiblityIsReadOnly() noexcept {
1337
1322
  return true;
1338
1323
  }
1339
1324
 
1325
+ ToggleState ComponentView::getToggleState() noexcept {
1326
+ return ToggleState::ToggleState_Off;
1327
+ }
1328
+
1329
+ void ComponentView::Toggle() noexcept {
1330
+ // no-op
1331
+ }
1332
+
1340
1333
  void ComponentView::updateBorderLayoutMetrics(
1341
1334
  facebook::react::LayoutMetrics const &layoutMetrics,
1342
1335
  const facebook::react::ViewProps &viewProps) noexcept {
@@ -1483,18 +1476,6 @@ std::string ComponentView::DefaultHelpText() const noexcept {
1483
1476
  return "";
1484
1477
  }
1485
1478
 
1486
- ViewComponentView::ViewComponentView(
1487
- const winrt::Microsoft::ReactNative::Composition::CreateCompositionComponentViewArgs &args)
1488
- : ViewComponentView(
1489
- ViewComponentView::defaultProps(),
1490
- winrt::get_self<
1491
- winrt::Microsoft::ReactNative::Composition::implementation::CreateCompositionComponentViewArgs>(args)
1492
- ->CompositionContext(),
1493
- args.Tag(),
1494
- args.ReactContext(),
1495
- args.Features(),
1496
- true) {}
1497
-
1498
1479
  facebook::react::SharedViewProps ViewComponentView::defaultProps() noexcept {
1499
1480
  static auto const defaultViewProps = std::make_shared<facebook::react::ViewProps const>();
1500
1481
  return defaultViewProps;
@@ -1505,33 +1486,42 @@ ViewComponentView::ViewComponentView(
1505
1486
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
1506
1487
  facebook::react::Tag tag,
1507
1488
  winrt::Microsoft::ReactNative::ReactContext const &reactContext,
1508
- ComponentViewFeatures flags,
1509
- bool customComponent)
1510
- : base_type(compContext, tag, reactContext, flags, customComponent),
1489
+ ComponentViewFeatures flags)
1490
+ : base_type(compContext, tag, reactContext, flags),
1511
1491
  m_props(defaultProps ? defaultProps : ViewComponentView::defaultProps()) {}
1512
1492
 
1513
1493
  winrt::Microsoft::ReactNative::Composition::Experimental::IVisual ViewComponentView::createVisual() noexcept {
1514
1494
  return m_compContext.CreateSpriteVisual();
1515
1495
  }
1516
1496
 
1517
- winrt::Microsoft::UI::Composition::Visual ViewComponentView::CreateVisual() noexcept {
1518
- return winrt::Microsoft::ReactNative::Composition::Experimental::MicrosoftCompositionContextHelper::InnerVisual(
1519
- createVisual());
1497
+ void ViewComponentView::CreateVisualHandler(
1498
+ const winrt::Microsoft::ReactNative::Composition::CreateVisualDelegate &handler) {
1499
+ m_createVisualHandler = handler;
1500
+ }
1501
+
1502
+ winrt::Microsoft::ReactNative::Composition::CreateVisualDelegate ViewComponentView::CreateVisualHandler()
1503
+ const noexcept {
1504
+ return m_createVisualHandler;
1505
+ }
1506
+
1507
+ void ViewComponentView::CreateInternalVisualHandler(
1508
+ const winrt::Microsoft::ReactNative::Composition::Experimental::CreateInternalVisualDelegate &handler) {
1509
+ m_createInternalVisualHandler = handler;
1510
+ }
1511
+
1512
+ winrt::Microsoft::ReactNative::Composition::Experimental::CreateInternalVisualDelegate
1513
+ ViewComponentView::CreateInternalVisualHandler() const noexcept {
1514
+ return m_createInternalVisualHandler;
1520
1515
  }
1521
1516
 
1522
1517
  void ViewComponentView::ensureVisual() noexcept {
1523
1518
  if (!m_visual) {
1524
- if (m_customComponent) {
1525
- // Review is it expected that I need this cast to call overridden methods?
1526
- winrt::Microsoft::ReactNative::Composition::ViewComponentView outer(*this);
1527
- winrt::Microsoft::ReactNative::Composition::Experimental::IInternalCreateVisual internalCreateVisual{nullptr};
1528
- if (outer.try_as(internalCreateVisual)) {
1529
- m_visual = internalCreateVisual.CreateInternalVisual();
1530
- } else {
1531
- m_visual =
1532
- winrt::Microsoft::ReactNative::Composition::Experimental::MicrosoftCompositionContextHelper::CreateVisual(
1533
- outer.CreateVisual());
1534
- }
1519
+ if (m_createInternalVisualHandler) {
1520
+ m_visual = m_createInternalVisualHandler(*this);
1521
+ } else if (m_createVisualHandler) {
1522
+ m_visual =
1523
+ winrt::Microsoft::ReactNative::Composition::Experimental::MicrosoftCompositionContextHelper::CreateVisual(
1524
+ m_createVisualHandler(*this));
1535
1525
  } else {
1536
1526
  m_visual = createVisual();
1537
1527
  }
@@ -1544,7 +1534,7 @@ winrt::Microsoft::ReactNative::ComponentView ViewComponentView::Create(
1544
1534
  facebook::react::Tag tag,
1545
1535
  winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept {
1546
1536
  return winrt::make<ViewComponentView>(
1547
- ViewComponentView::defaultProps(), compContext, tag, reactContext, ComponentViewFeatures::Default, false);
1537
+ ViewComponentView::defaultProps(), compContext, tag, reactContext, ComponentViewFeatures::Default);
1548
1538
  }
1549
1539
 
1550
1540
  void ViewComponentView::MountChildComponentView(
@@ -1555,10 +1545,20 @@ void ViewComponentView::MountChildComponentView(
1555
1545
  indexOffsetForBorder(index);
1556
1546
  ensureVisual();
1557
1547
 
1558
- // TODO if we get mixed children of composition and non-composition ComponentViews the indexes will get mixed up
1559
- // We could offset the index based on non-composition children in m_children
1560
1548
  if (auto compositionChild = childComponentView.try_as<ComponentView>()) {
1561
- Visual().InsertAt(compositionChild->OuterVisual(), index);
1549
+ auto visualIndex = index;
1550
+ // Most of the time child index will align with visual index.
1551
+ // But if we have non-visual children, we need to account for that.
1552
+ if (m_hasNonVisualChildren) {
1553
+ for (uint32_t i = 0; i <= index; i++) {
1554
+ if (!m_children.GetAt(i).try_as<ComponentView>()) {
1555
+ visualIndex--;
1556
+ }
1557
+ }
1558
+ }
1559
+ Visual().InsertAt(compositionChild->OuterVisual(), visualIndex);
1560
+ } else {
1561
+ m_hasNonVisualChildren = true;
1562
1562
  }
1563
1563
  }
1564
1564
 
@@ -1597,7 +1597,6 @@ void ViewComponentView::updateProps(
1597
1597
 
1598
1598
  const winrt::Microsoft::ReactNative::IComponentProps ViewComponentView::userProps(
1599
1599
  facebook::react::Props::Shared const &props) noexcept {
1600
- assert(m_customComponent);
1601
1600
  const auto &abiViewProps = *std::static_pointer_cast<const ::Microsoft::ReactNative::AbiViewProps>(props);
1602
1601
  return abiViewProps.UserProps();
1603
1602
  }
@@ -1663,22 +1662,21 @@ std::string CodeFromVirtualKey(
1663
1662
  }
1664
1663
 
1665
1664
  void ViewComponentView::OnKeyDown(
1666
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
1667
1665
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
1668
- auto eventCode = CodeFromVirtualKey(source, args.Key());
1666
+ auto eventCode = CodeFromVirtualKey(args.KeyboardSource(), args.Key());
1669
1667
  bool fShift =
1670
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
1668
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
1671
1669
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
1672
1670
  bool fAlt =
1673
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Menu) &
1671
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Menu) &
1674
1672
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
1675
1673
  bool fCtrl =
1676
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
1674
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
1677
1675
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
1678
1676
  bool fMeta =
1679
- ((source.GetKeyState(winrt::Windows::System::VirtualKey::LeftWindows) &
1677
+ ((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::LeftWindows) &
1680
1678
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ||
1681
- ((source.GetKeyState(winrt::Windows::System::VirtualKey::RightWindows) &
1679
+ ((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::RightWindows) &
1682
1680
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down);
1683
1681
 
1684
1682
  if (args.OriginalSource() == Tag() && !args.Handled()) {
@@ -1691,7 +1689,7 @@ void ViewComponentView::OnKeyDown(
1691
1689
  event.key = ::Microsoft::ReactNative::FromVirtualKey(
1692
1690
  args.Key(),
1693
1691
  event.shiftKey,
1694
- !!((source.GetKeyState(winrt::Windows::System::VirtualKey::CapitalLock) &
1692
+ !!((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::CapitalLock) &
1695
1693
  winrt::Microsoft::UI::Input::VirtualKeyStates::Locked) ==
1696
1694
  winrt::Microsoft::UI::Input::VirtualKeyStates::Locked));
1697
1695
  event.code = eventCode;
@@ -1707,26 +1705,25 @@ void ViewComponentView::OnKeyDown(
1707
1705
  }
1708
1706
  }
1709
1707
 
1710
- base_type::OnKeyDown(source, args);
1708
+ base_type::OnKeyDown(args);
1711
1709
  }
1712
1710
 
1713
1711
  void ViewComponentView::OnKeyUp(
1714
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
1715
1712
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
1716
- auto eventCode = CodeFromVirtualKey(source, args.Key());
1713
+ auto eventCode = CodeFromVirtualKey(args.KeyboardSource(), args.Key());
1717
1714
  bool fShift =
1718
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
1715
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
1719
1716
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
1720
1717
  bool fAlt =
1721
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Menu) &
1718
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Menu) &
1722
1719
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
1723
1720
  bool fCtrl =
1724
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
1721
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
1725
1722
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
1726
1723
  bool fMeta =
1727
- ((source.GetKeyState(winrt::Windows::System::VirtualKey::LeftWindows) &
1724
+ ((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::LeftWindows) &
1728
1725
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ||
1729
- ((source.GetKeyState(winrt::Windows::System::VirtualKey::RightWindows) &
1726
+ ((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::RightWindows) &
1730
1727
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down);
1731
1728
 
1732
1729
  if (args.OriginalSource() == Tag()) {
@@ -1739,7 +1736,7 @@ void ViewComponentView::OnKeyUp(
1739
1736
  event.key = ::Microsoft::ReactNative::FromVirtualKey(
1740
1737
  args.Key(),
1741
1738
  event.shiftKey,
1742
- !!((source.GetKeyState(winrt::Windows::System::VirtualKey::CapitalLock) &
1739
+ !!((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::CapitalLock) &
1743
1740
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ==
1744
1741
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down));
1745
1742
  event.code = eventCode;
@@ -1755,7 +1752,7 @@ void ViewComponentView::OnKeyUp(
1755
1752
  }
1756
1753
  }
1757
1754
 
1758
- base_type::OnKeyUp(source, args);
1755
+ base_type::OnKeyUp(args);
1759
1756
  }
1760
1757
 
1761
1758
  void ViewComponentView::updateLayoutMetrics(
@@ -1767,10 +1764,9 @@ void ViewComponentView::updateLayoutMetrics(
1767
1764
  }
1768
1765
  ensureVisual();
1769
1766
  base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
1770
- }
1771
-
1772
- void ViewComponentView::UpdateLayoutMetrics(const LayoutMetrics &metrics, const LayoutMetrics &oldMetrics) noexcept {
1773
- Visual().Size({metrics.Frame.Width * metrics.PointScaleFactor, metrics.Frame.Height * metrics.PointScaleFactor});
1767
+ Visual().Size(
1768
+ {layoutMetrics.frame.size.width * layoutMetrics.pointScaleFactor,
1769
+ layoutMetrics.frame.size.height * layoutMetrics.pointScaleFactor});
1774
1770
  }
1775
1771
 
1776
1772
  void ViewComponentView::prepareForRecycle() noexcept {}
@@ -11,7 +11,6 @@
11
11
  #include "CompositionHelpers.h"
12
12
 
13
13
  #include "Composition.ComponentView.g.h"
14
- #include "Composition.CreateCompositionComponentViewArgs.g.h"
15
14
  #include "Composition.ViewComponentView.g.h"
16
15
 
17
16
  namespace Microsoft::ReactNative {
@@ -20,39 +19,17 @@ struct CompContext;
20
19
 
21
20
  namespace winrt::Microsoft::ReactNative::Composition::implementation {
22
21
 
23
- struct CreateCompositionComponentViewArgs
24
- : public CreateCompositionComponentViewArgsT<
25
- CreateCompositionComponentViewArgs,
26
- winrt::Microsoft::ReactNative::implementation::CreateComponentViewArgs,
27
- winrt::Microsoft::ReactNative::Composition::Experimental::IInternalCreateComponentViewArgs> {
28
- CreateCompositionComponentViewArgs(
29
- const winrt::Microsoft::ReactNative::IReactContext &reactContext,
30
- facebook::react::Tag tag,
31
- const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compositionContext);
32
-
33
- winrt::Microsoft::UI::Composition::Compositor Compositor() const noexcept;
34
-
35
- winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext CompositionContext() const noexcept;
36
-
37
- ComponentViewFeatures Features() const noexcept;
38
- void Features(ComponentViewFeatures value) noexcept;
39
-
40
- private:
41
- ComponentViewFeatures m_features{ComponentViewFeatures::Default};
42
- winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext m_compositionContext;
43
- };
44
-
45
- struct ComponentView
46
- : public ComponentViewT<ComponentView, winrt::Microsoft::ReactNative::implementation::ComponentView> {
22
+ struct ComponentView : public ComponentViewT<
23
+ ComponentView,
24
+ winrt::Microsoft::ReactNative::implementation::ComponentView,
25
+ winrt::Microsoft::ReactNative::Composition::Experimental::IInternalComponentView> {
47
26
  static constexpr size_t SpecialBorderLayerCount = 8;
48
27
 
49
- ComponentView(winrt::Microsoft::ReactNative::Composition::CreateCompositionComponentViewArgs const &args);
50
28
  ComponentView(
51
29
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
52
30
  facebook::react::Tag tag,
53
31
  winrt::Microsoft::ReactNative::ReactContext const &reactContext,
54
- ComponentViewFeatures flags,
55
- bool customControl);
32
+ ComponentViewFeatures flags);
56
33
 
57
34
  virtual winrt::Microsoft::ReactNative::Composition::Experimental::IVisual Visual() const noexcept {
58
35
  return nullptr;
@@ -118,6 +95,8 @@ struct ComponentView
118
95
  std::optional<std::string> getAcccessiblityValue() noexcept override;
119
96
  void setAcccessiblityValue(std::string &&value) noexcept override;
120
97
  bool getAcccessiblityIsReadOnly() noexcept override;
98
+ ToggleState getToggleState() noexcept override;
99
+ void Toggle() noexcept override;
121
100
  virtual winrt::Microsoft::ReactNative::implementation::ClipState getClipState() noexcept;
122
101
 
123
102
  const facebook::react::LayoutMetrics &layoutMetrics() const noexcept;
@@ -129,9 +108,10 @@ struct ComponentView
129
108
  winrt::Microsoft::UI::Composition::Compositor Compositor() const noexcept;
130
109
  winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext CompositionContext() const noexcept;
131
110
 
132
- // Publicaly overridable APIs
133
111
  void FinalizeUpdates(winrt::Microsoft::ReactNative::ComponentViewUpdateMask updateMask) noexcept override;
134
- virtual void OnThemeChanged() noexcept;
112
+ winrt::event_token ThemeChanged(
113
+ winrt::Windows::Foundation::EventHandler<winrt::IInspectable> const &handler) noexcept;
114
+ void ThemeChanged(winrt::event_token const &token) noexcept;
135
115
 
136
116
  protected:
137
117
  bool anyHitTestHelper(
@@ -143,7 +123,6 @@ struct ComponentView
143
123
  winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext m_compContext;
144
124
  comp::CompositionPropertySet m_centerPropSet{nullptr};
145
125
  facebook::react::SharedViewEventEmitter m_eventEmitter;
146
- facebook::react::LayoutMetrics m_layoutMetrics;
147
126
  bool m_needsBorderUpdate{false};
148
127
  bool m_hasTransformMatrixFacade{false};
149
128
  bool m_enableFocusVisual{false};
@@ -177,10 +156,13 @@ struct ComponentView
177
156
  void showFocusVisual(bool show) noexcept;
178
157
  winrt::Microsoft::ReactNative::Composition::Experimental::IFocusVisual m_focusVisual{nullptr};
179
158
  winrt::Microsoft::ReactNative::Composition::Experimental::IVisual m_outerVisual{nullptr};
159
+ winrt::event<winrt::Windows::Foundation::EventHandler<winrt::IInspectable>> m_themeChangedEvent;
180
160
  };
181
161
 
182
- struct ViewComponentView : public ViewComponentViewT<ViewComponentView, ComponentView> {
183
- ViewComponentView(winrt::Microsoft::ReactNative::Composition::CreateCompositionComponentViewArgs const &args);
162
+ struct ViewComponentView : public ViewComponentViewT<
163
+ ViewComponentView,
164
+ ComponentView,
165
+ winrt::Microsoft::ReactNative::Composition::Experimental::IInternalCreateVisual> {
184
166
  [[nodiscard]] static winrt::Microsoft::ReactNative::ComponentView Create(
185
167
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
186
168
  facebook::react::Tag tag,
@@ -200,12 +182,8 @@ struct ViewComponentView : public ViewComponentViewT<ViewComponentView, Componen
200
182
  void prepareForRecycle() noexcept override;
201
183
  bool TryFocus() noexcept;
202
184
  bool focusable() const noexcept override;
203
- void OnKeyDown(
204
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
205
- const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
206
- void OnKeyUp(
207
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
208
- const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
185
+ void OnKeyDown(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
186
+ void OnKeyUp(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
209
187
  std::string DefaultControlType() const noexcept override;
210
188
 
211
189
  const facebook::react::SharedViewProps &viewProps() const noexcept override;
@@ -227,29 +205,27 @@ struct ViewComponentView : public ViewComponentViewT<ViewComponentView, Componen
227
205
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
228
206
  facebook::react::Tag tag,
229
207
  winrt::Microsoft::ReactNative::ReactContext const &reactContext,
230
- ComponentViewFeatures flags,
231
- bool customComponent);
208
+ ComponentViewFeatures flags);
232
209
 
233
210
  virtual winrt::Microsoft::ReactNative::Composition::Experimental::IVisual createVisual() noexcept;
234
211
 
235
- // Publicly overridable APIs
236
- virtual winrt::Microsoft::UI::Composition::Visual CreateVisual() noexcept;
237
- virtual void UpdateLayoutMetrics(const LayoutMetrics &metrics, const LayoutMetrics &oldMetrics) noexcept;
212
+ void CreateVisualHandler(const winrt::Microsoft::ReactNative::Composition::CreateVisualDelegate &handler);
213
+ winrt::Microsoft::ReactNative::Composition::CreateVisualDelegate CreateVisualHandler() const noexcept;
214
+ void CreateInternalVisualHandler(
215
+ const winrt::Microsoft::ReactNative::Composition::Experimental::CreateInternalVisualDelegate &handler);
216
+ winrt::Microsoft::ReactNative::Composition::Experimental::CreateInternalVisualDelegate CreateInternalVisualHandler()
217
+ const noexcept;
238
218
 
239
219
  protected:
240
220
  virtual winrt::Microsoft::ReactNative::ViewProps ViewPropsInner() noexcept;
241
221
 
242
222
  private:
223
+ bool m_hasNonVisualChildren{false};
243
224
  facebook::react::SharedViewProps m_props;
244
225
  winrt::Microsoft::ReactNative::Composition::Experimental::IVisual m_visual{nullptr};
226
+ winrt::Microsoft::ReactNative::Composition::CreateVisualDelegate m_createVisualHandler{nullptr};
227
+ winrt::Microsoft::ReactNative::Composition::Experimental::CreateInternalVisualDelegate m_createInternalVisualHandler{
228
+ nullptr};
245
229
  };
246
230
 
247
231
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
248
-
249
- namespace winrt::Microsoft::ReactNative::Composition::factory_implementation {
250
-
251
- struct ComponentView : ComponentViewT<ComponentView, implementation::ComponentView> {};
252
-
253
- struct ViewComponentView : ViewComponentViewT<ViewComponentView, implementation::ViewComponentView> {};
254
-
255
- } // namespace winrt::Microsoft::ReactNative::Composition::factory_implementation
@@ -0,0 +1,133 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include "ContentIslandComponentView.h"
8
+
9
+ #include <Fabric/FabricUIManagerModule.h>
10
+ #include <IReactContext.h>
11
+ #include <UI.Xaml.Controls.h>
12
+ #include <Utils/ValueUtils.h>
13
+ #include <winrt/Microsoft.UI.Content.h>
14
+ #include <winrt/Windows.UI.Composition.h>
15
+ #include "CompositionContextHelper.h"
16
+ #include "RootComponentView.h"
17
+
18
+ #include "Composition.ContentIslandComponentView.g.cpp"
19
+
20
+ namespace winrt::Microsoft::ReactNative::Composition::implementation {
21
+
22
+ ContentIslandComponentView::ContentIslandComponentView(
23
+ const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
24
+ facebook::react::Tag tag,
25
+ winrt::Microsoft::ReactNative::ReactContext const &reactContext)
26
+ : base_type(ViewComponentView::defaultProps(), compContext, tag, reactContext, ComponentViewFeatures::Default) {
27
+ m_mountedToken = Mounted([](const winrt::IInspectable &, const winrt::Microsoft::ReactNative::ComponentView &view) {
28
+ view.as<ContentIslandComponentView>()->OnMounted();
29
+ });
30
+ m_unmountedToken =
31
+ Unmounted([](const winrt::IInspectable &, const winrt::Microsoft::ReactNative::ComponentView &view) {
32
+ view.as<ContentIslandComponentView>()->OnUnmounted();
33
+ });
34
+ }
35
+
36
+ void ContentIslandComponentView::OnMounted() noexcept {
37
+ #ifdef USE_EXPERIMENTAL_WINUI3
38
+ m_childContentLink = winrt::Microsoft::UI::Content::ChildContentLink::Create(
39
+ rootComponentView()->parentContentIsland(),
40
+ winrt::Microsoft::ReactNative::Composition::Experimental::CompositionContextHelper::InnerVisual(Visual())
41
+ .as<winrt::Microsoft::UI::Composition::ContainerVisual>());
42
+ m_childContentLink.ActualSize({m_layoutMetrics.frame.size.width, m_layoutMetrics.frame.size.height});
43
+ if (m_islandToConnect) {
44
+ m_childContentLink.Connect(m_islandToConnect);
45
+ m_islandToConnect = nullptr;
46
+ }
47
+
48
+ ParentLayoutChanged();
49
+ auto view = Parent();
50
+ while (view) {
51
+ m_layoutMetricChangedRevokers.push_back(view.LayoutMetricsChanged(
52
+ winrt::auto_revoke,
53
+ [wkThis = get_weak()](
54
+ const winrt::IInspectable &sender, const winrt::Microsoft::ReactNative::LayoutMetricsChangedArgs &args) {
55
+ if (auto strongThis = wkThis.get()) {
56
+ strongThis->ParentLayoutChanged();
57
+ }
58
+ }));
59
+ view = view.Parent();
60
+ }
61
+ #endif
62
+ }
63
+
64
+ void ContentIslandComponentView::OnUnmounted() noexcept {
65
+ m_layoutMetricChangedRevokers.clear();
66
+ }
67
+
68
+ void ContentIslandComponentView::ParentLayoutChanged() noexcept {
69
+ #ifdef USE_EXPERIMENTAL_WINUI3
70
+ if (m_layoutChangePosted)
71
+ return;
72
+
73
+ m_layoutChangePosted = true;
74
+ ReactContext().UIDispatcher().Post([wkThis = get_weak()]() {
75
+ if (auto strongThis = wkThis.get()) {
76
+ auto clientRect = strongThis->getClientRect();
77
+
78
+ strongThis->m_childContentLink.OffsetOverride(
79
+ {static_cast<float>(clientRect.left), static_cast<float>(clientRect.top)});
80
+ strongThis->m_layoutChangePosted = false;
81
+ }
82
+ });
83
+ #endif
84
+ }
85
+
86
+ ContentIslandComponentView::~ContentIslandComponentView() noexcept {
87
+ if (m_islandToConnect) {
88
+ m_islandToConnect.Close();
89
+ }
90
+ }
91
+
92
+ void ContentIslandComponentView::MountChildComponentView(
93
+ const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
94
+ uint32_t index) noexcept {
95
+ assert(false);
96
+ base_type::MountChildComponentView(childComponentView, index);
97
+ }
98
+
99
+ void ContentIslandComponentView::UnmountChildComponentView(
100
+ const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
101
+ uint32_t index) noexcept {
102
+ assert(false);
103
+ base_type::UnmountChildComponentView(childComponentView, index);
104
+ }
105
+
106
+ void ContentIslandComponentView::updateLayoutMetrics(
107
+ facebook::react::LayoutMetrics const &layoutMetrics,
108
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
109
+ #ifdef USE_EXPERIMENTAL_WINUI3
110
+ if (m_childContentLink) {
111
+ m_childContentLink.ActualSize({layoutMetrics.frame.size.width, layoutMetrics.frame.size.height});
112
+ ParentLayoutChanged();
113
+ }
114
+ #endif
115
+ base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
116
+ }
117
+
118
+ void ContentIslandComponentView::Connect(const winrt::Microsoft::UI::Content::ContentIsland &contentIsland) noexcept {
119
+ #ifdef USE_EXPERIMENTAL_WINUI3
120
+ if (m_childContentLink) {
121
+ m_islandToConnect = nullptr;
122
+ m_childContentLink.Connect(contentIsland);
123
+ } else {
124
+ m_islandToConnect = contentIsland;
125
+ }
126
+ #endif
127
+ }
128
+
129
+ void ContentIslandComponentView::prepareForRecycle() noexcept {
130
+ Super::prepareForRecycle();
131
+ }
132
+
133
+ } // namespace winrt::Microsoft::ReactNative::Composition::implementation