react-native-windows 0.77.0-preview.4 → 0.78.0-preview.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 (233) hide show
  1. package/.flowconfig +1 -1
  2. package/Chakra/ChakraTracing.cpp +1 -1
  3. package/Libraries/Animated/animations/Animation.js +22 -1
  4. package/Libraries/Animated/animations/DecayAnimation.js +1 -0
  5. package/Libraries/Animated/animations/SpringAnimation.js +1 -0
  6. package/Libraries/Animated/animations/TimingAnimation.js +1 -0
  7. package/Libraries/Animated/nodes/AnimatedAddition.js +9 -2
  8. package/Libraries/Animated/nodes/AnimatedColor.js +4 -1
  9. package/Libraries/Animated/nodes/AnimatedDiffClamp.js +10 -2
  10. package/Libraries/Animated/nodes/AnimatedDivision.js +9 -2
  11. package/Libraries/Animated/nodes/AnimatedInterpolation.js +5 -1
  12. package/Libraries/Animated/nodes/AnimatedModulo.js +5 -2
  13. package/Libraries/Animated/nodes/AnimatedMultiplication.js +9 -2
  14. package/Libraries/Animated/nodes/AnimatedNode.js +25 -46
  15. package/Libraries/Animated/nodes/AnimatedObject.js +9 -2
  16. package/Libraries/Animated/nodes/AnimatedProps.js +5 -1
  17. package/Libraries/Animated/nodes/AnimatedStyle.js +5 -1
  18. package/Libraries/Animated/nodes/AnimatedSubtraction.js +9 -2
  19. package/Libraries/Animated/nodes/AnimatedTracking.js +5 -1
  20. package/Libraries/Animated/nodes/AnimatedTransform.js +5 -1
  21. package/Libraries/Animated/nodes/AnimatedValue.js +49 -4
  22. package/Libraries/Animated/nodes/AnimatedValueXY.js +3 -1
  23. package/Libraries/Animated/useAnimatedProps.js +0 -43
  24. package/Libraries/Components/Button.windows.js +3 -0
  25. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.d.ts +1 -1
  26. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.js +3 -1
  27. package/Libraries/Components/LayoutConformance/LayoutConformance.d.ts +21 -0
  28. package/Libraries/Components/LayoutConformance/LayoutConformance.js +59 -0
  29. package/Libraries/Components/LayoutConformance/LayoutConformanceNativeComponent.js +29 -0
  30. package/Libraries/Components/Pressable/Pressable.windows.js +3 -0
  31. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +1 -0
  32. package/Libraries/Components/TextInput/TextInput.d.ts +5 -0
  33. package/Libraries/Components/TextInput/TextInput.flow.js +6 -0
  34. package/Libraries/Components/TextInput/TextInput.js +6 -0
  35. package/Libraries/Components/TextInput/TextInput.windows.js +9 -0
  36. package/Libraries/Components/Touchable/TouchableBounce.windows.js +2 -0
  37. package/Libraries/Components/Touchable/TouchableNativeFeedback.windows.js +2 -0
  38. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +2 -0
  39. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +2 -0
  40. package/Libraries/Components/View/View.windows.js +3 -0
  41. package/Libraries/Components/View/ViewAccessibility.d.ts +7 -2
  42. package/Libraries/Components/View/ViewAccessibility.windows.js +1 -0
  43. package/Libraries/Components/View/ViewPropTypes.d.ts +0 -7
  44. package/Libraries/Components/View/ViewPropTypes.js +0 -9
  45. package/Libraries/Components/View/ViewPropTypes.windows.js +1 -9
  46. package/Libraries/Core/ReactNativeVersion.js +2 -2
  47. package/Libraries/Core/setUpBatchedBridge.js +1 -16
  48. package/Libraries/EventEmitter/RCTEventEmitter.js +2 -6
  49. package/Libraries/Image/AssetSourceResolver.js +11 -0
  50. package/Libraries/Image/AssetSourceResolver.windows.js +11 -0
  51. package/Libraries/Image/Image.windows.js +2 -0
  52. package/Libraries/Inspector/BorderBox.js +26 -14
  53. package/Libraries/Inspector/BoxInspector.js +60 -42
  54. package/Libraries/Inspector/ElementBox.js +55 -48
  55. package/Libraries/Inspector/StyleInspector.js +36 -30
  56. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -2
  57. package/Libraries/Lists/FlatList.d.ts +1 -1
  58. package/Libraries/Modal/Modal.js +2 -0
  59. package/Libraries/Modal/Modal.windows.js +2 -0
  60. package/Libraries/NativeComponent/BaseViewConfig.android.js +0 -2
  61. package/Libraries/NativeComponent/BaseViewConfig.ios.js +0 -2
  62. package/Libraries/NativeComponent/BaseViewConfig.windows.js +0 -2
  63. package/Libraries/Network/RCTNetworking.android.js +24 -16
  64. package/Libraries/Network/RCTNetworking.ios.js +1 -46
  65. package/Libraries/Network/RCTNetworking.windows.js +1 -46
  66. package/Libraries/Network/RCTNetworkingEventDefinitions.flow.js +57 -0
  67. package/Libraries/ReactNative/UIManagerProperties.js +3 -1
  68. package/Libraries/Renderer/implementations/ReactFabric-dev.js +15828 -26461
  69. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3907 -2560
  70. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4399 -2878
  71. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +16102 -26908
  72. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +4034 -2695
  73. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4535 -3045
  74. package/Libraries/Renderer/shims/ReactNativeTypes.js +5 -6
  75. package/Libraries/StyleSheet/processTransform.js +6 -0
  76. package/Libraries/Text/Text.d.ts +6 -1
  77. package/Libraries/Text/Text.windows.js +4 -0
  78. package/Libraries/Text/TextProps.js +2 -2
  79. package/Libraries/Text/TextProps.windows.js +3 -2
  80. package/Libraries/Utilities/BackHandler.android.js +5 -4
  81. package/Libraries/Utilities/BackHandler.ios.js +4 -5
  82. package/Libraries/Utilities/BackHandler.windows.js +5 -4
  83. package/Microsoft.ReactNative/CompositionComponentView.idl +13 -1
  84. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +0 -1
  85. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +0 -5
  86. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +92 -17
  87. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +9 -0
  88. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +13 -33
  89. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +1 -3
  90. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +43 -5
  91. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.h +2 -1
  92. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +12 -10
  93. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +11 -9
  94. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +1 -1
  95. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +191 -329
  96. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.h +3 -61
  97. package/Microsoft.ReactNative/Fabric/Composition/PortalComponentView.cpp +66 -0
  98. package/Microsoft.ReactNative/Fabric/Composition/PortalComponentView.h +52 -0
  99. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +21 -0
  100. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +7 -4
  101. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +79 -19
  102. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +12 -6
  103. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +71 -17
  104. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +16 -0
  105. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentDescriptor.h +5 -10
  106. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +4 -4
  107. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +138 -110
  108. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.h +27 -27
  109. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +1 -1
  110. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +38 -33
  111. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +0 -2
  112. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +5 -16
  113. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +0 -3
  114. package/Microsoft.ReactNative/Fabric/ImageManager.cpp +9 -0
  115. package/Microsoft.ReactNative/Fabric/WindowsComponentDescriptorRegistry.cpp +0 -2
  116. package/Microsoft.ReactNative/Fabric/platform/react/renderer/graphics/PlatformColorUtils.cpp +1 -1
  117. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +5 -0
  118. package/Microsoft.ReactNative/IReactContext.cpp +2 -2
  119. package/Microsoft.ReactNative/IReactContext.h +1 -1
  120. package/Microsoft.ReactNative/IReactContext.idl +2 -2
  121. package/Microsoft.ReactNative/IReactPackageBuilder.idl +3 -3
  122. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +97 -87
  123. package/Microsoft.ReactNative/Modules/AccessibilityInfoModule.cpp +4 -0
  124. package/Microsoft.ReactNative/Modules/AlertModule.cpp +9 -4
  125. package/Microsoft.ReactNative/Modules/Animated/NativeAnimatedNodeManager.cpp +1 -1
  126. package/Microsoft.ReactNative/Modules/Animated/PropsAnimatedNode.cpp +32 -35
  127. package/Microsoft.ReactNative/Modules/Animated/PropsAnimatedNode.h +7 -4
  128. package/Microsoft.ReactNative/Modules/AppStateModule.cpp +1 -1
  129. package/Microsoft.ReactNative/Modules/AppThemeModuleUwp.cpp +2 -2
  130. package/Microsoft.ReactNative/Modules/AppearanceModule.cpp +2 -2
  131. package/Microsoft.ReactNative/Modules/DeviceInfoModule.cpp +3 -3
  132. package/Microsoft.ReactNative/Modules/I18nManagerModule.cpp +1 -1
  133. package/Microsoft.ReactNative/Modules/LogBoxModule.cpp +7 -5
  134. package/Microsoft.ReactNative/Modules/LogBoxModule.h +2 -1
  135. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +10 -10
  136. package/Microsoft.ReactNative/Modules/PaperUIManagerModule.cpp +24 -24
  137. package/Microsoft.ReactNative/Modules/Timing.cpp +2 -2
  138. package/Microsoft.ReactNative/ReactHost/IReactInstance.h +5 -0
  139. package/Microsoft.ReactNative/ReactHost/React.h +0 -3
  140. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +39 -16
  141. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +4 -2
  142. package/Microsoft.ReactNative/ReactNativeHost.cpp +9 -4
  143. package/Microsoft.ReactNative/ReactNativeIsland.idl +5 -1
  144. package/Microsoft.ReactNative/ReactPackageBuilder.cpp +3 -3
  145. package/Microsoft.ReactNative/ReactPackageBuilder.h +4 -4
  146. package/Microsoft.ReactNative/Utils/Helpers.cpp +0 -2
  147. package/Microsoft.ReactNative/Views/DevMenu.cpp +6 -6
  148. package/Microsoft.ReactNative/Views/DevMenu.h +1 -1
  149. package/Microsoft.ReactNative/Views/ViewManagerBase.cpp +2 -2
  150. package/Microsoft.ReactNative/Views/ViewPanel.cpp +1 -1
  151. package/Microsoft.ReactNative/Views/ViewViewManager.cpp +2 -2
  152. package/Microsoft.ReactNative/XamlUIService.cpp +13 -7
  153. package/Microsoft.ReactNative/XamlUIService.h +4 -1
  154. package/Microsoft.ReactNative/XamlUIService.idl +2 -0
  155. package/Microsoft.ReactNative.Cxx/JSI/JsiAbiApi.h +6 -2
  156. package/Microsoft.ReactNative.Cxx/ReactContext.h +1 -1
  157. package/Microsoft.ReactNative.Cxx/XamlUtils.h +12 -0
  158. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  159. package/PropertySheets/React.Cpp.props +3 -0
  160. package/PropertySheets/WebView2.props +1 -1
  161. package/PropertySheets/WinUI.props +5 -4
  162. package/ReactCommon/ReactCommon.vcxproj +5 -1
  163. package/ReactCommon/ReactCommon.vcxproj.filters +1 -1
  164. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +3 -3
  165. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +3 -3
  166. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +91 -0
  167. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +1 -12
  168. package/{Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputState.h → ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/textinput/TextInputState.h} +37 -35
  169. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/AccessibilityPrimitives.h +1 -0
  170. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/accessibilityPropsConversions.h +4 -0
  171. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/imagemanager/ImageRequestParams.h +30 -0
  172. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/runtimescheduler/SchedulerPriorityUtils.h +4 -3
  173. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/primitives.h +179 -0
  174. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +43 -57
  175. package/Shared/HermesRuntimeHolder.cpp +2 -2
  176. package/Shared/Shared.vcxitems +8 -14
  177. package/Shared/Shared.vcxitems.filters +4 -16
  178. package/Shared/Threading/BatchingQueueThread.cpp +3 -3
  179. package/codegen/NativeCPUTimeSpec.g.h +41 -0
  180. package/codegen/NativeFantomSpec.g.h +78 -0
  181. package/codegen/NativePerformanceSpec.g.h +31 -43
  182. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +84 -84
  183. package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +212 -0
  184. package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +295 -0
  185. package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +200 -0
  186. package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +224 -0
  187. package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +250 -0
  188. package/codegen/react/components/rnwcore/AndroidSwitch.g.h +267 -0
  189. package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +234 -0
  190. package/codegen/react/components/rnwcore/InputAccessory.g.h +200 -0
  191. package/codegen/react/components/rnwcore/ModalHostView.g.h +283 -0
  192. package/codegen/react/components/rnwcore/PullToRefreshView.g.h +246 -0
  193. package/codegen/react/components/rnwcore/SafeAreaView.g.h +197 -0
  194. package/codegen/react/components/rnwcore/Switch.g.h +263 -0
  195. package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +200 -0
  196. package/codegen/rnwcoreJSI-generated.cpp +90 -57
  197. package/codegen/rnwcoreJSI.h +241 -104
  198. package/index.js +5 -0
  199. package/index.windows.js +5 -0
  200. package/just-task.js +1 -1
  201. package/package.json +23 -24
  202. package/src/private/animated/NativeAnimatedValidation.js +1 -1
  203. package/src/private/featureflags/ReactNativeFeatureFlags.js +32 -26
  204. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +5 -5
  205. package/src/private/renderer/errorhandling/ErrorHandlers.js +12 -55
  206. package/src/private/specs/modules/{NativeJSCSamplingProfiler.js → NativeCPUTime.js} +7 -2
  207. package/src/private/specs/modules/NativeFantom.js +37 -0
  208. package/src/private/utilities/ensureInstance.js +21 -0
  209. package/src/private/webapis/dom/nodes/ReactNativeElement.js +49 -6
  210. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +17 -9
  211. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +11 -11
  212. package/src/private/webapis/intersectionobserver/IntersectionObserverEntry.js +1 -1
  213. package/src/private/webapis/intersectionobserver/IntersectionObserverManager.js +1 -1
  214. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +1 -0
  215. package/src/private/webapis/performance/Performance.js +0 -12
  216. package/src/private/webapis/performance/specs/NativePerformance.js +0 -11
  217. package/types/index.d.ts +1 -0
  218. package/Libraries/HeapCapture/HeapCapture.js +0 -29
  219. package/Libraries/HeapCapture/NativeJSCHeapCapture.js +0 -13
  220. package/Libraries/Performance/NativeJSCSamplingProfiler.js +0 -13
  221. package/Libraries/Performance/SamplingProfiler.js +0 -39
  222. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +0 -334
  223. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentDescriptor.h +0 -39
  224. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewShadowNode.cpp +0 -18
  225. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewShadowNode.h +0 -39
  226. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputState.cpp +0 -34
  227. package/Microsoft.ReactNative/Fabric/ReactNativeConfigProperties.cpp +0 -53
  228. package/Microsoft.ReactNative/Fabric/ReactNativeConfigProperties.h +0 -26
  229. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/LayoutableShadowNode.cpp +0 -363
  230. package/codegen/NativeJSCSamplingProfilerSpec.g.h +0 -35
  231. package/src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock.js +0 -413
  232. package/src/private/webapis/intersectionobserver/specs/__mocks__/NativeIntersectionObserver.js +0 -181
  233. package/src/private/webapis/mutationobserver/specs/__mocks__/NativeMutationObserver.js +0 -327
@@ -5,379 +5,241 @@
5
5
 
6
6
  #include "WindowsModalHostViewComponentView.h"
7
7
 
8
- #include <AutoDraw.h>
9
- #include <Fabric/DWriteHelpers.h>
10
- #include "../CompositionDynamicAutomationProvider.h"
11
- #include "Unicode.h"
12
-
13
- #include <DispatcherQueue.h>
14
- #include <Fabric/ComponentView.h>
15
- #include <Fabric/Composition/CompositionContextHelper.h>
16
- #include <Fabric/Composition/CompositionUIService.h>
17
- #include <Fabric/Composition/ReactNativeIsland.h>
18
- #include <windows.ui.composition.interop.h>
19
- #include <winrt/Microsoft.ReactNative.Composition.Experimental.h>
8
+ #include "../../../codegen/react/components/rnwcore/ModalHostView.g.h"
9
+ #include <ComponentView.Experimental.interop.h>
20
10
  #include <winrt/Microsoft.UI.Content.h>
11
+ #include <winrt/Microsoft.UI.Input.h>
12
+ #include <winrt/Microsoft.UI.Windowing.h>
21
13
  #include <winrt/Microsoft.UI.interop.h>
22
- #include <winrt/Windows.UI.Composition.Desktop.h>
23
- #include <winrt/Windows.UI.Composition.h>
24
- #include "IReactContext.h"
25
- #include "ReactHost/ReactInstanceWin.h"
26
- #include "ReactNativeHost.h"
27
- #include "WindowsModalHostViewShadowNode.h"
28
14
 
29
15
  namespace winrt::Microsoft::ReactNative::Composition::implementation {
30
- WindowsModalHostComponentView::WindowsModalHostComponentView(
31
- const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
32
- facebook::react::Tag tag,
33
- winrt::Microsoft::ReactNative::ReactContext const &reactContext)
34
- : Super(compContext, tag, reactContext) {}
35
-
36
- WindowsModalHostComponentView::~WindowsModalHostComponentView() {
37
- // dispatch onDismiss event
38
- auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
39
- facebook::react::ModalHostViewEventEmitter::OnDismiss onDismissArgs;
40
- emitter->onDismiss(onDismissArgs);
41
-
42
- // reset the topWindowID
43
- if (m_prevWindowID) {
44
- auto host =
45
- winrt::Microsoft::ReactNative::implementation::ReactNativeHost::GetReactNativeHost(m_reactContext.Properties());
46
- winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
47
- host.InstanceSettings().Properties(), m_prevWindowID);
48
- m_prevWindowID = 0;
49
- }
50
-
51
- // enable input to parent
52
- EnableWindow(m_parentHwnd, true);
53
-
54
- // Check if the window handle (m_hwnd) exists and destroy it if necessary
55
- if (m_hwnd) {
56
- // Close/Destroy the modal window
57
- SendMessage(m_hwnd, WM_DESTROY, 0, 0);
58
- m_hwnd = nullptr;
59
- }
60
- }
61
-
62
- winrt::Microsoft::ReactNative::ComponentView WindowsModalHostComponentView::Create(
63
- const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
64
- facebook::react::Tag tag,
65
- winrt::Microsoft::ReactNative::ReactContext const &reactContext) noexcept {
66
- return winrt::make<WindowsModalHostComponentView>(compContext, tag, reactContext);
67
- }
68
16
 
69
- // constants for creating a new windows
70
- constexpr PCWSTR c_modalWindowClassName = L"MS_REACTNATIVE_MODAL";
71
- constexpr auto CompHostProperty = L"CompHost";
72
- const int MODAL_MIN_WIDTH = 50;
73
- const int MODAL_MIN_HEIGHT = 50;
17
+ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::Foundation::IInspectable>,
18
+ ::Microsoft::ReactNativeSpecs::BaseModalHostView<ModalHostView> {
19
+ ~ModalHostView() {
20
+ if (m_window && m_window.IsVisible()) {
21
+ CloseWindow();
22
+ }
74
23
 
75
- float ScaleFactor(HWND hwnd) noexcept {
76
- return GetDpiForWindow(hwnd) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);
77
- }
24
+ if (m_reactNativeIsland) {
25
+ m_reactNativeIsland.Island().Close();
26
+ }
78
27
 
79
- // creates a new modal window
80
- void WindowsModalHostComponentView::EnsureModalCreated() {
81
- auto host =
82
- winrt::Microsoft::ReactNative::implementation::ReactNativeHost::GetReactNativeHost(m_reactContext.Properties());
28
+ if (m_bridge) {
29
+ if (m_departFocusToken && !m_bridge.IsClosed()) {
30
+ auto navHost = winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteBridge(m_bridge);
31
+ navHost.DepartFocusRequested(m_departFocusToken);
32
+ }
33
+ m_bridge.Close();
34
+ }
83
35
 
84
- // return if hwnd already exists
85
- if (!host || m_hwnd) {
86
- return;
36
+ if (m_window) {
37
+ m_window.Destroy();
38
+ m_window = nullptr;
39
+ }
87
40
  }
88
41
 
89
- RegisterWndClass();
90
-
91
- HINSTANCE hInstance = GetModuleHandle(NULL);
92
- winrt::com_ptr<::IUnknown> spunk;
93
-
94
- // get the root hwnd
95
- m_prevWindowID =
96
- winrt::Microsoft::ReactNative::ReactCoreInjection::GetTopLevelWindowId(m_reactContext.Properties().Handle());
42
+ void InitializePortalViewComponent(
43
+ const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portalComponentView) noexcept {
44
+ m_reactContext = portalComponentView.ReactContext();
97
45
 
98
- m_parentHwnd = GetHwndForParenting();
99
-
100
- auto windowsStyle = m_showTitleBar ? WS_OVERLAPPEDWINDOW : WS_POPUP;
101
-
102
- m_hwnd = CreateWindow(
103
- c_modalWindowClassName,
104
- L"React-Native Modal",
105
- windowsStyle,
106
- CW_USEDEFAULT,
107
- CW_USEDEFAULT,
108
- MODAL_MIN_WIDTH,
109
- MODAL_MIN_HEIGHT,
110
- m_parentHwnd, // parent
111
- nullptr,
112
- hInstance,
113
- spunk.get());
114
-
115
- // Check if window creation succeeded
116
- if (!m_hwnd) {
117
- throw std::exception("Failed to create new hwnd for Modal: " + GetLastError());
46
+ portalComponentView.Mounted(
47
+ [](const auto & /*sender*/, const auto &view) { view.UserData().as<ModalHostView>()->OnMounted(view); });
48
+ portalComponentView.Unmounted(
49
+ [](const auto & /*sender*/, const auto &view) { view.UserData().as<ModalHostView>()->OnUnmounted(view); });
118
50
  }
119
51
 
120
- // Disable user sizing of the hwnd
121
- ::SetWindowLong(m_hwnd, GWL_STYLE, GetWindowLong(m_hwnd, GWL_STYLE) & ~WS_SIZEBOX);
122
-
123
- // set the top-level windows as the new hwnd
124
- winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
125
- host.InstanceSettings().Properties(), reinterpret_cast<uint64_t>(m_hwnd));
126
-
127
- // get current compositor - handles the creation/manipulation of visual objects
128
- auto compositionContext = CompositionContext();
129
- auto compositor =
130
- winrt::Microsoft::ReactNative::Composition::Experimental::MicrosoftCompositionContextHelper::InnerCompositor(
131
- compositionContext);
132
-
133
- // create a react native island - code taken from CompositionHwndHost
134
- auto bridge = winrt::Microsoft::UI::Content::DesktopChildSiteBridge::Create(
135
- compositor, winrt::Microsoft::UI::GetWindowIdFromWindow(m_hwnd));
136
- m_reactNativeIsland = winrt::Microsoft::ReactNative::ReactNativeIsland(compositor, m_reactContext.Handle(), *this);
137
- auto contentIsland = m_reactNativeIsland.Island();
138
- bridge.Connect(contentIsland);
139
- bridge.Show();
140
-
141
- // set ScaleFactor
142
- ScaleFactor(m_hwnd);
143
-
144
- // set layout contraints
145
- winrt::Microsoft::ReactNative::LayoutConstraints constraints;
146
- constraints.LayoutDirection = winrt::Microsoft::ReactNative::LayoutDirection::Undefined;
147
-
148
- RECT rc;
149
- GetClientRect(m_parentHwnd, &rc);
150
- // Maximum size is set to size of parent hwnd
151
- constraints.MaximumSize = {(rc.right - rc.left) * ScaleFactor(m_hwnd), (rc.bottom - rc.top) / ScaleFactor(m_hwnd)};
152
- constraints.MinimumSize = {MODAL_MIN_WIDTH * ScaleFactor(m_hwnd), MODAL_MIN_HEIGHT * ScaleFactor(m_hwnd)};
153
- m_reactNativeIsland.Arrange(constraints, {0, 0});
154
- bridge.ResizePolicy(winrt::Microsoft::UI::Content::ContentSizePolicy::ResizeContentToParentWindow);
155
-
156
- spunk.detach();
157
- }
158
-
159
- void WindowsModalHostComponentView::ShowOnUIThread() {
160
- if (m_hwnd && !IsWindowVisible(m_hwnd)) {
161
- ShowWindow(m_hwnd, SW_NORMAL);
162
- BringWindowToTop(m_hwnd);
163
- SetFocus(m_hwnd);
164
-
165
- // disable input to parent
166
- EnableWindow(m_parentHwnd, false);
167
-
168
- // dispatch onShow event
169
- auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
170
- facebook::react::ModalHostViewEventEmitter::OnShow onShowArgs;
171
- emitter->onShow(onShowArgs);
52
+ void UpdateProps(
53
+ const winrt::Microsoft::ReactNative::ComponentView &view,
54
+ const winrt::com_ptr<::Microsoft::ReactNativeSpecs::ModalHostViewProps> &newProps,
55
+ const winrt::com_ptr<::Microsoft::ReactNativeSpecs::ModalHostViewProps> &oldProps) noexcept override {
56
+ if (!oldProps || newProps->visible != oldProps->visible) {
57
+ if (newProps->visible.value_or(true)) {
58
+ // We do not immediately show the window, since we want to resize/position
59
+ // the window based on the layout metrics before we show it
60
+ m_showQueued = true;
61
+ } else {
62
+ CloseWindow();
63
+ }
64
+ }
65
+ ::Microsoft::ReactNativeSpecs::BaseModalHostView<ModalHostView>::UpdateProps(view, newProps, oldProps);
172
66
  }
173
- }
174
67
 
175
- void WindowsModalHostComponentView::HideOnUIThread() noexcept {
176
- if (m_hwnd) {
177
- SendMessage(m_hwnd, WM_CLOSE, 0, 0);
68
+ void UpdateLayoutMetrics(
69
+ const winrt::Microsoft::ReactNative::ComponentView &view,
70
+ const winrt::Microsoft::ReactNative::LayoutMetrics &newLayoutMetrics,
71
+ const winrt::Microsoft::ReactNative::LayoutMetrics & /*oldLayoutMetrics*/) noexcept override {
72
+ if (m_window) {
73
+ AdjustWindowSize(newLayoutMetrics);
74
+ }
178
75
  }
179
76
 
180
- // dispatch onDismiss event
181
- auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
182
- facebook::react::ModalHostViewEventEmitter::OnDismiss onDismissArgs;
183
- emitter->onDismiss(onDismissArgs);
77
+ void FinalizeUpdate(
78
+ const winrt::Microsoft::ReactNative::ComponentView &view,
79
+ winrt::Microsoft::ReactNative::ComponentViewUpdateMask /*mask*/) noexcept override {
80
+ if (m_showQueued) {
81
+ ShowOnUIThread(view);
82
+ }
83
+ }
184
84
 
185
- // enable input to parent
186
- EnableWindow(m_parentHwnd, true);
85
+ private:
86
+ void OnMounted(const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
87
+ m_mounted = true;
187
88
 
188
- // reset the topWindowID
189
- if (m_prevWindowID) {
190
- auto host =
191
- winrt::Microsoft::ReactNative::implementation::ReactNativeHost::GetReactNativeHost(m_reactContext.Properties());
192
- winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
193
- host.InstanceSettings().Properties(), m_prevWindowID);
194
- m_prevWindowID = 0;
89
+ if (m_showQueued) {
90
+ ShowOnUIThread(view);
91
+ }
195
92
  }
196
- }
197
93
 
198
- // Windows Procedure - callback function used for handling all messages (generated by NTUser or manual calls to
199
- // SendMessage)
200
- LRESULT CALLBACK ModalBoxWndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) noexcept {
201
- auto data = reinterpret_cast<::IUnknown *>(GetProp(
202
- hwnd,
203
- CompHostProperty)); // gets data handle from the property list of specified window (ie the window we want to make)
204
- winrt::Microsoft::ReactNative::CompositionHwndHost host{nullptr};
205
-
206
- if (data) {
207
- winrt::check_hresult(data->QueryInterface(
208
- winrt::guid_of<winrt::Microsoft::ReactNative::CompositionHwndHost>(),
209
- winrt::put_abi(host))); // look into the data for a CompositionHwndHost and store it in host
210
- auto result = static_cast<LRESULT>(host.TranslateMessage(message, wparam, lparam));
211
- if (result) {
212
- return result;
213
- }
94
+ void OnUnmounted(const winrt::Microsoft::ReactNative::ComponentView & /*view*/) noexcept {
95
+ m_mounted = false;
214
96
  }
215
97
 
216
- switch (message) {
217
- case WM_NCCREATE: { // called before WM_CREATE, lparam should be identical to members of CreateWindowEx
218
- auto createStruct = reinterpret_cast<CREATESTRUCT *>(lparam); // CreateStruct
219
- data = static_cast<::IUnknown *>(createStruct->lpCreateParams);
220
- SetProp(hwnd, CompHostProperty, data); // adds new properties to window
221
- break;
98
+ void AdjustWindowSize(const winrt::Microsoft::ReactNative::LayoutMetrics &layoutMetrics) noexcept {
99
+ if (layoutMetrics.Frame.Width == 0 && layoutMetrics.Frame.Height == 0) {
100
+ return;
222
101
  }
223
- case WM_CLOSE: {
224
- // Just hide the window instead of destroying it
225
- ::ShowWindow(hwnd, SW_HIDE);
226
- return 0;
227
- }
228
- case WM_DESTROY: { // called when we want to destroy the window
229
- ::ShowWindow(hwnd, SW_HIDE);
230
- if (data) {
231
- data->Release();
102
+
103
+ // get Modal's position based on parent
104
+ RECT parentRC;
105
+ GetWindowRect(m_parentHwnd, &parentRC);
106
+ int32_t xCor = static_cast<int32_t>(
107
+ (parentRC.left + parentRC.right - layoutMetrics.Frame.Width * layoutMetrics.PointScaleFactor) / 2);
108
+ int32_t yCor = static_cast<int32_t>(
109
+ (parentRC.top + parentRC.bottom - layoutMetrics.Frame.Height * layoutMetrics.PointScaleFactor) / 2);
110
+
111
+ // Adjust window position and size
112
+ m_window.ResizeClient(
113
+ {static_cast<int32_t>(layoutMetrics.Frame.Width * (layoutMetrics.PointScaleFactor)),
114
+ static_cast<int32_t>(layoutMetrics.Frame.Height * (layoutMetrics.PointScaleFactor))});
115
+ m_window.Move({xCor, yCor});
116
+ };
117
+
118
+ void ShowOnUIThread(const winrt::Microsoft::ReactNative::ComponentView &view) {
119
+ if (!m_mounted)
120
+ return;
121
+
122
+ m_showQueued = false;
123
+ EnsureModalCreated(view);
124
+
125
+ if (m_window && !m_window.IsVisible()) {
126
+ m_bridge.Enable();
127
+ m_window.Show(true);
128
+
129
+ auto navHost = winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteBridge(m_bridge);
130
+ auto result = navHost.NavigateFocus(winrt::Microsoft::UI::Input::FocusNavigationRequest::Create(
131
+ winrt::Microsoft::UI::Input::FocusNavigationReason::First));
132
+
133
+ // dispatch onShow event
134
+ if (auto eventEmitter = EventEmitter()) {
135
+ ::Microsoft::ReactNativeSpecs::ModalHostViewEventEmitter::OnShow eventArgs;
136
+ eventEmitter->onShow(eventArgs);
232
137
  }
233
- SetProp(hwnd, CompHostProperty, nullptr);
234
- break;
235
138
  }
236
139
  }
237
140
 
238
- return DefWindowProc(hwnd, message, wparam, lparam);
239
- }
240
-
241
- // Creates and Register a new window class
242
- void WindowsModalHostComponentView::RegisterWndClass() noexcept {
243
- static bool registered = false;
244
- if (registered) {
245
- return;
246
- }
247
-
248
- HINSTANCE hInstance =
249
- GetModuleHandle(NULL); // returns a handle to the file used to create the calling process (.exe file)
250
-
251
- WNDCLASSEX wcex = {}; // contains window class information
252
- wcex.cbSize = sizeof(wcex); // size of windows class (bytes)
253
- wcex.style = CS_HREDRAW | CS_VREDRAW; // class style (redraw window on size adjustment)
254
- wcex.lpfnWndProc = &ModalBoxWndProc; // pointer to windows procedure
255
- wcex.cbClsExtra = DLGWINDOWEXTRA; // extra bytes to allocate
256
- wcex.cbWndExtra =
257
- sizeof(winrt::impl::abi<winrt::Microsoft::ReactNative::ICompositionHwndHost>::type *); // extra bytes to allocate
258
- wcex.hInstance = hInstance;
259
- wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); // handle to class cursor
260
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // background color
261
- wcex.lpszClassName = c_modalWindowClassName; // specify resource name
262
- ATOM classId = RegisterClassEx(&wcex); // register new windows class
263
- WINRT_VERIFY(classId); // 0 = fail
264
- winrt::check_win32(!classId);
265
-
266
- registered = true;
267
- }
268
-
269
- winrt::Microsoft::ReactNative::Composition::Experimental::IVisual
270
- WindowsModalHostComponentView::VisualToMountChildrenInto() noexcept {
271
- return m_reactNativeIsland
272
- .as<winrt::Microsoft::ReactNative::Composition::Experimental::IInternalCompositionRootView>()
273
- .InternalRootVisual();
274
- }
141
+ void CloseWindow() noexcept {
142
+ // enable input to parent before closing the modal window, so focus can return back to the parent window
143
+ EnableWindow(m_parentHwnd, true);
275
144
 
276
- // childComponentView - reference to the child component view
277
- // index - the position in which the childComponentView should be mounted
278
- void WindowsModalHostComponentView::MountChildComponentView(
279
- const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
280
- uint32_t index) noexcept {
281
- EnsureModalCreated();
282
- base_type::MountChildComponentView(childComponentView, index);
283
- }
145
+ if (m_window) {
146
+ m_window.Hide();
147
+ }
284
148
 
285
- void WindowsModalHostComponentView::UnmountChildComponentView(
286
- const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
287
- uint32_t index) noexcept {
288
- base_type::UnmountChildComponentView(childComponentView, index);
289
- }
149
+ // dispatch onDismiss event
150
+ if (auto eventEmitter = EventEmitter()) {
151
+ ::Microsoft::ReactNativeSpecs::ModalHostViewEventEmitter::OnDismiss eventArgs;
152
+ eventEmitter->onDismiss(eventArgs);
153
+ }
290
154
 
291
- void WindowsModalHostComponentView::updateLayoutMetrics(
292
- facebook::react::LayoutMetrics const &layoutMetrics,
293
- facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
294
- base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
295
- if (m_hwnd) {
296
- EnsureModalCreated();
297
- AdjustWindowSize();
298
- ShowOnUIThread();
299
- }
300
- }
155
+ // reset the topWindowID
156
+ if (m_prevWindowID) {
157
+ winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
158
+ m_reactContext.Properties().Handle(), m_prevWindowID);
159
+ m_prevWindowID = 0;
160
+ }
301
161
 
302
- void WindowsModalHostComponentView::AdjustWindowSize() noexcept {
303
- if (m_layoutMetrics.overflowInset.right == 0 && m_layoutMetrics.overflowInset.bottom == 0) {
304
- return;
162
+ m_bridge.Disable();
305
163
  }
306
164
 
307
- // Modal's size is based on it's children, use the overflow to calculate the width/height
308
- float xPos = (-m_layoutMetrics.overflowInset.right * (m_layoutMetrics.pointScaleFactor));
309
- float yPos = (-m_layoutMetrics.overflowInset.bottom * (m_layoutMetrics.pointScaleFactor));
310
- RECT rc;
311
- GetClientRect(m_hwnd, &rc);
312
- RECT rect = {0, 0, (int)xPos, (int)yPos};
313
-
314
- if (m_showTitleBar) {
315
- AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); // Adjust for title bar and borders
316
- }
165
+ // creates a new modal window
166
+ void EnsureModalCreated(const winrt::Microsoft::ReactNative::ComponentView &view) {
167
+ if (m_window) {
168
+ return;
169
+ }
317
170
 
318
- // set the layoutMetrics
319
- m_layoutMetrics.frame.size = {(float)rect.right - rect.left, (float)rect.bottom - rect.top};
320
- m_layoutMetrics.overflowInset.right = 0;
321
- m_layoutMetrics.overflowInset.bottom = 0;
171
+ // get the root hwnd
172
+ m_prevWindowID =
173
+ winrt::Microsoft::ReactNative::ReactCoreInjection::GetTopLevelWindowId(view.ReactContext().Properties());
322
174
 
323
- // get Modal's position based on parent
324
- RECT parentRC;
325
- GetWindowRect(m_parentHwnd, &parentRC);
326
- float xCor = (parentRC.left + parentRC.right - m_layoutMetrics.frame.size.width) / 2; // midpointx - width / 2
327
- float yCor = (parentRC.top + parentRC.bottom - m_layoutMetrics.frame.size.height) / 2; // midpointy - height / 2
175
+ m_parentHwnd =
176
+ view.as<::Microsoft::ReactNative::Composition::Experimental::IComponentViewInterop>()->GetHwndForParenting();
328
177
 
329
- // Adjust window position and size
330
- MoveWindow(m_hwnd, (int)xCor, (int)yCor, (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), true);
178
+ auto presenter = winrt::Microsoft::UI::Windowing::OverlappedPresenter::CreateForDialog();
179
+ presenter.SetBorderAndTitleBar(true, false);
180
+ presenter.IsModal(true);
331
181
 
332
- // Let RNWIsland know that Modal's size has changed
333
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(m_reactNativeIsland)
334
- ->NotifySizeChanged();
335
- };
182
+ m_window = winrt::Microsoft::UI::Windowing::AppWindow::Create(
183
+ presenter, winrt::Microsoft::UI::GetWindowIdFromWindow(m_parentHwnd));
336
184
 
337
- void WindowsModalHostComponentView::updateProps(
338
- facebook::react::Props::Shared const &props,
339
- facebook::react::Props::Shared const &oldProps) noexcept {
340
- const auto &oldModalProps =
341
- *std::static_pointer_cast<const facebook::react::ModalHostViewProps>(oldProps ? oldProps : viewProps());
342
- const auto &newModalProps = *std::static_pointer_cast<const facebook::react::ModalHostViewProps>(props);
343
- newModalProps.visible ? m_isVisible = true : m_isVisible = false;
344
- if (!m_isVisible) {
345
- HideOnUIThread();
185
+ // set the top-level windows as the new hwnd
186
+ winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
187
+ view.ReactContext().Properties(),
188
+ reinterpret_cast<uint64_t>(winrt::Microsoft::UI::GetWindowFromWindowId(m_window.Id())));
189
+
190
+ // create a react native island - code taken from CompositionHwndHost
191
+ m_bridge = winrt::Microsoft::UI::Content::DesktopChildSiteBridge::Create(
192
+ view.Parent().as<winrt::Microsoft::ReactNative::Composition::ComponentView>().Compositor(), m_window.Id());
193
+ m_reactNativeIsland = winrt::Microsoft::ReactNative::ReactNativeIsland::CreatePortal(
194
+ view.as<winrt::Microsoft::ReactNative::Composition::PortalComponentView>());
195
+ auto contentIsland = m_reactNativeIsland.Island();
196
+
197
+ auto navHost = winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteBridge(m_bridge);
198
+ m_departFocusToken = navHost.DepartFocusRequested(
199
+ [wkView = winrt::make_weak(view)](
200
+ const auto &sender, const winrt::Microsoft::UI::Input::FocusNavigationRequestEventArgs &args) {
201
+ if (auto strongView = wkView.get()) {
202
+ TrySetFocus(strongView.Parent());
203
+ }
204
+ });
205
+
206
+ m_bridge.ResizePolicy(winrt::Microsoft::UI::Content::ContentSizePolicy::ResizeContentToParentWindow);
207
+ m_bridge.Connect(contentIsland);
208
+ AdjustWindowSize(view.LayoutMetrics());
209
+ m_bridge.Show();
346
210
  }
347
- base_type::updateProps(props, oldProps);
348
- }
349
211
 
350
- facebook::react::SharedViewProps WindowsModalHostComponentView::defaultProps() noexcept {
351
- static auto const defaultProps = std::make_shared<facebook::react::ModalHostViewProps const>();
352
- return defaultProps;
353
- }
354
- const facebook::react::ModalHostViewProps &WindowsModalHostComponentView::modalHostViewProps() const noexcept {
355
- return *std::static_pointer_cast<const facebook::react::ModalHostViewProps>(viewProps());
356
- }
357
-
358
- facebook::react::Tag WindowsModalHostComponentView::hitTest(
359
- facebook::react::Point pt,
360
- facebook::react::Point &localPt,
361
- bool ignorePointerEvents) const noexcept {
362
- facebook::react::Point ptLocal{pt.x - m_layoutMetrics.frame.origin.x, pt.y - m_layoutMetrics.frame.origin.y};
363
-
364
- if ((ignorePointerEvents || viewProps()->pointerEvents == facebook::react::PointerEventsMode::Auto ||
365
- viewProps()->pointerEvents == facebook::react::PointerEventsMode::BoxOnly) &&
366
- ptLocal.x >= 0 && ptLocal.x <= m_layoutMetrics.frame.size.width && ptLocal.y >= 0 &&
367
- ptLocal.y <= m_layoutMetrics.frame.size.height) {
368
- localPt = ptLocal;
369
- return Tag();
212
+ static void TrySetFocus(const winrt::Microsoft::ReactNative::ComponentView &view) {
213
+ auto focusController = winrt::Microsoft::UI::Input::InputFocusController::GetForIsland(
214
+ view.as<winrt::Microsoft::ReactNative::Composition::ComponentView>().Root().ReactNativeIsland().Island());
215
+ focusController.TrySetFocus();
370
216
  }
371
217
 
372
- return -1;
373
- }
374
-
375
- bool WindowsModalHostComponentView::focusable() const noexcept {
376
- return false;
377
- }
218
+ ReactContext m_reactContext{nullptr};
219
+ HWND m_parentHwnd{nullptr};
220
+ winrt::Microsoft::UI::Windowing::AppWindow m_window{nullptr};
221
+ uint64_t m_prevWindowID;
222
+ bool m_showTitleBar{false};
223
+ bool m_showQueued{false};
224
+ bool m_mounted{false};
225
+ winrt::Microsoft::UI::Input::InputFocusNavigationHost::DepartFocusRequested_revoker m_departFocusRevoker;
226
+ winrt::event_token m_departFocusToken;
227
+ winrt::Microsoft::UI::Content::DesktopChildSiteBridge m_bridge{nullptr};
228
+ winrt::Microsoft::ReactNative::ReactNativeIsland m_reactNativeIsland{nullptr};
229
+ };
378
230
 
379
- std::string WindowsModalHostComponentView::DefaultControlType() const noexcept {
380
- return "modal";
231
+ void RegisterWindowsModalHostNativeComponent(
232
+ winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder) noexcept {
233
+ ::Microsoft::ReactNativeSpecs::RegisterModalHostViewNativeComponent<ModalHostView>(
234
+ packageBuilder,
235
+ [](const winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder &builder) {
236
+ builder.SetPortalComponentViewInitializer(
237
+ [](const winrt::Microsoft::ReactNative::Composition::PortalComponentView &portalComponentView) noexcept {
238
+ auto userData = winrt::make_self<ModalHostView>();
239
+ userData->InitializePortalViewComponent(portalComponentView);
240
+ portalComponentView.UserData(*userData);
241
+ });
242
+ });
381
243
  }
382
244
 
383
245
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -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