react-native-windows 0.74.6 → 0.74.7

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.
@@ -5,6 +5,7 @@ import "IJSValueWriter.idl";
5
5
  import "ReactCoreInjection.idl";
6
6
  import "ReactNativeHost.idl";
7
7
  import "Theme.idl";
8
+ import "IReactViewComponentBuilder.idl";
8
9
  #include "NamespaceRedirect.h"
9
10
  #include "DocString.h"
10
11
 
@@ -61,6 +62,13 @@ namespace Microsoft.ReactNative
61
62
  }
62
63
  }
63
64
 
65
+ [default_interface]
66
+ [webhosthidden]
67
+ [experimental]
68
+ runtimeclass RootViewSizeChangedEventArgs {
69
+ Windows.Foundation.Size Size { get; };
70
+ }
71
+
64
72
  [default_interface]
65
73
  [webhosthidden]
66
74
  [experimental]
@@ -82,7 +90,7 @@ namespace Microsoft.ReactNative
82
90
  DOC_STRING("The RootVisual associated with the @CompositionRootView. It must be set to show any React UI elements.")
83
91
  Microsoft.UI.Composition.Visual RootVisual { get; };
84
92
 
85
- Windows.Foundation.Size Size {get; set; };
93
+ Windows.Foundation.Size Size { get; };
86
94
 
87
95
  DOC_STRING("ScaleFactor for this windows (DPI/96)")
88
96
  Single ScaleFactor {get; set;};
@@ -90,8 +98,8 @@ namespace Microsoft.ReactNative
90
98
  DOC_STRING("Move focus to this @CompositionRootView")
91
99
  FocusNavigationResult NavigateFocus(FocusNavigationRequest request);
92
100
 
93
- Windows.Foundation.Size Measure(Windows.Foundation.Size availableSize);
94
- Windows.Foundation.Size Arrange(Windows.Foundation.Size availableSize);
101
+ Windows.Foundation.Size Measure(LayoutConstraints layoutConstraints, Windows.Foundation.Point viewportOffset);
102
+ void Arrange(LayoutConstraints layoutConstraints, Windows.Foundation.Point viewportOffset);
95
103
 
96
104
  Object GetUiaProvider();
97
105
 
@@ -104,6 +112,8 @@ namespace Microsoft.ReactNative
104
112
  #ifdef USE_WINUI3
105
113
  Microsoft.UI.Content.ContentIsland Island { get; };
106
114
  #endif
115
+
116
+ event Windows.Foundation.EventHandler<RootViewSizeChangedEventArgs> SizeChanged;
107
117
  }
108
118
 
109
119
  } // namespace Microsoft.ReactNative
@@ -243,7 +243,7 @@ CompositionEventHandler::CompositionEventHandler(
243
243
  : static_cast<facebook::react::Tag>(
244
244
  winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
245
245
  strongRootView)
246
- ->GetTag()),
246
+ ->RootTag()),
247
247
  args);
248
248
  auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
249
249
  onKeyDown(keyboardSource, keyArgs);
@@ -266,7 +266,7 @@ CompositionEventHandler::CompositionEventHandler(
266
266
  : static_cast<facebook::react::Tag>(
267
267
  winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
268
268
  strongRootView)
269
- ->GetTag()),
269
+ ->RootTag()),
270
270
  args);
271
271
  auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
272
272
  onKeyUp(keyboardSource, keyArgs);
@@ -290,7 +290,7 @@ CompositionEventHandler::CompositionEventHandler(
290
290
  : static_cast<facebook::react::Tag>(
291
291
  winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
292
292
  strongRootView)
293
- ->GetTag()),
293
+ ->RootTag()),
294
294
  args);
295
295
  auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
296
296
  onCharacterReceived(keyboardSource, charArgs);
@@ -323,7 +323,7 @@ CompositionEventHandler::~CompositionEventHandler() {
323
323
  facebook::react::SurfaceId CompositionEventHandler::SurfaceId() const noexcept {
324
324
  if (auto strongRootView = m_wkRootView.get()) {
325
325
  return static_cast<facebook::react::SurfaceId>(
326
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(strongRootView)->GetTag());
326
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(strongRootView)->RootTag());
327
327
  }
328
328
  return -1;
329
329
  }
@@ -460,7 +460,7 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
460
460
  : static_cast<facebook::react::Tag>(
461
461
  winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
462
462
  strongRootView)
463
- ->GetTag()),
463
+ ->RootTag()),
464
464
  msg,
465
465
  wParam,
466
466
  lParam);
@@ -481,7 +481,7 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
481
481
  : static_cast<facebook::react::Tag>(
482
482
  winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
483
483
  strongRootView)
484
- ->GetTag()),
484
+ ->RootTag()),
485
485
  msg,
486
486
  wParam,
487
487
  lParam);
@@ -101,8 +101,9 @@ void CompositionHwndHost::UpdateSize() noexcept {
101
101
  static_cast<float>(m_width / ScaleFactor()), static_cast<float>(m_height / ScaleFactor())};
102
102
  // Do not relayout when minimized
103
103
  if (!IsIconic(m_hwnd)) {
104
- m_compRootView.Size(size);
105
- m_compRootView.Arrange(size);
104
+ winrt::Microsoft::ReactNative::LayoutConstraints constraints;
105
+ constraints.MinimumSize = constraints.MaximumSize = size;
106
+ m_compRootView.Arrange(constraints, {0, 0});
106
107
  }
107
108
  }
108
109
  }
@@ -4,6 +4,7 @@
4
4
  #include "CompositionRootView.h"
5
5
  #include "CompositionRootView.g.cpp"
6
6
  #include "FocusNavigationRequest.g.cpp"
7
+ #include <RootViewSizeChangedEventArgs.g.h>
7
8
 
8
9
  #include <AutoDraw.h>
9
10
  #include <DynamicWriter.h>
@@ -330,26 +331,6 @@ winrt::IInspectable CompositionRootView::GetUiaProvider() noexcept {
330
331
  return m_uiaProvider;
331
332
  }
332
333
 
333
- std::string CompositionRootView::JSComponentName() const noexcept {
334
- return to_string(m_reactViewOptions.ComponentName());
335
- }
336
-
337
- int64_t CompositionRootView::GetActualHeight() const noexcept {
338
- return static_cast<int64_t>(m_size.Height);
339
- }
340
-
341
- int64_t CompositionRootView::GetActualWidth() const noexcept {
342
- return static_cast<int64_t>(m_size.Width);
343
- }
344
-
345
- int64_t CompositionRootView::GetTag() const noexcept {
346
- return m_rootTag;
347
- }
348
-
349
- void CompositionRootView::SetTag(int64_t tag) noexcept {
350
- m_rootTag = tag;
351
- }
352
-
353
334
  void CompositionRootView::SetWindow(uint64_t hwnd) noexcept {
354
335
  m_hwnd = reinterpret_cast<HWND>(hwnd);
355
336
  }
@@ -445,7 +426,7 @@ void CompositionRootView::UninitRootView() noexcept {
445
426
 
446
427
  auto uiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties(
447
428
  winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties()));
448
- uiManager->stopSurface(static_cast<facebook::react::SurfaceId>(GetTag()));
429
+ uiManager->stopSurface(static_cast<facebook::react::SurfaceId>(RootTag()));
449
430
 
450
431
  // This is needed to ensure that the unmount JS logic is completed before the the instance is shutdown during
451
432
  // instance destruction. Aligns with similar code in ReactInstanceWin::DetachRootView for paper Future: Instead this
@@ -484,19 +465,82 @@ void CompositionRootView::ShowInstanceLoaded() noexcept {
484
465
  auto uiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties(
485
466
  winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties()));
486
467
 
487
- auto rootTag = ::Microsoft::ReactNative::getNextRootViewTag();
488
- SetTag(rootTag);
468
+ m_rootTag = ::Microsoft::ReactNative::getNextRootViewTag();
489
469
  auto initProps = DynamicWriter::ToDynamic(Mso::Copy(m_reactViewOptions.InitialProps()));
490
470
  if (initProps.isNull()) {
491
471
  initProps = folly::dynamic::object();
492
472
  }
493
473
  initProps["concurrentRoot"] = true;
494
- uiManager->startSurface(*this, rootTag, JSComponentName(), initProps);
474
+ uiManager->startSurface(
475
+ *this,
476
+ static_cast<facebook::react::SurfaceId>(m_rootTag),
477
+ m_layoutConstraints,
478
+ to_string(m_reactViewOptions.ComponentName()),
479
+ initProps);
495
480
 
496
481
  m_isJSViewAttached = true;
497
482
  }
498
483
  }
499
484
 
485
+ facebook::react::AttributedStringBox CreateLoadingAttributedString() noexcept {
486
+ auto attributedString = facebook::react::AttributedString{};
487
+ auto fragment = facebook::react::AttributedString::Fragment{};
488
+ fragment.string = "Loading";
489
+ fragment.textAttributes.fontSize = loadingBarFontSize;
490
+ attributedString.appendFragment(fragment);
491
+ return facebook::react::AttributedStringBox{attributedString};
492
+ }
493
+
494
+ facebook::react::Size MeasureLoading(const facebook::react::LayoutConstraints &layoutConstraints, float scaleFactor) {
495
+ auto attributedStringBox = CreateLoadingAttributedString();
496
+ winrt::com_ptr<::IDWriteTextLayout> textLayout;
497
+ facebook::react::TextLayoutManager::GetTextLayout(
498
+ attributedStringBox, {} /*paragraphAttributes*/, layoutConstraints, textLayout);
499
+
500
+ DWRITE_TEXT_METRICS tm;
501
+ textLayout->GetMetrics(&tm);
502
+
503
+ return layoutConstraints.clamp(
504
+ {loadingActivityHorizontalOffset * scaleFactor + tm.width, loadingBarHeight * scaleFactor});
505
+ }
506
+
507
+ winrt::event_token CompositionRootView::SizeChanged(
508
+ winrt::Windows::Foundation::EventHandler<winrt::Microsoft::ReactNative::RootViewSizeChangedEventArgs> const
509
+ &handler) noexcept {
510
+ return m_sizeChangedEvent.add(handler);
511
+ }
512
+
513
+ void CompositionRootView::SizeChanged(winrt::event_token const &token) noexcept {
514
+ m_sizeChangedEvent.remove(token);
515
+ }
516
+
517
+ struct RootViewSizeChangedEventArgs : RootViewSizeChangedEventArgsT<RootViewSizeChangedEventArgs> {
518
+ RootViewSizeChangedEventArgs(winrt::Windows::Foundation::Size size) : m_size(size) {}
519
+ winrt::Windows::Foundation::Size Size() const noexcept {
520
+ return m_size;
521
+ }
522
+
523
+ private:
524
+ const winrt::Windows::Foundation::Size m_size;
525
+ };
526
+
527
+ void CompositionRootView::NotifySizeChanged() noexcept {
528
+ auto oldSize = m_size;
529
+ facebook::react::Size size;
530
+ auto rootComponentView = GetComponentView();
531
+ if (rootComponentView) {
532
+ size = rootComponentView->layoutMetrics().frame.size;
533
+ } else if (m_loadingVisual) {
534
+ size = MeasureLoading(m_layoutConstraints, m_scaleFactor);
535
+ }
536
+
537
+ m_size = {size.width, size.height};
538
+ UpdateRootVisualSize();
539
+ if (oldSize != m_size) {
540
+ m_sizeChangedEvent(*this, winrt::make<RootViewSizeChangedEventArgs>(m_size));
541
+ }
542
+ }
543
+
500
544
  void CompositionRootView::ShowInstanceError() noexcept {
501
545
  ClearLoadingUI();
502
546
  }
@@ -506,6 +550,9 @@ Composition::Experimental::IDrawingSurfaceBrush CompositionRootView::CreateLoadi
506
550
  winrt::Microsoft::ReactNative::Composition::implementation::CompositionUIService::GetCompositionContext(
507
551
  m_context.Properties().Handle());
508
552
 
553
+ if (m_size.Height == 0 || m_size.Width == 0)
554
+ return nullptr;
555
+
509
556
  winrt::Windows::Foundation::Size surfaceSize = {
510
557
  m_size.Width * m_scaleFactor, std::min(m_size.Height, loadingBarHeight) * m_scaleFactor};
511
558
  auto drawingSurface = compContext.CreateDrawingSurfaceBrush(
@@ -523,12 +570,7 @@ Composition::Experimental::IDrawingSurfaceBrush CompositionRootView::CreateLoadi
523
570
  constraints.maximumSize.width = std::max(0.0f, m_size.Width - loadingTextHorizontalOffset);
524
571
  constraints.maximumSize.height = std::max(0.0f, m_size.Height - loadingBarHeight);
525
572
 
526
- auto attributedString = facebook::react::AttributedString{};
527
- auto fragment = facebook::react::AttributedString::Fragment{};
528
- fragment.string = "Loading";
529
- fragment.textAttributes.fontSize = loadingBarFontSize;
530
- attributedString.appendFragment(fragment);
531
- auto attributedStringBox = facebook::react::AttributedStringBox{attributedString};
573
+ auto attributedStringBox = CreateLoadingAttributedString();
532
574
 
533
575
  auto textAttributes = facebook::react::TextAttributes{};
534
576
  textAttributes.foregroundColor = facebook::react::whiteColor();
@@ -569,10 +611,7 @@ void CompositionRootView::ShowInstanceLoading() noexcept {
569
611
  winrt::Microsoft::ReactNative::Composition::implementation::CompositionUIService::GetCompositionContext(
570
612
  m_context.Properties().Handle());
571
613
 
572
- auto drawingSurface = CreateLoadingVisualBrush();
573
-
574
614
  m_loadingVisual = compContext.CreateSpriteVisual();
575
- m_loadingVisual.Brush(drawingSurface);
576
615
 
577
616
  auto foregroundBrush = compContext.CreateColorBrush({255, 255, 255, 255});
578
617
 
@@ -580,14 +619,28 @@ void CompositionRootView::ShowInstanceLoading() noexcept {
580
619
  m_loadingActivityVisual.Brush(foregroundBrush);
581
620
  m_loadingVisual.InsertAt(m_loadingActivityVisual, 0);
582
621
 
622
+ NotifySizeChanged();
583
623
  UpdateLoadingVisualSize();
584
624
 
585
625
  InternalRootVisual().InsertAt(m_loadingVisual, m_hasRenderedVisual ? 1 : 0);
586
626
  }
587
627
 
628
+ void ApplyConstraints(
629
+ const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraintsIn,
630
+ facebook::react::LayoutConstraints &layoutConstraintsOut) noexcept {
631
+ layoutConstraintsOut.minimumSize = {layoutConstraintsIn.MinimumSize.Width, layoutConstraintsIn.MinimumSize.Height};
632
+ layoutConstraintsOut.maximumSize = {layoutConstraintsIn.MaximumSize.Width, layoutConstraintsIn.MaximumSize.Height};
633
+ layoutConstraintsOut.layoutDirection =
634
+ static_cast<facebook::react::LayoutDirection>(layoutConstraintsIn.LayoutDirection);
635
+ }
636
+
588
637
  winrt::Windows::Foundation::Size CompositionRootView::Measure(
589
- winrt::Windows::Foundation::Size const &availableSize) const {
590
- winrt::Windows::Foundation::Size size{0.0f, 0.0f};
638
+ const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraints,
639
+ const winrt::Windows::Foundation::Point &viewportOffset) const noexcept {
640
+ facebook::react::Size size{0, 0};
641
+
642
+ facebook::react::LayoutConstraints constraints;
643
+ ApplyConstraints(layoutConstraints, constraints);
591
644
 
592
645
  if (m_isInitialized && m_rootTag != -1) {
593
646
  if (auto fabricuiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties(
@@ -596,55 +649,39 @@ winrt::Windows::Foundation::Size CompositionRootView::Measure(
596
649
  // TODO scaling factor
597
650
  context.pointScaleFactor = static_cast<facebook::react::Float>(m_scaleFactor);
598
651
  context.fontSizeMultiplier = static_cast<facebook::react::Float>(m_scaleFactor);
652
+ context.viewportOffset = {viewportOffset.X, viewportOffset.Y};
599
653
 
600
- facebook::react::LayoutConstraints constraints;
601
- // TODO should support MinHeight/MinWidth
602
- constraints.minimumSize.height = static_cast<facebook::react::Float>(0.0f);
603
- constraints.minimumSize.width = static_cast<facebook::react::Float>(0.0f);
604
-
605
- // TODO should support MaxHeight/MaxWidth props?
606
- constraints.minimumSize.height = constraints.maximumSize.height =
607
- static_cast<facebook::react::Float>(availableSize.Height);
608
- constraints.minimumSize.width = constraints.maximumSize.width =
609
- static_cast<facebook::react::Float>(availableSize.Width);
610
- // TODO get RTL
611
- constraints.layoutDirection = facebook::react::LayoutDirection::LeftToRight;
612
-
613
- auto yogaSize =
614
- fabricuiManager->measureSurface(static_cast<facebook::react::SurfaceId>(m_rootTag), constraints, context);
615
- return {std::min(yogaSize.width, availableSize.Width), std::min(yogaSize.height, availableSize.Height)};
654
+ size = fabricuiManager->measureSurface(static_cast<facebook::react::SurfaceId>(m_rootTag), constraints, context);
616
655
  }
656
+ } else if (m_loadingVisual) {
657
+ size = MeasureLoading(constraints, m_scaleFactor);
617
658
  }
618
659
 
619
- return size;
660
+ auto clampedSize = constraints.clamp(size);
661
+ return {clampedSize.width, clampedSize.height};
620
662
  }
621
663
 
622
- winrt::Windows::Foundation::Size CompositionRootView::Arrange(winrt::Windows::Foundation::Size finalSize) const {
664
+ void CompositionRootView::Arrange(
665
+ const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraints,
666
+ const winrt::Windows::Foundation::Point &viewportOffset) noexcept {
667
+ ApplyConstraints(layoutConstraints, m_layoutConstraints);
668
+
623
669
  if (m_isInitialized && m_rootTag != -1) {
624
670
  if (auto fabricuiManager = ::Microsoft::ReactNative::FabricUIManager::FromProperties(
625
671
  winrt::Microsoft::ReactNative::ReactPropertyBag(m_context.Properties()))) {
626
672
  facebook::react::LayoutContext context;
627
673
  context.pointScaleFactor = static_cast<facebook::react::Float>(m_scaleFactor);
628
674
  context.fontSizeMultiplier = static_cast<facebook::react::Float>(m_scaleFactor);
629
-
630
- facebook::react::LayoutConstraints constraints;
631
- // TODO should support MinHeight/MinWidth
632
- constraints.minimumSize.height = static_cast<facebook::react::Float>(0.0f);
633
- constraints.minimumSize.width = static_cast<facebook::react::Float>(0.0f);
634
-
635
- // TODO should support MaxHeight/MaxWidth props?
636
- constraints.minimumSize.height = constraints.maximumSize.height =
637
- static_cast<facebook::react::Float>(finalSize.Height);
638
- constraints.minimumSize.width = constraints.maximumSize.width =
639
- static_cast<facebook::react::Float>(finalSize.Width);
640
- // TODO get RTL
641
- constraints.layoutDirection = facebook::react::LayoutDirection::LeftToRight;
675
+ context.viewportOffset = {viewportOffset.X, viewportOffset.Y};
642
676
 
643
677
  fabricuiManager->constraintSurfaceLayout(
644
- static_cast<facebook::react::SurfaceId>(m_rootTag), constraints, context);
678
+ static_cast<facebook::react::SurfaceId>(m_rootTag), m_layoutConstraints, context);
645
679
  }
680
+ } else if (m_loadingVisual) {
681
+ // TODO: Resize to align loading
682
+ auto s = m_layoutConstraints.clamp(MeasureLoading(m_layoutConstraints, m_scaleFactor));
683
+ NotifySizeChanged();
646
684
  }
647
- return finalSize;
648
685
  }
649
686
 
650
687
  #ifdef USE_WINUI3
@@ -7,11 +7,11 @@
7
7
  #include <FocusNavigationResult.g.h>
8
8
 
9
9
  #include <ReactContext.h>
10
+ #include <react/renderer/core/LayoutConstraints.h>
10
11
  #include <winrt/Microsoft.ReactNative.Composition.Experimental.h>
11
12
  #include <winrt/Microsoft.ReactNative.h>
12
13
  #include "CompositionEventHandler.h"
13
14
  #include "ReactHost/React.h"
14
- #include "Views/ICompositionRootView.h"
15
15
 
16
16
  namespace winrt::Microsoft::ReactNative::implementation {
17
17
 
@@ -42,8 +42,7 @@ struct FocusNavigationResult : FocusNavigationResultT<FocusNavigationResult> {
42
42
  };
43
43
 
44
44
  struct CompositionRootView
45
- : CompositionRootViewT<CompositionRootView, Composition::Experimental::IInternalCompositionRootView>,
46
- ::Microsoft::ReactNative::ICompositionRootView {
45
+ : CompositionRootViewT<CompositionRootView, Composition::Experimental::IInternalCompositionRootView> {
47
46
  CompositionRootView() noexcept;
48
47
  ~CompositionRootView() noexcept;
49
48
 
@@ -70,6 +69,12 @@ struct CompositionRootView
70
69
  float ScaleFactor() noexcept;
71
70
  void ScaleFactor(float value) noexcept;
72
71
 
72
+ winrt::event_token SizeChanged(
73
+ winrt::Windows::Foundation::EventHandler<winrt::Microsoft::ReactNative::RootViewSizeChangedEventArgs> const
74
+ &handler) noexcept;
75
+ void SizeChanged(winrt::event_token const &token) noexcept;
76
+ void NotifySizeChanged() noexcept;
77
+
73
78
  void AddRenderedVisual(const winrt::Microsoft::ReactNative::Composition::Experimental::IVisual &visual) noexcept;
74
79
  void RemoveRenderedVisual(const winrt::Microsoft::ReactNative::Composition::Experimental::IVisual &visual) noexcept;
75
80
  bool TrySetFocus() noexcept;
@@ -80,8 +85,12 @@ struct CompositionRootView
80
85
  winrt::Microsoft::ReactNative::Composition::Theme Theme() noexcept;
81
86
  void Theme(const winrt::Microsoft::ReactNative::Composition::Theme &value) noexcept;
82
87
 
83
- winrt::Windows::Foundation::Size Measure(winrt::Windows::Foundation::Size const &availableSize) const;
84
- winrt::Windows::Foundation::Size Arrange(winrt::Windows::Foundation::Size finalSize) const;
88
+ winrt::Windows::Foundation::Size Measure(
89
+ const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraints,
90
+ const winrt::Windows::Foundation::Point &viewportOffset) const noexcept;
91
+ void Arrange(
92
+ const winrt::Microsoft::ReactNative::LayoutConstraints &layoutConstraints,
93
+ const winrt::Windows::Foundation::Point &viewportOffset) noexcept;
85
94
 
86
95
  winrt::Microsoft::ReactNative::FocusNavigationResult NavigateFocus(
87
96
  const winrt::Microsoft::ReactNative::FocusNavigationRequest &request) noexcept;
@@ -103,13 +112,6 @@ struct CompositionRootView
103
112
  const winrt::Microsoft::ReactNative::Composition::Input::Pointer &pointer,
104
113
  facebook::react::Tag tag) noexcept;
105
114
 
106
- public: // IReactRootView
107
- std::string JSComponentName() const noexcept override;
108
- int64_t GetActualHeight() const noexcept override;
109
- int64_t GetActualWidth() const noexcept override;
110
- int64_t GetTag() const noexcept override;
111
- void SetTag(int64_t tag) noexcept override;
112
-
113
115
  public: // IReactViewInstance UI-thread implementation
114
116
  void InitRootView(
115
117
  winrt::Microsoft::ReactNative::IReactContext &&context,
@@ -134,7 +136,7 @@ struct CompositionRootView
134
136
  winrt::IInspectable m_uiaProvider{nullptr};
135
137
  int64_t m_rootTag{-1};
136
138
  float m_scaleFactor{1.0};
137
- winrt::Windows::Foundation::Size m_size;
139
+ winrt::Windows::Foundation::Size m_size{0, 0};
138
140
  winrt::Microsoft::ReactNative::ReactContext m_context;
139
141
  winrt::Microsoft::ReactNative::IReactViewHost m_reactViewHost;
140
142
  winrt::Microsoft::ReactNative::ReactViewOptions m_reactViewOptions;
@@ -145,6 +147,9 @@ struct CompositionRootView
145
147
  winrt::Microsoft::ReactNative::Composition::ICustomResourceLoader m_resources{nullptr};
146
148
  winrt::Microsoft::ReactNative::Composition::Theme m_theme{nullptr};
147
149
  winrt::Microsoft::ReactNative::Composition::Theme::ThemeChanged_revoker m_themeChangedRevoker;
150
+ facebook::react::LayoutConstraints m_layoutConstraints;
151
+ winrt::event<winrt::Windows::Foundation::EventHandler<winrt::Microsoft::ReactNative::RootViewSizeChangedEventArgs>>
152
+ m_sizeChangedEvent;
148
153
 
149
154
  void UpdateRootViewInternal() noexcept;
150
155
  void ClearLoadingUI() noexcept;
@@ -175,6 +175,10 @@ void ComponentView::updateLayoutMetrics(
175
175
  base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
176
176
  }
177
177
 
178
+ const facebook::react::LayoutMetrics &ComponentView::layoutMetrics() const noexcept {
179
+ return m_layoutMetrics;
180
+ }
181
+
178
182
  void ComponentView::FinalizeUpdates(winrt::Microsoft::ReactNative::ComponentViewUpdateMask updateMask) noexcept {
179
183
  if ((m_flags & ComponentViewFeatures::NativeBorder) == ComponentViewFeatures::NativeBorder) {
180
184
  finalizeBorderUpdates(m_layoutMetrics, *viewProps());
@@ -120,6 +120,8 @@ struct ComponentView
120
120
  bool getAcccessiblityIsReadOnly() noexcept override;
121
121
  virtual winrt::Microsoft::ReactNative::implementation::ClipState getClipState() noexcept;
122
122
 
123
+ const facebook::react::LayoutMetrics &layoutMetrics() const noexcept;
124
+
123
125
  virtual std::string DefaultControlType() const noexcept;
124
126
  virtual std::string DefaultAccessibleName() const noexcept;
125
127
  virtual std::string DefaultHelpText() const noexcept;
@@ -45,6 +45,20 @@ RootComponentView *RootComponentView::rootComponentView() noexcept {
45
45
  return this;
46
46
  }
47
47
 
48
+ void RootComponentView::updateLayoutMetrics(
49
+ facebook::react::LayoutMetrics const &layoutMetrics,
50
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept {
51
+ base_type::updateLayoutMetrics(layoutMetrics, oldLayoutMetrics);
52
+
53
+ if (oldLayoutMetrics.frame != layoutMetrics.frame ||
54
+ oldLayoutMetrics.pointScaleFactor != layoutMetrics.pointScaleFactor) {
55
+ if (auto rootView = m_wkRootView.get()) {
56
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(rootView)
57
+ ->NotifySizeChanged();
58
+ }
59
+ }
60
+ }
61
+
48
62
  winrt::Microsoft::ReactNative::ComponentView RootComponentView::GetFocusedComponent() noexcept {
49
63
  return m_focusedComponent;
50
64
  }
@@ -43,6 +43,10 @@ struct RootComponentView : RootComponentViewT<RootComponentView, ViewComponentVi
43
43
  HRESULT GetFragmentRoot(IRawElementProviderFragmentRoot **pRetVal) noexcept;
44
44
  winrt::Microsoft::ReactNative::implementation::ClipState getClipState() noexcept override;
45
45
 
46
+ void updateLayoutMetrics(
47
+ facebook::react::LayoutMetrics const &layoutMetrics,
48
+ facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
49
+
46
50
  winrt::IInspectable UiaProviderFromPoint(const POINT &ptPixels) noexcept;
47
51
 
48
52
  RootComponentView(
@@ -12,7 +12,6 @@
12
12
  #include <Fabric/FabricUIManagerModule.h>
13
13
  #include <Fabric/ReactNativeConfigProperties.h>
14
14
  #include <Fabric/WindowsComponentDescriptorRegistry.h>
15
- #include <ICompositionRootView.h>
16
15
  #include <IReactContext.h>
17
16
  #include <IReactRootView.h>
18
17
  #include <JSI/jsi.h>
@@ -144,6 +143,7 @@ const IComponentViewRegistry &FabricUIManager::GetViewRegistry() const noexcept
144
143
  void FabricUIManager::startSurface(
145
144
  const winrt::Microsoft::ReactNative::CompositionRootView &rootView,
146
145
  facebook::react::SurfaceId surfaceId,
146
+ const facebook::react::LayoutConstraints &layoutConstraints,
147
147
  const std::string &moduleName,
148
148
  const folly::dynamic &initialProps) noexcept {
149
149
  m_surfaceRegistry.insert({surfaceId, {rootView}});
@@ -158,22 +158,16 @@ void FabricUIManager::startSurface(
158
158
  root->start(rootView);
159
159
  });
160
160
 
161
- facebook::react::LayoutContext context;
162
- facebook::react::LayoutConstraints constraints;
163
- context.pointScaleFactor = rootView.ScaleFactor();
164
- context.fontSizeMultiplier = rootView.ScaleFactor();
165
- constraints.minimumSize.height = rootView.Size().Height;
166
- constraints.minimumSize.width = rootView.Size().Width;
167
- constraints.maximumSize.height = rootView.Size().Height;
168
- constraints.maximumSize.width = rootView.Size().Width;
169
- constraints.layoutDirection = facebook::react::LayoutDirection::LeftToRight;
161
+ facebook::react::LayoutContext layoutContext;
162
+ layoutContext.pointScaleFactor = rootView.ScaleFactor();
163
+ layoutContext.fontSizeMultiplier = rootView.ScaleFactor();
170
164
 
171
165
  m_surfaceManager->startSurface(
172
166
  surfaceId,
173
167
  moduleName,
174
168
  initialProps,
175
- constraints, // layout constraints
176
- context // layout context
169
+ layoutConstraints,
170
+ layoutContext // layout context
177
171
  );
178
172
  }
179
173
 
@@ -31,6 +31,7 @@ struct FabricUIManager final : public std::enable_shared_from_this<FabricUIManag
31
31
  void startSurface(
32
32
  const winrt::Microsoft::ReactNative::CompositionRootView &rootView,
33
33
  facebook::react::SurfaceId surfaceId,
34
+ const facebook::react::LayoutConstraints &layoutConstraints,
34
35
  const std::string &moduleName,
35
36
  const folly::dynamic &initialProps) noexcept;
36
37
 
@@ -10,11 +10,11 @@
10
10
  -->
11
11
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
12
12
  <PropertyGroup>
13
- <ReactNativeWindowsVersion>0.74.6</ReactNativeWindowsVersion>
13
+ <ReactNativeWindowsVersion>0.74.7</ReactNativeWindowsVersion>
14
14
  <ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
15
15
  <ReactNativeWindowsMinor>74</ReactNativeWindowsMinor>
16
- <ReactNativeWindowsPatch>6</ReactNativeWindowsPatch>
16
+ <ReactNativeWindowsPatch>7</ReactNativeWindowsPatch>
17
17
  <ReactNativeWindowsCanary>false</ReactNativeWindowsCanary>
18
- <ReactNativeWindowsCommitId>c93d7314ed1689c74689990641fbf3c1a54aa8cc</ReactNativeWindowsCommitId>
18
+ <ReactNativeWindowsCommitId>92b63ecf09a8f2c61a3c972e76bfdb535707d87b</ReactNativeWindowsCommitId>
19
19
  </PropertyGroup>
20
20
  </Project>
@@ -69,11 +69,6 @@
69
69
  <DependentUpon>$(ReactNativeWindowsDir)Microsoft.ReactNative\CompositionRootView.idl</DependentUpon>
70
70
  <SubType>Code</SubType>
71
71
  </ClCompile>
72
- <ClCompile Include="$(MSBuildThisFileDirectory)..\Microsoft.ReactNative\Fabric\Composition\CompositionRootView_emptyimpl.cpp">
73
- <ExcludedFromBuild Condition="'$(UseFabric)' == 'true' OR '$(IncludeFabricInterface)' != 'true'">true</ExcludedFromBuild>
74
- <DependentUpon>$(ReactNativeWindowsDir)Microsoft.ReactNative\CompositionRootView.idl</DependentUpon>
75
- <SubType>Code</SubType>
76
- </ClCompile>
77
72
  <ClCompile Include="$(MSBuildThisFileDirectory)..\Microsoft.ReactNative\Fabric\Composition\CompositionUIService.cpp">
78
73
  <ExcludedFromBuild Condition="'$(UseFabric)' != 'true'">true</ExcludedFromBuild>
79
74
  <DependentUpon>$(ReactNativeWindowsDir)Microsoft.ReactNative\CompositionUIService.idl</DependentUpon>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows",
3
- "version": "0.74.6",
3
+ "version": "0.74.7",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -34,8 +34,9 @@ void UpdateRootViewSizeToAppWindow(
34
34
  // Do not relayout when minimized
35
35
  if (window.Presenter().as<winrt::Microsoft::UI::Windowing::OverlappedPresenter>().State() !=
36
36
  winrt::Microsoft::UI::Windowing::OverlappedPresenterState::Minimized) {
37
- rootView.Arrange(size);
38
- rootView.Size(size);
37
+ winrt::Microsoft::ReactNative::LayoutConstraints constraints;
38
+ constraints.MaximumSize = constraints.MinimumSize = size;
39
+ rootView.Arrange(constraints, {0,0});
39
40
  }
40
41
  }
41
42
 
@@ -1,149 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- #include "pch.h"
4
-
5
- #include "CompositionRootView.h"
6
-
7
- #include "CompositionRootView.g.cpp"
8
- #include "FocusNavigationRequest.g.cpp"
9
-
10
- namespace winrt::Microsoft::ReactNative::implementation {
11
-
12
- //! This class ensures that we access ReactRootView from UI thread.
13
- struct CompositionReactViewInstance
14
- : public winrt::implements<CompositionReactViewInstance, winrt::Microsoft::ReactNative::IReactViewInstance> {
15
- CompositionReactViewInstance(
16
- winrt::weak_ref<winrt::Microsoft::ReactNative::implementation::CompositionRootView> &&) noexcept {}
17
-
18
- void InitRootView(
19
- winrt::Microsoft::ReactNative::IReactContext,
20
- winrt::Microsoft::ReactNative::ReactViewOptions) noexcept {}
21
-
22
- void UpdateRootView() noexcept {}
23
- void UninitRootView() noexcept {}
24
- };
25
-
26
- //===========================================================================
27
- // ReactViewInstance inline implementation
28
- //===========================================================================
29
-
30
- CompositionRootView::CompositionRootView() noexcept {}
31
- CompositionRootView::~CompositionRootView() noexcept {}
32
-
33
- CompositionRootView::CompositionRootView(const winrt::Microsoft::UI::Composition::Compositor &compositor) noexcept {}
34
-
35
- ReactNative::IReactViewHost CompositionRootView::ReactViewHost() noexcept {
36
- return nullptr;
37
- }
38
-
39
- void CompositionRootView::ReactViewHost(winrt::Microsoft::ReactNative::IReactViewHost const &) noexcept {}
40
-
41
- winrt::Microsoft::UI::Composition::Visual CompositionRootView::RootVisual() noexcept {
42
- return nullptr;
43
- }
44
-
45
- winrt::Microsoft::ReactNative::Composition::Experimental::IVisual CompositionRootView::InternalRootVisual() noexcept {
46
- return nullptr;
47
- }
48
-
49
- void CompositionRootView::InternalRootVisual(
50
- const winrt::Microsoft::ReactNative::Composition::Experimental::IVisual &) noexcept {}
51
-
52
- winrt::Microsoft::UI::Content::ContentIsland CompositionRootView::Island() noexcept {
53
- return nullptr;
54
- }
55
-
56
- winrt::Windows::Foundation::Size CompositionRootView::Size() noexcept {
57
- return {};
58
- }
59
-
60
- void CompositionRootView::Size(winrt::Windows::Foundation::Size) noexcept {}
61
-
62
- float CompositionRootView::ScaleFactor() noexcept {
63
- return 0;
64
- }
65
-
66
- void CompositionRootView::ScaleFactor(float) noexcept {}
67
-
68
- winrt::Microsoft::ReactNative::Composition::Theme CompositionRootView::Theme() noexcept {
69
- return nullptr;
70
- }
71
- void CompositionRootView::Theme(const winrt::Microsoft::ReactNative::Composition::Theme &) noexcept {}
72
-
73
- winrt::Microsoft::ReactNative::Composition::ICustomResourceLoader CompositionRootView::Resources() noexcept {
74
- return nullptr;
75
- }
76
- void CompositionRootView::Resources(
77
- const winrt::Microsoft::ReactNative::Composition::ICustomResourceLoader &) noexcept {}
78
-
79
- winrt::IInspectable CompositionRootView::GetUiaProvider() noexcept {
80
- return nullptr;
81
- }
82
-
83
- std::string CompositionRootView::JSComponentName() const noexcept {
84
- return {};
85
- }
86
-
87
- int64_t CompositionRootView::GetActualHeight() const noexcept {
88
- return 0;
89
- }
90
-
91
- int64_t CompositionRootView::GetActualWidth() const noexcept {
92
- return 0;
93
- }
94
-
95
- int64_t CompositionRootView::GetTag() const noexcept {
96
- return 0;
97
- }
98
-
99
- int64_t CompositionRootView::RootTag() const noexcept {
100
- return 0;
101
- }
102
-
103
- void CompositionRootView::SetTag(int64_t) noexcept {}
104
-
105
- void CompositionRootView::SetWindow(uint64_t) noexcept {}
106
-
107
- int64_t CompositionRootView::SendMessage(uint32_t, uint64_t, int64_t) noexcept {
108
- return 0;
109
- }
110
-
111
- void CompositionRootView::InitRootView(
112
- winrt::Microsoft::ReactNative::IReactContext &&,
113
- winrt::Microsoft::ReactNative::ReactViewOptions &&) noexcept {}
114
-
115
- void CompositionRootView::UpdateRootView() noexcept {}
116
-
117
- void CompositionRootView::UpdateRootViewInternal() noexcept {}
118
-
119
- void CompositionRootView::UninitRootView() noexcept {}
120
-
121
- void CompositionRootView::ClearLoadingUI() noexcept {}
122
-
123
- void CompositionRootView::EnsureLoadingUI() noexcept {}
124
-
125
- void CompositionRootView::ShowInstanceLoaded() noexcept {}
126
-
127
- void CompositionRootView::ShowInstanceError() noexcept {}
128
-
129
- void CompositionRootView::ShowInstanceLoading() noexcept {}
130
-
131
- winrt::Windows::Foundation::Size CompositionRootView::Measure(winrt::Windows::Foundation::Size const &) const {
132
- return {};
133
- }
134
-
135
- winrt::Windows::Foundation::Size CompositionRootView::Arrange(winrt::Windows::Foundation::Size) const {
136
- return {};
137
- }
138
-
139
- winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView *
140
- CompositionRootView::GetComponentView() noexcept {
141
- return nullptr;
142
- }
143
-
144
- winrt::Microsoft::ReactNative::FocusNavigationResult CompositionRootView::NavigateFocus(
145
- const winrt::Microsoft::ReactNative::FocusNavigationRequest &) noexcept {
146
- return nullptr;
147
- }
148
-
149
- } // namespace winrt::Microsoft::ReactNative::implementation
@@ -1,18 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
-
4
- #pragma once
5
-
6
- #include <Fabric/Composition/CompositionHelpers.h>
7
- #include <IReactRootView.h>
8
- #include <React.h>
9
- #include <folly/dynamic.h>
10
- #include <winrt/Windows.UI.Composition.h>
11
-
12
- namespace Microsoft::ReactNative {
13
-
14
- struct ICompositionRootView : public facebook::react::IReactRootView {
15
- virtual float ScaleFactor() noexcept = 0;
16
- };
17
-
18
- } // namespace Microsoft::ReactNative