react-native-windows 0.75.9 → 0.75.11

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 (118) hide show
  1. package/Libraries/Modal/Modal.windows.js +352 -0
  2. package/Microsoft.ReactNative/CompositionComponentView.idl +2 -1
  3. package/Microsoft.ReactNative/Fabric/AbiComponentDescriptor.cpp +4 -1
  4. package/Microsoft.ReactNative/Fabric/AbiViewComponentDescriptor.cpp +1 -1
  5. package/Microsoft.ReactNative/Fabric/AbiViewProps.cpp +7 -0
  6. package/Microsoft.ReactNative/Fabric/AbiViewProps.h +2 -0
  7. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +45 -50
  8. package/Microsoft.ReactNative/Fabric/ComponentView.h +14 -22
  9. package/Microsoft.ReactNative/Fabric/Composition/BorderPrimitive.cpp +931 -0
  10. package/Microsoft.ReactNative/Fabric/Composition/BorderPrimitive.h +80 -0
  11. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +31 -13
  12. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +187 -6
  13. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +10 -1
  14. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootAutomationProvider.cpp +8 -32
  15. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +316 -911
  16. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +32 -29
  17. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +9 -2
  18. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +2 -1
  19. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +1 -1
  20. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +181 -123
  21. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.h +16 -8
  22. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +99 -37
  23. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +25 -3
  24. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +63 -2
  25. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +12 -0
  26. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +51 -3
  27. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +3 -0
  28. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +18 -8
  29. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +3 -0
  30. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +54 -5
  31. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +8 -0
  32. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +9 -3
  33. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +11 -0
  34. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +2 -0
  35. package/Microsoft.ReactNative/Fabric/Composition/UnimplementedNativeViewComponentView.cpp +1 -1
  36. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +26 -0
  37. package/Microsoft.ReactNative/IReactViewComponentBuilder.idl +1 -1
  38. package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +25 -129
  39. package/Microsoft.ReactNative/ReactNativeAppBuilder.h +5 -13
  40. package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +13 -34
  41. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -2
  42. package/Microsoft.ReactNative/ReactNativeWin32App.cpp +129 -18
  43. package/Microsoft.ReactNative/ReactNativeWin32App.h +14 -5
  44. package/Microsoft.ReactNative/ViewProps.idl +2 -0
  45. package/Microsoft.ReactNative.Cxx/ComponentView.Experimental.interop.h +14 -0
  46. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  47. package/Shared/Shared.vcxitems +3 -10
  48. package/Shared/Shared.vcxitems.filters +1 -0
  49. package/codegen/NativeAccessibilityInfoSpec.g.h +1 -0
  50. package/codegen/NativeAccessibilityManagerSpec.g.h +1 -0
  51. package/codegen/NativeActionSheetManagerSpec.g.h +1 -0
  52. package/codegen/NativeAlertManagerSpec.g.h +1 -0
  53. package/codegen/NativeAnimatedModuleSpec.g.h +1 -0
  54. package/codegen/NativeAnimatedTurboModuleSpec.g.h +1 -0
  55. package/codegen/NativeAppStateSpec.g.h +1 -0
  56. package/codegen/NativeAppThemeSpec.g.h +1 -0
  57. package/codegen/NativeAppearanceSpec.g.h +1 -0
  58. package/codegen/NativeBlobModuleSpec.g.h +1 -0
  59. package/codegen/NativeBugReportingSpec.g.h +1 -0
  60. package/codegen/NativeClipboardSpec.g.h +1 -0
  61. package/codegen/NativeDOMSpec.g.h +1 -0
  62. package/codegen/NativeDevLoadingViewSpec.g.h +1 -0
  63. package/codegen/NativeDevMenuSpec.g.h +1 -0
  64. package/codegen/NativeDevSettingsSpec.g.h +1 -0
  65. package/codegen/NativeDevToolsSettingsManagerSpec.g.h +1 -0
  66. package/codegen/NativeDeviceEventManagerSpec.g.h +1 -0
  67. package/codegen/NativeDeviceInfoSpec.g.h +1 -0
  68. package/codegen/NativeDialogManagerAndroidSpec.g.h +1 -0
  69. package/codegen/NativeDialogManagerWindowsSpec.g.h +1 -0
  70. package/codegen/NativeExceptionsManagerSpec.g.h +1 -0
  71. package/codegen/NativeFileReaderModuleSpec.g.h +1 -0
  72. package/codegen/NativeFrameRateLoggerSpec.g.h +1 -0
  73. package/codegen/NativeHeadlessJsTaskSupportSpec.g.h +1 -0
  74. package/codegen/NativeI18nManagerSpec.g.h +1 -0
  75. package/codegen/NativeIdleCallbacksSpec.g.h +1 -0
  76. package/codegen/NativeImageEditorSpec.g.h +1 -0
  77. package/codegen/NativeImageLoaderAndroidSpec.g.h +1 -0
  78. package/codegen/NativeImageLoaderIOSSpec.g.h +1 -0
  79. package/codegen/NativeImageStoreAndroidSpec.g.h +1 -0
  80. package/codegen/NativeImageStoreIOSSpec.g.h +1 -0
  81. package/codegen/NativeIntentAndroidSpec.g.h +1 -0
  82. package/codegen/NativeIntersectionObserverSpec.g.h +1 -0
  83. package/codegen/NativeJSCHeapCaptureSpec.g.h +1 -0
  84. package/codegen/NativeJSCSamplingProfilerSpec.g.h +1 -0
  85. package/codegen/NativeKeyboardObserverSpec.g.h +1 -0
  86. package/codegen/NativeLinkingManagerSpec.g.h +1 -0
  87. package/codegen/NativeLogBoxSpec.g.h +1 -0
  88. package/codegen/NativeMicrotasksSpec.g.h +1 -0
  89. package/codegen/NativeModalManagerSpec.g.h +1 -0
  90. package/codegen/NativeMutationObserverSpec.g.h +1 -0
  91. package/codegen/NativeNetworkingAndroidSpec.g.h +1 -0
  92. package/codegen/NativeNetworkingIOSSpec.g.h +1 -0
  93. package/codegen/NativePerformanceObserverSpec.g.h +1 -0
  94. package/codegen/NativePerformanceSpec.g.h +1 -0
  95. package/codegen/NativePermissionsAndroidSpec.g.h +1 -0
  96. package/codegen/NativePlatformConstantsAndroidSpec.g.h +1 -0
  97. package/codegen/NativePlatformConstantsIOSSpec.g.h +1 -0
  98. package/codegen/NativePlatformConstantsWindowsSpec.g.h +1 -0
  99. package/codegen/NativePushNotificationManagerIOSSpec.g.h +1 -0
  100. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +1 -0
  101. package/codegen/NativeRedBoxSpec.g.h +1 -0
  102. package/codegen/NativeSampleTurboModuleSpec.g.h +1 -0
  103. package/codegen/NativeSegmentFetcherSpec.g.h +1 -0
  104. package/codegen/NativeSettingsManagerSpec.g.h +1 -0
  105. package/codegen/NativeShareModuleSpec.g.h +1 -0
  106. package/codegen/NativeSoundManagerSpec.g.h +1 -0
  107. package/codegen/NativeSourceCodeSpec.g.h +1 -0
  108. package/codegen/NativeStatusBarManagerAndroidSpec.g.h +1 -0
  109. package/codegen/NativeStatusBarManagerIOSSpec.g.h +1 -0
  110. package/codegen/NativeTimingSpec.g.h +1 -0
  111. package/codegen/NativeToastAndroidSpec.g.h +1 -0
  112. package/codegen/NativeUIManagerSpec.g.h +1 -0
  113. package/codegen/NativeVibrationSpec.g.h +1 -0
  114. package/codegen/NativeWebSocketModuleSpec.g.h +1 -0
  115. package/package.json +3 -3
  116. package/templates/cpp-app/windows/MyApp/MyApp.cpp +46 -130
  117. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.cpp +0 -59
  118. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.h +0 -23
@@ -165,6 +165,10 @@ struct CompTextHost : public winrt::implements<CompTextHost, ITextHost> {
165
165
 
166
166
  //@cmember Show the caret
167
167
  BOOL TxShowCaret(BOOL fShow) override {
168
+ // Only show the caret if we have focus
169
+ if (fShow && !m_outer->m_hasFocus) {
170
+ return false;
171
+ }
168
172
  m_outer->ShowCaret(m_outer->windowsTextInputProps().caretHidden ? false : fShow);
169
173
  return true;
170
174
  }
@@ -232,19 +236,25 @@ struct CompTextHost : public winrt::implements<CompTextHost, ITextHost> {
232
236
 
233
237
  //@cmember Establish a new cursor shape
234
238
  void TxSetCursor(HCURSOR hcur, BOOL fText) override {
235
- assert(false);
239
+ m_outer->m_hcursor = hcur;
236
240
  }
237
241
 
238
242
  //@cmember Converts screen coordinates of a specified point to the client coordinates
239
243
  BOOL TxScreenToClient(LPPOINT lppt) override {
240
- assert(false);
241
- return {};
244
+ winrt::Windows::Foundation::Point pt{static_cast<float>(lppt->x), static_cast<float>(lppt->y)};
245
+ auto localpt = m_outer->ScreenToLocal(pt);
246
+ lppt->x = static_cast<LONG>(localpt.X);
247
+ lppt->y = static_cast<LONG>(localpt.Y);
248
+ return true;
242
249
  }
243
250
 
244
251
  //@cmember Converts the client coordinates of a specified point to screen coordinates
245
252
  BOOL TxClientToScreen(LPPOINT lppt) override {
246
- assert(false);
247
- return {};
253
+ winrt::Windows::Foundation::Point pt{static_cast<float>(lppt->x), static_cast<float>(lppt->y)};
254
+ auto screenpt = m_outer->LocalToScreen(pt);
255
+ lppt->x = static_cast<LONG>(screenpt.X);
256
+ lppt->y = static_cast<LONG>(screenpt.Y);
257
+ return true;
248
258
  }
249
259
 
250
260
  //@cmember Request host to activate text services
@@ -722,6 +732,9 @@ void WindowsTextInputComponentView::OnPointerMoved(
722
732
  auto hr = m_textServices->TxSendMessage(msg, static_cast<WPARAM>(wParam), static_cast<LPARAM>(lParam), &lresult);
723
733
  args.Handled(hr != S_FALSE);
724
734
  }
735
+
736
+ m_textServices->OnTxSetCursor(
737
+ DVASPECT_CONTENT, -1, nullptr, nullptr, nullptr, nullptr, nullptr, ptContainer.x, ptContainer.y);
725
738
  }
726
739
 
727
740
  void WindowsTextInputComponentView::OnKeyDown(
@@ -870,6 +883,7 @@ void WindowsTextInputComponentView::OnCharacterReceived(
870
883
  emitter->onKeyPress(onKeyPressArgs);
871
884
 
872
885
  WPARAM wParam = static_cast<WPARAM>(args.KeyCode());
886
+
873
887
  LPARAM lParam = 0;
874
888
  lParam = args.KeyStatus().RepeatCount; // bits 0-15
875
889
  lParam |= args.KeyStatus().ScanCode << 16; // bits 16-23
@@ -908,6 +922,7 @@ void WindowsTextInputComponentView::UnmountChildComponentView(
908
922
 
909
923
  void WindowsTextInputComponentView::onLostFocus(
910
924
  const winrt::Microsoft::ReactNative::Composition::Input::RoutedEventArgs &args) noexcept {
925
+ m_hasFocus = false;
911
926
  Super::onLostFocus(args);
912
927
  if (m_textServices) {
913
928
  LRESULT lresult;
@@ -919,6 +934,7 @@ void WindowsTextInputComponentView::onLostFocus(
919
934
 
920
935
  void WindowsTextInputComponentView::onGotFocus(
921
936
  const winrt::Microsoft::ReactNative::Composition::Input::RoutedEventArgs &args) noexcept {
937
+ m_hasFocus = true;
922
938
  Super::onGotFocus(args);
923
939
  if (m_textServices) {
924
940
  LRESULT lresult;
@@ -1022,6 +1038,10 @@ void WindowsTextInputComponentView::updateProps(
1022
1038
  m_submitKeyEvents.clear();
1023
1039
  }
1024
1040
 
1041
+ if (oldTextInputProps.autoCapitalize != newTextInputProps.autoCapitalize) {
1042
+ autoCapitalizeOnUpdateProps(oldTextInputProps.autoCapitalize, newTextInputProps.autoCapitalize);
1043
+ }
1044
+
1025
1045
  UpdatePropertyBits();
1026
1046
  }
1027
1047
 
@@ -1462,6 +1482,10 @@ WindowsTextInputComponentView::createVisual() noexcept {
1462
1482
  return visual;
1463
1483
  }
1464
1484
 
1485
+ std::pair<facebook::react::Cursor, HCURSOR> WindowsTextInputComponentView::cursor() const noexcept {
1486
+ return {viewProps()->cursor, m_hcursor};
1487
+ }
1488
+
1465
1489
  void WindowsTextInputComponentView::onThemeChanged() noexcept {
1466
1490
  const auto &props = windowsTextInputProps();
1467
1491
  updateCursorColor(props.cursorColor, props.textAttributes.foregroundColor);
@@ -1476,4 +1500,29 @@ winrt::Microsoft::ReactNative::ComponentView WindowsTextInputComponentView::Crea
1476
1500
  return winrt::make<WindowsTextInputComponentView>(compContext, tag, reactContext);
1477
1501
  }
1478
1502
 
1503
+ // This function assumes that previous and new capitalization types are different.
1504
+ void WindowsTextInputComponentView::autoCapitalizeOnUpdateProps(
1505
+ const std::string &previousCapitalizationType,
1506
+ const std::string &newCapitalizationType) noexcept {
1507
+ /*
1508
+ Possible values are:
1509
+ Characters - All characters.
1510
+ Words - First letter of each word.
1511
+ Sentences - First letter of each sentence.
1512
+ None - Do not autocapitalize anything.
1513
+
1514
+ For now, only characters and none are supported.
1515
+ */
1516
+
1517
+ if (previousCapitalizationType == "characters") {
1518
+ winrt::check_hresult(m_textServices->TxSendMessage(
1519
+ EM_SETEDITSTYLE, 0 /* disable */, SES_UPPERCASE /* flag affected */, nullptr /* LRESULT */));
1520
+ }
1521
+
1522
+ if (newCapitalizationType == "characters") {
1523
+ winrt::check_hresult(m_textServices->TxSendMessage(
1524
+ EM_SETEDITSTYLE, SES_UPPERCASE /* enable */, SES_UPPERCASE /* flag affected */, nullptr /* LRESULT */));
1525
+ }
1526
+ }
1527
+
1479
1528
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -78,6 +78,8 @@ struct WindowsTextInputComponentView
78
78
 
79
79
  winrt::Microsoft::ReactNative::Composition::Experimental::IVisual createVisual() noexcept;
80
80
 
81
+ std::pair<facebook::react::Cursor, HCURSOR> cursor() const noexcept override;
82
+
81
83
  private:
82
84
  struct DrawBlock {
83
85
  DrawBlock(WindowsTextInputComponentView &view);
@@ -104,6 +106,10 @@ struct WindowsTextInputComponentView
104
106
  void InternalFinalize() noexcept;
105
107
  void UpdatePropertyBits() noexcept;
106
108
 
109
+ void autoCapitalizeOnUpdateProps(
110
+ const std::string &previousCapitalizationType,
111
+ const std::string &newcapitalizationType) noexcept;
112
+
107
113
  winrt::Windows::UI::Composition::CompositionSurfaceBrush m_brush{nullptr};
108
114
  winrt::Microsoft::ReactNative::Composition::Experimental::ICaretVisual m_caretVisual{nullptr};
109
115
  winrt::Microsoft::ReactNative::Composition::Experimental::IDrawingSurfaceBrush m_drawingSurface{nullptr};
@@ -124,10 +130,12 @@ struct WindowsTextInputComponentView
124
130
  int m_cDrawBlock{0};
125
131
  bool m_needsRedraw{false};
126
132
  bool m_drawing{false};
133
+ bool m_hasFocus{false};
127
134
  bool m_clearTextOnSubmit{false};
128
135
  bool m_multiline{false};
129
136
  DWORD m_propBitsMask{0};
130
137
  DWORD m_propBits{0};
138
+ HCURSOR m_hcursor{nullptr};
131
139
  std::vector<facebook::react::CompWindowsTextInputSubmitKeyEventsStruct> m_submitKeyEvents;
132
140
  };
133
141
 
@@ -330,7 +330,9 @@ bool Theme::TryGetPlatformColor(const std::string &platformColor, winrt::Windows
330
330
  {"AcrylicInAppFillColorDefault", {0x9E, 0xFF, 0xFF, 0xFF}},
331
331
  {"SystemChromeMediumLowColor", {0xFF, 0xF2, 0xF2, 0xF2}},
332
332
  {"SystemControlForegroundBaseHighColor", {0xFF, 0x00, 0x00, 0x00}},
333
- {"SystemControlTransientBorderColor", {0x24, 0x00, 0x00, 0x00}}};
333
+ {"SystemControlTransientBorderColor", {0x24, 0x00, 0x00, 0x00}},
334
+ {"FocusVisualPrimary", {0xFF, 0x00, 0x00, 0x00}},
335
+ {"FocusVisualSecondary", {0x99, 0xFF, 0xFF, 0xFF}}};
334
336
 
335
337
  static std::unordered_map<std::string, winrt::Windows::UI::Color, std::hash<std::string_view>, std::equal_to<>>
336
338
  s_darkColors = {
@@ -362,7 +364,9 @@ bool Theme::TryGetPlatformColor(const std::string &platformColor, winrt::Windows
362
364
  {"AcrylicInAppFillColorDefault", {0x9E, 0x00, 0x00, 0x00}},
363
365
  {"SystemChromeMediumLowColor", {0xFF, 0x2B, 0x2B, 0x2B}},
364
366
  {"SystemControlForegroundBaseHighColor", {0xFF, 0xFF, 0xFF, 0xFF}},
365
- {"SystemControlTransientBorderColor", {0x5C, 0x00, 0x00, 0x00}}};
367
+ {"SystemControlTransientBorderColor", {0x5C, 0x00, 0x00, 0x00}},
368
+ {"FocusVisualPrimary", {0xFF, 0xFF, 0xFF, 0xFF}},
369
+ {"FocusVisualSecondary", {0x99, 0x00, 0x00, 0x00F}}};
366
370
 
367
371
  static std::unordered_map<
368
372
  std::string,
@@ -399,7 +403,9 @@ bool Theme::TryGetPlatformColor(const std::string &platformColor, winrt::Windows
399
403
  {"ControlStrongFillColorDisabled", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonFace, {}}},
400
404
  {"SystemChromeMediumLowColor", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonFace, {}}},
401
405
  {"SystemControlForegroundBaseHighColor", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonText, {}}},
402
- {"SystemControlTransientBorderColor", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonText, {}}}};
406
+ {"SystemControlTransientBorderColor", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonText, {}}},
407
+ {"FocusVisualPrimary", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonText, {}}},
408
+ {"FocusVisualSecondary", {winrt::Windows::UI::ViewManagement::UIElementType::ButtonFace, {}}}};
403
409
 
404
410
  auto alias = s_xamlAliasedColors.find(platformColor);
405
411
  if (alias != s_xamlAliasedColors.end()) {
@@ -214,4 +214,15 @@ ExpandCollapseState GetExpandCollapseState(const bool &expanded) noexcept {
214
214
  }
215
215
  }
216
216
 
217
+ ToggleState GetToggleState(const std::optional<facebook::react::AccessibilityState> &state) noexcept {
218
+ if (state.has_value()) {
219
+ if (state->checked == facebook::react::AccessibilityState::Checked) {
220
+ return ToggleState::ToggleState_On;
221
+ } else if (state->checked == facebook::react::AccessibilityState::Mixed) {
222
+ return ToggleState::ToggleState_Indeterminate;
223
+ }
224
+ }
225
+ return ToggleState::ToggleState_Off;
226
+ }
227
+
217
228
  } // namespace winrt::Microsoft::ReactNative::implementation
@@ -36,4 +36,6 @@ std::string extractAccessibilityValue(const facebook::react::AccessibilityValue
36
36
  void DispatchAccessibilityAction(::Microsoft::ReactNative::ReactTaggedView &view, const std::string &action) noexcept;
37
37
 
38
38
  ExpandCollapseState GetExpandCollapseState(const bool &expanded) noexcept;
39
+
40
+ ToggleState GetToggleState(const std::optional<facebook::react::AccessibilityState> &state) noexcept;
39
41
  } // namespace winrt::Microsoft::ReactNative::implementation
@@ -26,7 +26,7 @@ UnimplementedNativeViewComponentView::UnimplementedNativeViewComponentView(
26
26
  ~(ComponentViewFeatures::Background | ComponentViewFeatures::ShadowProps |
27
27
  ComponentViewFeatures::NativeBorder)) {
28
28
  m_labelVisual = compContext.CreateSpriteVisual();
29
- OuterVisual().InsertAt(m_labelVisual, 1);
29
+ OuterVisual().InsertAt(m_labelVisual, 0);
30
30
  }
31
31
 
32
32
  winrt::Microsoft::ReactNative::ComponentView UnimplementedNativeViewComponentView::Create(
@@ -25,6 +25,29 @@ namespace Microsoft.ReactNative.Composition
25
25
  [webhosthidden]
26
26
  delegate Microsoft.UI.Composition.Visual CreateVisualDelegate(Microsoft.ReactNative.ComponentView view);
27
27
 
28
+ [experimental]
29
+ delegate void UpdateLayoutMetricsDelegate(Microsoft.ReactNative.ComponentView source, Microsoft.ReactNative.LayoutMetrics newLayoutMetrics, Microsoft.ReactNative.LayoutMetrics oldLayoutMetrics);
30
+
31
+ [experimental]
32
+ [webhosthidden]
33
+ delegate Microsoft.UI.Composition.Visual VisualToMountChildrenIntoDelegate(Microsoft.ReactNative.ComponentView view);
34
+
35
+ namespace Experimental {
36
+ [experimental]
37
+ [webhosthidden]
38
+ DOC_STRING("This type will be removed in future versions")
39
+ delegate Microsoft.ReactNative.Composition.Experimental.IVisual IVisualToMountChildrenIntoDelegate(Microsoft.ReactNative.ComponentView view);
40
+
41
+ [experimental]
42
+ [webhosthidden]
43
+ DOC_STRING("This interface is for use when running react-native-windows using a custom compositor. "
44
+ "This interface will be removed in future versions")
45
+ interface IReactCompositionViewComponentInternalBuilder
46
+ {
47
+ void SetIVisualToMountChildrenIntoHandler(IVisualToMountChildrenIntoDelegate impl);
48
+ };
49
+ }
50
+
28
51
  [webhosthidden]
29
52
  [experimental]
30
53
  DOC_STRING(".")
@@ -33,6 +56,9 @@ namespace Microsoft.ReactNative.Composition
33
56
  void SetViewComponentViewInitializer(ViewComponentViewInitializer initializer);
34
57
  void SetContentIslandComponentViewInitializer(ComponentIslandComponentViewInitializer initializer);
35
58
  void SetCreateVisualHandler(CreateVisualDelegate impl);
59
+ void SetViewFeatures(ComponentViewFeatures viewFeatures);
60
+ void SetUpdateLayoutMetricsHandler(UpdateLayoutMetricsDelegate impl);
61
+ void SetVisualToMountChildrenIntoHandler(VisualToMountChildrenIntoDelegate impl);
36
62
  };
37
63
 
38
64
  } // namespace Microsoft.ReactNative
@@ -56,7 +56,7 @@ namespace Microsoft.ReactNative
56
56
 
57
57
  [experimental]
58
58
  DOC_STRING("A delegate that creates a @IComponentProps object for an instance of @ViewProps. See @IReactViewComponentBuilder.SetCreateProps")
59
- delegate IComponentProps ViewPropsFactory(ViewProps props);
59
+ delegate IComponentProps ViewPropsFactory(ViewProps props, IComponentProps cloneFrom);
60
60
 
61
61
  [experimental]
62
62
  delegate Windows.Foundation.Size MeasureContentHandler(ShadowNode shadowNode, LayoutContext layoutContext, LayoutConstraints layoutConstraints);
@@ -1,43 +1,17 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
1
4
  #include "pch.h"
2
5
  #include "ReactNativeAppBuilder.h"
3
6
  #include "ReactNativeAppBuilder.g.cpp"
4
- #include "IReactDispatcher.h"
5
- #include "ReactNativeHost.h"
7
+
6
8
  #include "ReactNativeWin32App.h"
9
+
10
+ #include "winrt/Microsoft.ReactNative.h"
7
11
  #include "winrt/Microsoft.UI.Composition.h"
8
12
  #include "winrt/Microsoft.UI.Dispatching.h"
13
+ #include "winrt/Microsoft.UI.Interop.h"
9
14
  #include "winrt/Microsoft.UI.Windowing.h"
10
- #include "winrt/microsoft.UI.Interop.h"
11
-
12
- // Scaling factor for the window's content based on the DPI of the display where the window is located.
13
- float ScaleFactor(HWND hwnd) noexcept {
14
- return GetDpiForWindow(hwnd) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);
15
- }
16
-
17
- void UpdateRootViewSizeToAppWindow(
18
- winrt::Microsoft::ReactNative::ReactNativeIsland const &rootView,
19
- winrt::Microsoft::UI::Windowing::AppWindow const &window) {
20
- auto hwnd = winrt::Microsoft::UI::GetWindowFromWindowId(window.Id());
21
- auto scaleFactor = ScaleFactor(hwnd);
22
- winrt::Windows::Foundation::Size size{
23
- window.ClientSize().Width / scaleFactor, window.ClientSize().Height / scaleFactor};
24
- // Do not relayout when minimized
25
- if (window.Presenter().as<winrt::Microsoft::UI::Windowing::OverlappedPresenter>().State() !=
26
- winrt::Microsoft::UI::Windowing::OverlappedPresenterState::Minimized) {
27
- winrt::Microsoft::ReactNative::LayoutConstraints constraints;
28
- constraints.LayoutDirection = winrt::Microsoft::ReactNative::LayoutDirection::Undefined;
29
- constraints.MaximumSize = constraints.MinimumSize = size;
30
- rootView.Arrange(constraints, {0, 0});
31
- }
32
- }
33
-
34
- namespace winrt::ReactNative {
35
- using namespace winrt::Microsoft::ReactNative;
36
- }
37
-
38
- namespace winrt::UI {
39
- using namespace winrt::Microsoft::UI;
40
- }
41
15
 
42
16
  namespace winrt::Microsoft::ReactNative::implementation {
43
17
  ReactNativeAppBuilder::ReactNativeAppBuilder() {
@@ -46,133 +20,55 @@ ReactNativeAppBuilder::ReactNativeAppBuilder() {
46
20
 
47
21
  ReactNativeAppBuilder::~ReactNativeAppBuilder() {}
48
22
 
49
- winrt::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::AddPackageProviders(
50
- winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::ReactNative::IReactPackageProvider> const
51
- &packageProviders) {
52
- for (auto const &provider : packageProviders) {
53
- m_reactNativeWin32App.ReactNativeHost().PackageProviders().Append(provider);
54
- }
55
-
56
- return *this;
57
- }
58
-
59
- winrt::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetReactInstanceSettings(
60
- winrt::Microsoft::ReactNative::ReactInstanceSettings const &settings) {
61
- m_reactNativeWin32App.ReactNativeHost().InstanceSettings(settings);
62
-
23
+ winrt::Microsoft::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetDispatcherQueueController(
24
+ winrt::Microsoft::UI::Dispatching::DispatcherQueueController const &dispatcherQueueController) {
25
+ m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->DispatcherQueueController(
26
+ dispatcherQueueController);
63
27
  return *this;
64
28
  }
65
29
 
66
- winrt::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetCompositor(
30
+ winrt::Microsoft::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetCompositor(
67
31
  winrt::Microsoft::UI::Composition::Compositor const &compositor) {
68
32
  m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->Compositor(compositor);
69
33
  return *this;
70
34
  }
71
35
 
72
- winrt::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetAppWindow(
36
+ winrt::Microsoft::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetAppWindow(
73
37
  winrt::Microsoft::UI::Windowing::AppWindow const &appWindow) {
74
38
  m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->AppWindow(appWindow);
75
39
 
76
40
  return *this;
77
41
  }
78
42
 
79
- winrt::Microsoft::ReactNative::ReactNativeAppBuilder ReactNativeAppBuilder::SetReactViewOptions(
80
- winrt::Microsoft::ReactNative::ReactViewOptions const &reactViewOptions) {
81
- m_reactViewOptions = reactViewOptions;
43
+ winrt::Microsoft::ReactNative::ReactNativeWin32App ReactNativeAppBuilder::Build() {
44
+ // Create the DispatcherQueueController if the app developer doesn't provide one
45
+ if (m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->DispatcherQueueController() == nullptr) {
46
+ assert(m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->Compositor() == nullptr);
82
47
 
83
- return *this;
84
- }
85
-
86
- winrt::ReactNative::ReactNativeWin32App ReactNativeAppBuilder::Build() {
87
- if (m_reactNativeWin32App.Compositor() == nullptr) {
88
- // Create a DispatcherQueue for this thread. This is needed for Composition, Content, and
89
- // Input APIs.
48
+ // Create a DispatcherQueue for this thread. This is needed for Composition, Content, and Input APIs.
90
49
  auto dispatcherQueueController =
91
50
  winrt::Microsoft::UI::Dispatching::DispatcherQueueController::CreateOnCurrentThread();
92
51
 
93
- m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->DispatchQueueController(
52
+ m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->DispatcherQueueController(
94
53
  dispatcherQueueController);
54
+ }
95
55
 
96
- // Create the compositor on behalf of the App Developer
56
+ // Create the Compositor if the app developer doesn't provide one
57
+ if (m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->Compositor() == nullptr) {
58
+ // Create the compositor on behalf of the App Developer.
97
59
  auto compositor = winrt::Microsoft::UI::Composition::Compositor();
98
60
  m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->Compositor(compositor);
99
61
  }
100
62
 
101
- // Create the AppWindow if the developer doesn't provide one
63
+ // Create the AppWindow if the app developer doesn't provide one
102
64
  if (m_reactNativeWin32App.AppWindow() == nullptr) {
103
65
  auto appWindow = winrt::Microsoft::UI::Windowing::AppWindow::Create();
104
- appWindow.Title(L"SampleApplication");
66
+ appWindow.Title(L"ReactNativeWin32App");
105
67
  appWindow.Resize({1000, 1000});
106
- appWindow.Show();
107
68
 
108
69
  m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->AppWindow(appWindow);
109
70
  }
110
71
 
111
- // Currently set the property to use current thread dispatcher as a default UI dispatcher.
112
- // TODO: Provision for setting dispatcher based on the thread dispatcherQueueController is created.
113
- m_reactNativeWin32App.ReactNativeHost().InstanceSettings().Properties().Set(
114
- ReactDispatcherHelper::UIDispatcherProperty(), ReactDispatcherHelper::UIThreadDispatcher());
115
-
116
- auto hwnd{winrt::UI::GetWindowFromWindowId(m_reactNativeWin32App.AppWindow().Id())};
117
-
118
- winrt::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
119
- m_reactNativeWin32App.ReactNativeHost().InstanceSettings().Properties(), reinterpret_cast<uint64_t>(hwnd));
120
-
121
- winrt::ReactNative::Composition::CompositionUIService::SetCompositor(
122
- m_reactNativeWin32App.ReactNativeHost().InstanceSettings(), m_reactNativeWin32App.Compositor());
123
-
124
- // Start the react-native instance, which will create a JavaScript runtime and load the applications bundle.
125
- m_reactNativeWin32App.ReactNativeHost().ReloadInstance();
126
-
127
- // Create a RootView which will present a react-native component
128
- auto reactNativeIsland = winrt::Microsoft::ReactNative::ReactNativeIsland(m_reactNativeWin32App.Compositor());
129
- reactNativeIsland.ReactViewHost(winrt::Microsoft::ReactNative::ReactCoreInjection::MakeViewHost(
130
- m_reactNativeWin32App.ReactNativeHost(), m_reactViewOptions));
131
-
132
- m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->ReactNativeIsland(
133
- std::move(reactNativeIsland));
134
-
135
- // Update the size of the RootView when the AppWindow changes size
136
- m_reactNativeWin32App.AppWindow().Changed(
137
- [wkRootView = winrt::make_weak(m_reactNativeWin32App.ReactNativeIsland())](
138
- winrt::Microsoft::UI::Windowing::AppWindow const &window,
139
- winrt::Microsoft::UI::Windowing::AppWindowChangedEventArgs const &args) {
140
- if (args.DidSizeChange() || args.DidVisibilityChange()) {
141
- if (auto rootView = wkRootView.get()) {
142
- UpdateRootViewSizeToAppWindow(rootView, window);
143
- }
144
- }
145
- });
146
-
147
- // Quit application when main window is closed
148
- m_reactNativeWin32App.AppWindow().Destroying([this](
149
- winrt::Microsoft::UI::Windowing::AppWindow const &window,
150
- winrt::Windows::Foundation::IInspectable const & /*args*/) {
151
- // Before we shutdown the application - unload the ReactNativeHost to give the javascript a chance to save any
152
- // state
153
- auto async = m_reactNativeWin32App.ReactNativeHost().UnloadInstance();
154
- async.Completed([this](auto asyncInfo, winrt::Windows::Foundation::AsyncStatus asyncStatus) {
155
- assert(asyncStatus == winrt::Windows::Foundation::AsyncStatus::Completed);
156
- m_reactNativeWin32App.ReactNativeHost().InstanceSettings().UIDispatcher().Post([]() { PostQuitMessage(0); });
157
- });
158
- });
159
-
160
- // DesktopChildSiteBridge create a ContentSite that can host the RootView ContentIsland
161
- auto desktopChildSiteBridge = winrt::Microsoft::UI::Content::DesktopChildSiteBridge::Create(
162
- m_reactNativeWin32App.Compositor(), m_reactNativeWin32App.AppWindow().Id());
163
-
164
- desktopChildSiteBridge.Connect(m_reactNativeWin32App.ReactNativeIsland().Island());
165
-
166
- desktopChildSiteBridge.ResizePolicy(winrt::Microsoft::UI::Content::ContentSizePolicy::ResizeContentToParentWindow);
167
-
168
- auto scaleFactor = ScaleFactor(hwnd);
169
- m_reactNativeWin32App.ReactNativeIsland().ScaleFactor(scaleFactor);
170
-
171
- UpdateRootViewSizeToAppWindow(reactNativeIsland, m_reactNativeWin32App.AppWindow());
172
-
173
- m_reactNativeWin32App.as<implementation::ReactNativeWin32App>().get()->DesktopChildSiteBridge(
174
- std::move(desktopChildSiteBridge));
175
-
176
72
  return m_reactNativeWin32App;
177
73
  }
178
74
 
@@ -1,6 +1,8 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
1
3
  #pragma once
4
+
2
5
  #include "ReactNativeAppBuilder.g.h"
3
- #include <winrt/Microsoft.UI.Content.h>
4
6
 
5
7
  namespace winrt::Microsoft::ReactNative::implementation {
6
8
  struct ReactNativeAppBuilder : ReactNativeAppBuilderT<ReactNativeAppBuilder> {
@@ -8,25 +10,15 @@ struct ReactNativeAppBuilder : ReactNativeAppBuilderT<ReactNativeAppBuilder> {
8
10
 
9
11
  ~ReactNativeAppBuilder();
10
12
 
11
- winrt::Microsoft::ReactNative::ReactNativeAppBuilder AddPackageProviders(
12
- winrt::Windows::Foundation::Collections::IVector<winrt::Microsoft::ReactNative::IReactPackageProvider> const
13
- &packageProviders);
14
- winrt::Microsoft::ReactNative::ReactNativeAppBuilder SetReactInstanceSettings(
15
- winrt::Microsoft::ReactNative::ReactInstanceSettings const &settings);
16
-
17
- // TODO: Currently, SetCompositor API is not exposed to the developer.
18
- // Compositor depends on the DispatcherQueue created by DispatcherQueueController on a current thread
19
- // or dedicated thread. So we also have to make a provision for setting DispatcherQueueController.
13
+ winrt::Microsoft::ReactNative::ReactNativeAppBuilder SetDispatcherQueueController(
14
+ winrt::Microsoft::UI::Dispatching::DispatcherQueueController const &dispatcherQueueController);
20
15
  winrt::Microsoft::ReactNative::ReactNativeAppBuilder SetCompositor(
21
16
  winrt::Microsoft::UI::Composition::Compositor const &compositor);
22
17
  winrt::Microsoft::ReactNative::ReactNativeAppBuilder SetAppWindow(
23
18
  winrt::Microsoft::UI::Windowing::AppWindow const &appWindow);
24
- winrt::Microsoft::ReactNative::ReactNativeAppBuilder SetReactViewOptions(
25
- winrt::Microsoft::ReactNative::ReactViewOptions const &reactViewOptions);
26
19
  winrt::Microsoft::ReactNative::ReactNativeWin32App Build();
27
20
 
28
21
  private:
29
- winrt::Microsoft::ReactNative::ReactViewOptions m_reactViewOptions{};
30
22
  winrt::Microsoft::ReactNative::ReactNativeWin32App m_reactNativeWin32App{nullptr};
31
23
  };
32
24
  } // namespace winrt::Microsoft::ReactNative::implementation
@@ -9,60 +9,39 @@ import "IReactPackageProvider.idl";
9
9
  namespace Microsoft.ReactNative {
10
10
 
11
11
  [experimental]
12
- DOC_STRING("ReactNativeWin32App is used to manage resources appropriately to be able to host ReactNative component in a contentIsland.")
12
+ DOC_STRING("ReactNativeWin32App sets up the infrastructure for the default experience of a ReactNative application filling a WinAppSDK window.")
13
13
  runtimeclass ReactNativeWin32App {
14
14
  // Properties
15
15
  Microsoft.UI.Windowing.AppWindow AppWindow {get;};
16
16
 
17
- Microsoft.UI.Composition.Compositor Compositor {get;};
18
-
19
- Microsoft.UI.Content.DesktopChildSiteBridge DesktopChildSiteBridge {get;};
20
-
21
17
  ReactNativeHost ReactNativeHost {get;};
22
18
 
23
- ReactNativeIsland ReactNativeIsland {get;};
19
+ ReactViewOptions ReactViewOptions {get;};
20
+
21
+ // TODO: Hide these APIs for now until we're sure we need to expose them and can do so safely
22
+ // Microsoft.UI.Composition.Compositor Compositor {get;};
23
+ // Microsoft.UI.Content.DesktopChildSiteBridge DesktopChildSiteBridge {get;};
24
+ // Microsoft.UI.Dispatching DispatcherQueueController {get;};
25
+ // ReactNativeIsland ReactNativeIsland {get;};
24
26
 
25
27
  // Methods
26
28
  void Start();
27
29
  }
28
30
 
29
31
  [experimental]
30
- DOC_STRING("This is the builder for creating ReactInstanceSettings.")
31
- runtimeclass ReactInstanceSettingsBuilder
32
- {
33
- ReactInstanceSettingsBuilder();
34
-
35
- // Properties
36
- ReactInstanceSettings ReactInstanceSettings {get;};
37
-
38
- // Methods
39
- ReactInstanceSettingsBuilder UseDirectDebugger(Boolean state);
40
-
41
- ReactInstanceSettingsBuilder UseDeveloperSupport(Boolean state);
42
-
43
- ReactInstanceSettingsBuilder BundleRootPath(String path);
44
-
45
- ReactInstanceSettingsBuilder DebugBundlePath(String path);
46
-
47
- ReactInstanceSettingsBuilder JavaScriptBundleFile(String file);
48
-
49
- ReactInstanceSettingsBuilder UseFastRefresh(Boolean state);
50
- }
51
-
52
- [experimental]
53
- DOC_STRING("ReactNativeAppBuilder initializes all the required infrastructure for a Win32 Fabric Application.")
32
+ DOC_STRING("ReactNativeAppBuilder builds a ReactNativeWin32App with the base WinAppSDK infrastructure.")
54
33
  runtimeclass ReactNativeAppBuilder
55
34
  {
56
35
  ReactNativeAppBuilder();
57
36
 
58
37
  // Methods
59
- ReactNativeAppBuilder AddPackageProviders(Windows.Foundation.Collections.IVector<Microsoft.ReactNative.IReactPackageProvider> packageProviders);
60
-
61
- ReactNativeAppBuilder SetReactInstanceSettings(ReactInstanceSettings settings);
62
38
 
63
39
  ReactNativeAppBuilder SetAppWindow(Microsoft.UI.Windowing.AppWindow appWindow);
64
40
 
65
- ReactNativeAppBuilder SetReactViewOptions(Microsoft.ReactNative.ReactViewOptions reactViewOptions);
41
+ // TODO: Hide these APIs for now until we're sure we need to expose them and can do so safely
42
+ // Compositor depends on the DispatcherQueue created by DispatcherQueueController
43
+ // ReactNativeAppBuilder SetCompositor(Microsoft.UI.Composition.Compositor compositor);
44
+ // ReactNativeAppBuilder SetDispatcherQueueController(Microsoft.UI.Dispatching DispatcherQueueController);
66
45
 
67
46
  ReactNativeWin32App Build();
68
47
  }
@@ -78,11 +78,12 @@ namespace Microsoft.ReactNative
78
78
  DOC_STRING("A windows composition component that hosts React Native UI elements.")
79
79
  runtimeclass ReactNativeIsland
80
80
  {
81
- DOC_STRING("Creates a new instance of @ReactNativeIsland.")
81
+ DOC_STRING("Creates a new instance of @ReactNativeIsland. Can be implemented with a ReactViewHost or a ComponentView with reactContext")
82
82
  ReactNativeIsland();
83
83
 
84
84
  #ifdef USE_WINUI3
85
85
  ReactNativeIsland(Microsoft.UI.Composition.Compositor compositor);
86
+ ReactNativeIsland(Microsoft.UI.Composition.Compositor compositor, Microsoft.ReactNative.IReactContext context, Microsoft.ReactNative.ComponentView componentView);
86
87
  #endif
87
88
 
88
89
  DOC_STRING(
@@ -97,7 +98,7 @@ namespace Microsoft.ReactNative
97
98
 
98
99
  DOC_STRING("ScaleFactor for this windows (DPI/96)")
99
100
  Single ScaleFactor {get; set;};
100
-
101
+
101
102
  Single FontSizeMultiplier { get; };
102
103
 
103
104
  DOC_STRING("Move focus to this @ReactNativeIsland")