react-native-windows 0.77.7 → 0.77.9

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 (55) hide show
  1. package/Libraries/Modal/Modal.windows.js +4 -1
  2. package/Microsoft.ReactNative/CompositionComponentView.idl +13 -1
  3. package/Microsoft.ReactNative/Fabric/AbiPortalShadowNode.cpp +97 -0
  4. package/Microsoft.ReactNative/Fabric/AbiPortalShadowNode.h +53 -0
  5. package/Microsoft.ReactNative/Fabric/AbiViewComponentDescriptor.h +160 -17
  6. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +0 -1
  7. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +0 -5
  8. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +0 -2
  9. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +13 -32
  10. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +1 -3
  11. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +1 -1
  12. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.h +2 -1
  13. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +25 -20
  14. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +313 -319
  15. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.h +3 -61
  16. package/Microsoft.ReactNative/Fabric/Composition/PortalComponentView.cpp +78 -0
  17. package/Microsoft.ReactNative/Fabric/Composition/PortalComponentView.h +52 -0
  18. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +22 -0
  19. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +7 -5
  20. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +79 -19
  21. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +12 -6
  22. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +73 -19
  23. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +16 -0
  24. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +2 -2
  25. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +38 -23
  26. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +1 -6
  27. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +0 -3
  28. package/Microsoft.ReactNative/Fabric/WindowsComponentDescriptorRegistry.cpp +0 -2
  29. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +15 -1
  30. package/Microsoft.ReactNative/ReactNativeHost.cpp +5 -0
  31. package/Microsoft.ReactNative/ReactNativeIsland.idl +5 -1
  32. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  33. package/Shared/Networking/WinRTWebSocketResource.cpp +82 -96
  34. package/Shared/Networking/WinRTWebSocketResource.h +91 -7
  35. package/Shared/Shared.vcxitems +6 -5
  36. package/Shared/Shared.vcxitems.filters +3 -4
  37. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +212 -0
  38. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +295 -0
  39. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +200 -0
  40. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +224 -0
  41. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +250 -0
  42. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +267 -0
  43. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +234 -0
  44. package/codegen/react/components/rnwcore/InputAccessory.g.h +200 -0
  45. package/codegen/react/components/rnwcore/ModalHostView.g.h +283 -0
  46. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +246 -0
  47. package/codegen/react/components/rnwcore/SafeAreaView.g.h +197 -0
  48. package/codegen/react/components/rnwcore/Switch.g.h +263 -0
  49. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +200 -0
  50. package/just-task.js +1 -1
  51. package/package.json +3 -3
  52. package/Microsoft.ReactNative/Fabric/AbiViewComponentDescriptor.cpp +0 -191
  53. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentDescriptor.h +0 -39
  54. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewShadowNode.cpp +0 -18
  55. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewShadowNode.h +0 -39
@@ -3,69 +3,11 @@
3
3
 
4
4
  #pragma once
5
5
 
6
- #include <Fabric/ComponentView.h>
7
- #include <Microsoft.ReactNative.Cxx/ReactContext.h>
8
-
9
- #include "Composition.WindowsModalHostComponentView.g.h"
10
- #include "../CompositionViewComponentView.h"
11
-
12
- #include <Fabric/Composition/RootComponentView.h>
13
- #include <react/components/rnwcore/ShadowNodes.h>
6
+ #include <winrt/Microsoft.ReactNative.h>
14
7
 
15
8
  namespace winrt::Microsoft::ReactNative::Composition::implementation {
16
9
 
17
- struct WindowsModalHostComponentView
18
- : WindowsModalHostComponentViewT<WindowsModalHostComponentView, RootComponentView> {
19
- using Super = WindowsModalHostComponentViewT<WindowsModalHostComponentView, RootComponentView>;
20
-
21
- ~WindowsModalHostComponentView();
22
-
23
- [[nodiscard]] static winrt::Microsoft::ReactNative::ComponentView Create(
24
- const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
25
- facebook::react::Tag tag,
26
- winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept;
27
-
28
- winrt::Microsoft::ReactNative::Composition::Experimental::IVisual VisualToMountChildrenInto() noexcept override;
29
- void MountChildComponentView(
30
- const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
31
- uint32_t index) noexcept override;
32
- void UnmountChildComponentView(
33
- const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
34
- uint32_t index) noexcept override;
35
-
36
- void AdjustWindowSize() noexcept;
37
-
38
- void updateLayoutMetrics(
39
- facebook::react::LayoutMetrics const &layoutMetrics,
40
- facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
41
-
42
- void updateProps(facebook::react::Props::Shared const &props, facebook::react::Props::Shared const &oldProps) noexcept
43
- override;
44
- static facebook::react::SharedViewProps defaultProps() noexcept;
45
- const facebook::react::ModalHostViewProps &modalHostViewProps() const noexcept;
46
- bool focusable() const noexcept override;
47
- facebook::react::Tag hitTest(facebook::react::Point pt, facebook::react::Point &localPt, bool ignorePointerEvents)
48
- const noexcept override;
49
- virtual std::string DefaultControlType() const noexcept;
50
-
51
- WindowsModalHostComponentView(
52
- const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
53
- facebook::react::Tag tag,
54
- winrt::Microsoft::ReactNative::ReactContext const &reactContext);
55
-
56
- // Used for creating new window
57
- void ShowOnUIThread();
58
- void HideOnUIThread() noexcept;
59
- void EnsureModalCreated();
60
- static void RegisterWndClass() noexcept;
61
-
62
- private:
63
- HWND m_parentHwnd{nullptr};
64
- HWND m_hwnd{nullptr};
65
- uint64_t m_prevWindowID;
66
- bool m_isVisible{false};
67
- bool m_showTitleBar{false};
68
- winrt::Microsoft::ReactNative::ReactNativeIsland m_reactNativeIsland;
69
- };
10
+ void RegisterWindowsModalHostNativeComponent(
11
+ winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder) noexcept;
70
12
 
71
13
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -0,0 +1,78 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include "PortalComponentView.h"
8
+
9
+ #include "Composition.PortalComponentView.g.cpp"
10
+
11
+ namespace winrt::Microsoft::ReactNative::Composition::implementation {
12
+
13
+ PortalComponentView::PortalComponentView(
14
+ const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
15
+ facebook::react::Tag tag,
16
+ winrt::Microsoft::ReactNative::ReactContext const &reactContext,
17
+ winrt::Microsoft::ReactNative::Composition::ReactCompositionViewComponentBuilder *builder)
18
+ : base_type(tag, reactContext, builder) {
19
+ m_rootComponentView = winrt::make_self<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>(
20
+ compContext, *this, reactContext);
21
+ }
22
+
23
+ PortalComponentView::~PortalComponentView() {}
24
+
25
+ winrt::Microsoft::ReactNative::Composition::RootComponentView PortalComponentView::ContentRoot() const noexcept {
26
+ return *m_rootComponentView;
27
+ }
28
+
29
+ void PortalComponentView::MountChildComponentView(
30
+ const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
31
+ uint32_t index) noexcept {
32
+ m_rootComponentView->MountChildComponentView(childComponentView, index);
33
+ if (m_builder && m_builder->MountChildComponentViewHandler()) {
34
+ m_builder->MountChildComponentViewHandler()(
35
+ *this,
36
+ winrt::make<winrt::Microsoft::ReactNative::implementation::MountChildComponentViewArgs>(
37
+ childComponentView, index));
38
+ }
39
+ }
40
+
41
+ void PortalComponentView::UnmountChildComponentView(
42
+ const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
43
+ uint32_t index) noexcept {
44
+ if (m_builder && m_builder->UnmountChildComponentViewHandler()) {
45
+ m_builder->UnmountChildComponentViewHandler()(
46
+ *this,
47
+ winrt::make<winrt::Microsoft::ReactNative::implementation::UnmountChildComponentViewArgs>(
48
+ childComponentView, index));
49
+ }
50
+ m_rootComponentView->UnmountChildComponentView(childComponentView, index);
51
+ }
52
+
53
+ const winrt::Microsoft::ReactNative::IComponentProps PortalComponentView::userProps(
54
+ facebook::react::Props::Shared const &props) noexcept {
55
+ const auto &abiViewProps = *std::static_pointer_cast<const ::Microsoft::ReactNative::AbiViewProps>(props);
56
+ return abiViewProps.UserProps();
57
+ }
58
+
59
+ void PortalComponentView::updateProps(
60
+ facebook::react::Props::Shared const &props,
61
+ facebook::react::Props::Shared const &oldProps) noexcept {
62
+ m_rootComponentView->updateProps(props, oldProps);
63
+ base_type::updateProps(props, oldProps);
64
+ }
65
+
66
+ void PortalComponentView::updateLayoutMetrics(
67
+ facebook::react::LayoutMetrics const &layoutMetrics,
68
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
69
+ m_rootComponentView->updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
70
+ base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
71
+ }
72
+
73
+ void PortalComponentView::FinalizeUpdates(winrt::Microsoft::ReactNative::ComponentViewUpdateMask updateMask) noexcept {
74
+ m_rootComponentView->FinalizeUpdates(updateMask);
75
+ base_type::FinalizeUpdates(updateMask);
76
+ }
77
+
78
+ } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -0,0 +1,52 @@
1
+
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ #pragma once
6
+
7
+ #include <Fabric/ComponentView.h>
8
+ #include <Microsoft.ReactNative.Cxx/ReactContext.h>
9
+ #include "RootComponentView.h"
10
+
11
+ #include "Composition.PortalComponentView.g.h"
12
+
13
+ namespace Microsoft::ReactNative {
14
+ struct CompContext;
15
+ } // namespace Microsoft::ReactNative
16
+
17
+ namespace winrt::Microsoft::ReactNative::Composition::implementation {
18
+
19
+ struct PortalComponentView
20
+ : public PortalComponentViewT<PortalComponentView, winrt::Microsoft::ReactNative::implementation::ComponentView> {
21
+ PortalComponentView(
22
+ const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
23
+ facebook::react::Tag tag,
24
+ winrt::Microsoft::ReactNative::ReactContext const &reactContext,
25
+ winrt::Microsoft::ReactNative::Composition::ReactCompositionViewComponentBuilder *builder);
26
+ virtual ~PortalComponentView();
27
+
28
+ winrt::Microsoft::ReactNative::Composition::RootComponentView ContentRoot() const noexcept;
29
+
30
+ void MountChildComponentView(
31
+ const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
32
+ uint32_t index) noexcept override;
33
+ void UnmountChildComponentView(
34
+ const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
35
+ uint32_t index) noexcept override;
36
+
37
+ const winrt::Microsoft::ReactNative::IComponentProps userProps(
38
+ facebook::react::Props::Shared const &props) noexcept override;
39
+ void updateProps(facebook::react::Props::Shared const &props, facebook::react::Props::Shared const &oldProps) noexcept
40
+ override;
41
+
42
+ void updateLayoutMetrics(
43
+ facebook::react::LayoutMetrics const &layoutMetrics,
44
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
45
+
46
+ void FinalizeUpdates(winrt::Microsoft::ReactNative::ComponentViewUpdateMask updateMask) noexcept override;
47
+
48
+ private:
49
+ winrt::com_ptr<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView> m_rootComponentView;
50
+ };
51
+
52
+ } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -3,8 +3,10 @@
3
3
 
4
4
  #include "pch.h"
5
5
  #include "ReactCompositionViewComponentBuilder.h"
6
+ #include <Fabric/AbiViewComponentDescriptor.h>
6
7
  #include <Fabric/Composition/CompositionViewComponentView.h>
7
8
  #include <Fabric/Composition/ContentIslandComponentView.h>
9
+ #include <Fabric/Composition/PortalComponentView.h>
8
10
  #include <strsafe.h>
9
11
  #include "CompositionContextHelper.h"
10
12
  #include "DynamicWriter.h"
@@ -111,6 +113,26 @@ void ReactCompositionViewComponentBuilder::SetContentIslandComponentViewInitiali
111
113
  };
112
114
  }
113
115
 
116
+ void ReactCompositionViewComponentBuilder::SetPortalComponentViewInitializer(
117
+ const PortalComponentViewInitializer &initializer) noexcept {
118
+ m_fnCreateView = [initializer](
119
+ const IReactContext &reactContext,
120
+ int32_t tag,
121
+ const Experimental::ICompositionContext &context,
122
+ ComponentViewFeatures /*features*/,
123
+ ReactCompositionViewComponentBuilder &builder)
124
+ -> winrt::Microsoft::ReactNative::Composition::PortalComponentView {
125
+ auto view = winrt::make<winrt::Microsoft::ReactNative::Composition::implementation::PortalComponentView>(
126
+ context, tag, reactContext, &builder);
127
+ initializer(view);
128
+ return view;
129
+ };
130
+ m_descriptorConstructorFactory = []() {
131
+ return &facebook::react::concreteComponentDescriptorConstructor<
132
+ ::Microsoft::ReactNative::AbiPortalComponentDescriptor>;
133
+ };
134
+ }
135
+
114
136
  // (Object handle, Microsoft.ReactNative.IComponentState state) => void
115
137
  // void ReactCompositionViewComponentBuilder::SetStateUpdater(StateUpdater impl) noexcept {
116
138
  // m_stateUpdater = impl;
@@ -3,7 +3,6 @@
3
3
  // Licensed under the MIT License.
4
4
 
5
5
  #include <Fabric/AbiComponentDescriptor.h>
6
- #include <Fabric/AbiViewComponentDescriptor.h>
7
6
  #include <react/renderer/componentregistry/ComponentDescriptorProvider.h>
8
7
  #include <react/renderer/core/ReactPrimitives.h>
9
8
  #include "winrt/Microsoft.ReactNative.Composition.Experimental.h"
@@ -12,10 +11,12 @@
12
11
 
13
12
  namespace winrt::Microsoft::ReactNative::Composition {
14
13
 
15
- struct ReactCompositionViewComponentBuilder : winrt::implements<
16
- ReactCompositionViewComponentBuilder,
17
- IReactViewComponentBuilder,
18
- Composition::IReactCompositionViewComponentBuilder> {
14
+ struct ReactCompositionViewComponentBuilder
15
+ : winrt::implements<
16
+ ReactCompositionViewComponentBuilder,
17
+ IReactViewComponentBuilder,
18
+ Composition::IReactCompositionViewComponentBuilder,
19
+ Composition::Experimental::IReactCompositionViewComponentInternalBuilder> {
19
20
  ReactCompositionViewComponentBuilder() noexcept;
20
21
 
21
22
  public: // IReactViewComponentBuilder
@@ -42,6 +43,7 @@ struct ReactCompositionViewComponentBuilder : winrt::implements<
42
43
  public: // Composition::IReactCompositionViewComponentBuilder
43
44
  void SetViewComponentViewInitializer(const ViewComponentViewInitializer &initializer) noexcept;
44
45
  void SetContentIslandComponentViewInitializer(const ComponentIslandComponentViewInitializer &initializer) noexcept;
46
+ void SetPortalComponentViewInitializer(const PortalComponentViewInitializer &initializer) noexcept;
45
47
  void SetCreateVisualHandler(CreateVisualDelegate impl) noexcept;
46
48
  void SetViewFeatures(ComponentViewFeatures viewFeatures) noexcept;
47
49
  void SetVisualToMountChildrenIntoHandler(VisualToMountChildrenIntoDelegate impl) noexcept;
@@ -127,21 +127,39 @@ ReactNativeIsland::ReactNativeIsland(const winrt::Microsoft::UI::Composition::Co
127
127
  InitTextScaleMultiplier();
128
128
  }
129
129
 
130
- // Constructor to initialize ReactNativeIsland with context and componentView
131
130
  ReactNativeIsland::ReactNativeIsland(
132
- const winrt::Microsoft::UI::Composition::Compositor &compositor,
133
- winrt::Microsoft::ReactNative::IReactContext context,
134
- winrt::Microsoft::ReactNative::ComponentView componentView) noexcept
135
- : m_compositor(compositor),
136
- m_context(context),
131
+ const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portal) noexcept
132
+ : m_compositor(portal.ContentRoot().Compositor()),
133
+ m_context(portal.ReactContext()),
137
134
  m_layoutConstraints({{0, 0}, {0, 0}, winrt::Microsoft::ReactNative::LayoutDirection::Undefined}),
138
135
  m_isFragment(true) {
139
- m_rootTag = componentView.Tag();
136
+ m_portal = winrt::make_weak(portal);
137
+
138
+ auto trueRoot =
139
+ winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::PortalComponentView>(portal)
140
+ ->rootComponentView();
141
+ while (auto p = trueRoot->Portal()) {
142
+ trueRoot = winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::PortalComponentView>(p)
143
+ ->rootComponentView();
144
+ };
145
+ m_rootTag = trueRoot->Tag();
146
+
140
147
  InitTextScaleMultiplier();
141
- AddFragmentCompositionEventHandler(context, componentView);
148
+ AddFragmentCompositionEventHandler(m_context.Handle(), portal.ContentRoot());
149
+ auto selfPortal = winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>(
150
+ portal.ContentRoot());
151
+ selfPortal->ReactNativeIsland(*this);
152
+ NotifySizeChanged();
153
+ selfPortal->start(*this);
154
+ }
155
+
156
+ winrt::Microsoft::ReactNative::ReactNativeIsland ReactNativeIsland::CreatePortal(
157
+ const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portal) noexcept {
158
+ return winrt::make<ReactNativeIsland>(portal);
142
159
  }
143
160
 
144
- ReactNativeIsland::ReactNativeIsland() noexcept : ReactNativeIsland(nullptr) {}
161
+ ReactNativeIsland::ReactNativeIsland() noexcept
162
+ : ReactNativeIsland(winrt::Microsoft::UI::Composition::Compositor{nullptr}) {}
145
163
 
146
164
  ReactNativeIsland::~ReactNativeIsland() noexcept {
147
165
  #ifdef USE_WINUI3
@@ -159,14 +177,20 @@ ReactNativeIsland::~ReactNativeIsland() noexcept {
159
177
  assert(m_uiDispatcher.HasThreadAccess());
160
178
  UninitRootView();
161
179
  }
180
+
181
+ if (m_island) {
182
+ m_island.Close();
183
+ }
162
184
  }
163
185
 
164
186
  ReactNative::IReactViewHost ReactNativeIsland::ReactViewHost() noexcept {
165
187
  return m_reactViewHost;
166
188
  }
167
189
 
168
- void ReactNativeIsland::ReactViewHost(winrt::Microsoft::ReactNative::IReactViewHost const &value) noexcept {
169
- assert(!m_isFragment); // make sure this isn't a FragmentIsalnd
190
+ void ReactNativeIsland::ReactViewHost(winrt::Microsoft::ReactNative::IReactViewHost const &value) {
191
+ if (m_isFragment)
192
+ winrt::throw_hresult(E_ACCESSDENIED);
193
+
170
194
  if (m_reactViewHost == value) {
171
195
  return;
172
196
  }
@@ -217,6 +241,8 @@ void ReactNativeIsland::AddRenderedVisual(
217
241
 
218
242
  void ReactNativeIsland::RemoveRenderedVisual(
219
243
  const winrt::Microsoft::ReactNative::Composition::Experimental::IVisual &visual) noexcept {
244
+ if (m_isFragment)
245
+ return;
220
246
  assert(m_hasRenderedVisual);
221
247
  InternalRootVisual().Remove(visual);
222
248
  m_hasRenderedVisual = false;
@@ -442,7 +468,7 @@ void ReactNativeIsland::InitRootView(
442
468
 
443
469
  m_context = winrt::Microsoft::ReactNative::ReactContext(std::move(context));
444
470
  m_reactViewOptions = std::move(viewOptions);
445
- m_CompositionEventHandler = std::make_shared<::Microsoft::ReactNative::CompositionEventHandler>(m_context, *this, -1);
471
+ m_CompositionEventHandler = std::make_shared<::Microsoft::ReactNative::CompositionEventHandler>(m_context, *this);
446
472
  m_CompositionEventHandler->Initialize();
447
473
 
448
474
  UpdateRootViewInternal();
@@ -457,15 +483,13 @@ void ReactNativeIsland::AddFragmentCompositionEventHandler(
457
483
  .Get(winrt::Microsoft::ReactNative::ReactDispatcherHelper::UIDispatcherProperty())
458
484
  .try_as<IReactDispatcher>();
459
485
  VerifyElseCrash(m_uiDispatcher.HasThreadAccess());
460
- VerifyElseCrash(m_rootTag != -1);
461
486
  auto uiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties(
462
487
  winrt::Microsoft::ReactNative::ReactPropertyBag(context.Properties()));
463
488
 
464
489
  if (!m_CompositionEventHandler) {
465
490
  // Create CompositionEventHandler if not already created
466
491
  m_context = winrt::Microsoft::ReactNative::ReactContext(context);
467
- m_CompositionEventHandler =
468
- std::make_shared<::Microsoft::ReactNative::CompositionEventHandler>(m_context, *this, componentView.Tag());
492
+ m_CompositionEventHandler = std::make_shared<::Microsoft::ReactNative::CompositionEventHandler>(m_context, *this);
469
493
  m_CompositionEventHandler->Initialize();
470
494
  m_isInitialized = true;
471
495
  }
@@ -545,6 +569,7 @@ void ReactNativeIsland::ClearLoadingUI() noexcept {
545
569
  void ReactNativeIsland::EnsureLoadingUI() noexcept {}
546
570
 
547
571
  void ReactNativeIsland::ShowInstanceLoaded() noexcept {
572
+ VerifyElseCrash(!m_isFragment);
548
573
  if (m_rootVisual) {
549
574
  ClearLoadingUI();
550
575
 
@@ -740,6 +765,9 @@ void ReactNativeIsland::InitTextScaleMultiplier() noexcept {
740
765
  winrt::Windows::Foundation::Size ReactNativeIsland::Measure(
741
766
  const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraints,
742
767
  const winrt::Windows::Foundation::Point &viewportOffset) const {
768
+ if (m_isFragment)
769
+ winrt::throw_hresult(E_ILLEGAL_METHOD_CALL);
770
+
743
771
  facebook::react::Size size{0, 0};
744
772
 
745
773
  if (layoutConstraints.LayoutDirection != winrt::Microsoft::ReactNative::LayoutDirection::LeftToRight &&
@@ -781,7 +809,7 @@ void ReactNativeIsland::Arrange(
781
809
  facebook::react::LayoutConstraints fbLayoutConstraints;
782
810
  ApplyConstraints(layoutConstraints, fbLayoutConstraints);
783
811
 
784
- if (m_isInitialized && m_rootTag != -1) {
812
+ if (m_isInitialized && m_rootTag != -1 && !m_isFragment) {
785
813
  if (auto fabricuiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties(
786
814
  winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties()))) {
787
815
  facebook::react::LayoutContext context;
@@ -820,6 +848,23 @@ winrt::Microsoft::UI::Content::ContentIsland ReactNativeIsland::Island() {
820
848
  rootVisual));
821
849
  m_island = winrt::Microsoft::UI::Content::ContentIsland::Create(rootVisual);
822
850
 
851
+ auto focusController = winrt::Microsoft::UI::Input::InputFocusController::GetForIsland(m_island);
852
+ focusController.NavigateFocusRequested(
853
+ [weakThis = get_weak()](
854
+ const auto &sender, const winrt::Microsoft::UI::Input::FocusNavigationRequestEventArgs &args) {
855
+ if (auto pThis = weakThis.get()) {
856
+ if (auto rootView = pThis->GetComponentView()) {
857
+ args.Result(
858
+ rootView->NavigateFocus(winrt::Microsoft::ReactNative::FocusNavigationRequest(
859
+ winrt::Microsoft::ReactNative::FocusNavigationReason::First))
860
+ ? winrt::Microsoft::UI::Input::FocusNavigationResult::Moved
861
+ : winrt::Microsoft::UI::Input::FocusNavigationResult::NotMoved);
862
+ } else {
863
+ args.Result(winrt::Microsoft::UI::Input::FocusNavigationResult::NoFocusableElements);
864
+ }
865
+ }
866
+ });
867
+
823
868
  // ContentIsland does not support weak_ref, so we cannot use auto_revoke for these events
824
869
  m_islandAutomationProviderRequestedToken = m_island.AutomationProviderRequested(
825
870
  [weakThis = get_weak()](
@@ -903,13 +948,29 @@ void ReactNativeIsland::OnUnmounted() noexcept {
903
948
  if (!m_mounted)
904
949
  return;
905
950
  m_mounted = false;
951
+
952
+ if (m_island && m_island.IsConnected()) {
953
+ auto focusController = winrt::Microsoft::UI::Input::InputFocusController::GetForIsland(m_island);
954
+ auto request = winrt::Microsoft::UI::Input::FocusNavigationRequest::Create(
955
+ winrt::Microsoft::UI::Input::FocusNavigationReason::Programmatic);
956
+ if (focusController.HasFocus()) {
957
+ focusController.DepartFocus(request);
958
+ }
959
+ }
960
+
906
961
  if (auto componentView = GetComponentView()) {
907
962
  componentView->onUnmounted();
908
963
  }
909
964
  }
910
965
 
911
- winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView *
966
+ winrt::com_ptr<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>
912
967
  ReactNativeIsland::GetComponentView() noexcept {
968
+ if (auto portal = m_portal.get()) {
969
+ return winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::PortalComponentView>(portal)
970
+ ->ContentRoot()
971
+ .as<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>();
972
+ }
973
+
913
974
  if (!m_context || m_context.Handle().LoadingState() != winrt::Microsoft::ReactNative::LoadingState::Loaded ||
914
975
  m_rootTag == -1)
915
976
  return nullptr;
@@ -919,8 +980,7 @@ ReactNativeIsland::GetComponentView() noexcept {
919
980
  auto rootComponentViewDescriptor = fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(
920
981
  static_cast<facebook::react::SurfaceId>(m_rootTag));
921
982
  return rootComponentViewDescriptor.view
922
- .as<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>()
923
- .get();
983
+ .as<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>();
924
984
  }
925
985
  return nullptr;
926
986
  }
@@ -12,6 +12,7 @@
12
12
  #include <winrt/Microsoft.ReactNative.h>
13
13
  #include <winrt/Windows.UI.ViewManagement.h>
14
14
  #include "CompositionEventHandler.h"
15
+ #include "PortalComponentView.h"
15
16
  #include "ReactHost/React.h"
16
17
 
17
18
  namespace winrt::Microsoft::ReactNative::implementation {
@@ -48,15 +49,15 @@ struct ReactNativeIsland
48
49
  ~ReactNativeIsland() noexcept;
49
50
 
50
51
  ReactNativeIsland(const winrt::Microsoft::UI::Composition::Compositor &compositor) noexcept;
51
- ReactNativeIsland(
52
- const winrt::Microsoft::UI::Composition::Compositor &compositor,
53
- winrt::Microsoft::ReactNative::IReactContext context,
54
- winrt::Microsoft::ReactNative::ComponentView componentView) noexcept;
52
+ ReactNativeIsland(const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portal) noexcept;
53
+
54
+ static winrt::Microsoft::ReactNative::ReactNativeIsland CreatePortal(
55
+ const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portal) noexcept;
55
56
  winrt::Microsoft::UI::Content::ContentIsland Island();
56
57
 
57
58
  // property ReactViewHost
58
59
  ReactNative::IReactViewHost ReactViewHost() noexcept;
59
- void ReactViewHost(ReactNative::IReactViewHost const &value) noexcept;
60
+ void ReactViewHost(ReactNative::IReactViewHost const &value);
60
61
 
61
62
  winrt::Microsoft::UI::Composition::Visual RootVisual() noexcept;
62
63
 
@@ -104,7 +105,8 @@ struct ReactNativeIsland
104
105
  winrt::Microsoft::ReactNative::FocusNavigationResult NavigateFocus(
105
106
  const winrt::Microsoft::ReactNative::FocusNavigationRequest &request) noexcept;
106
107
 
107
- winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView *GetComponentView() noexcept;
108
+ winrt::com_ptr<winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView>
109
+ GetComponentView() noexcept;
108
110
 
109
111
  int64_t RootTag() const noexcept;
110
112
 
@@ -153,8 +155,12 @@ struct ReactNativeIsland
153
155
  bool m_hasRenderedVisual{false};
154
156
  bool m_showingLoadingUI{false};
155
157
  bool m_mounted{false};
158
+ winrt::weak_ref<winrt::Microsoft::ReactNative::Composition::PortalComponentView> m_portal{nullptr};
156
159
  IReactDispatcher m_uiDispatcher{nullptr};
157
160
  winrt::IInspectable m_uiaProvider{nullptr};
161
+
162
+ // This is the surfaceId that this island belongs to.
163
+ // In the case of portal content root, this will be the surfaceId that contains the portal.
158
164
  int64_t m_rootTag{-1};
159
165
  float m_scaleFactor{1.0};
160
166
  float m_textScaleMultiplier{1.0};