react-native-windows 0.74.20 → 0.74.22

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 (94) hide show
  1. package/Microsoft.ReactNative/ComponentView.idl +44 -32
  2. package/Microsoft.ReactNative/Composition.Input.idl +3 -0
  3. package/Microsoft.ReactNative/CompositionComponentView.idl +43 -24
  4. package/Microsoft.ReactNative/CompositionSwitcher.idl +3 -0
  5. package/Microsoft.ReactNative/Fabric/AbiEventEmitter.cpp +21 -0
  6. package/Microsoft.ReactNative/Fabric/AbiEventEmitter.h +23 -0
  7. package/Microsoft.ReactNative/Fabric/AbiShadowNode.cpp +7 -0
  8. package/Microsoft.ReactNative/Fabric/AbiShadowNode.h +3 -0
  9. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +334 -65
  10. package/Microsoft.ReactNative/Fabric/ComponentView.h +162 -38
  11. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.cpp +2 -2
  12. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +3 -0
  13. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.cpp +29 -7
  14. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.h +23 -4
  15. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp +44 -13
  16. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +118 -0
  17. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +12 -1
  18. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +147 -119
  19. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +4 -8
  20. package/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp +1 -0
  21. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +129 -106
  22. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +31 -54
  23. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +133 -0
  24. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +61 -0
  25. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +9 -8
  26. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.h +1 -2
  27. package/Microsoft.ReactNative/Fabric/Composition/FocusManager.cpp +20 -6
  28. package/Microsoft.ReactNative/Fabric/Composition/FocusManager.h +13 -6
  29. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +1 -4
  30. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +3 -5
  31. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.h +1 -2
  32. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +1 -6
  33. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +0 -1
  34. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +108 -18
  35. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +33 -5
  36. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +137 -56
  37. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +21 -4
  38. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +45 -10
  39. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +9 -2
  40. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +209 -189
  41. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +2 -5
  42. package/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.cpp +22 -10
  43. package/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.h +4 -5
  44. package/Microsoft.ReactNative/Fabric/Composition/TextDrawing.cpp +1 -2
  45. package/Microsoft.ReactNative/Fabric/Composition/TextDrawing.h +1 -1
  46. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +115 -168
  47. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +11 -14
  48. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +14 -11
  49. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.h +4 -4
  50. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputState.cpp +0 -13
  51. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputState.h +0 -3
  52. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +12 -4
  53. package/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp +338 -0
  54. package/Microsoft.ReactNative/Fabric/Composition/TooltipService.h +66 -0
  55. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +56 -4
  56. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +7 -0
  57. package/Microsoft.ReactNative/Fabric/Composition/UnimplementedNativeViewComponentView.cpp +2 -4
  58. package/Microsoft.ReactNative/Fabric/Composition/UnimplementedNativeViewComponentView.h +1 -2
  59. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +40 -9
  60. package/Microsoft.ReactNative/Fabric/ReactTaggedView.h +4 -0
  61. package/Microsoft.ReactNative/Fabric/WindowsComponentDescriptorRegistry.cpp +1 -3
  62. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.cpp +25 -1
  63. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.h +4 -1
  64. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +1 -1
  65. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +9 -2
  66. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +13 -3
  67. package/Microsoft.ReactNative/IReactViewComponentBuilder.idl +64 -4
  68. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -1
  69. package/Microsoft.ReactNative/Modules/LogBoxModule.cpp +9 -0
  70. package/Microsoft.ReactNative/Modules/LogBoxModule.h +2 -0
  71. package/Microsoft.ReactNative/Modules/SampleTurboModule.cpp +104 -0
  72. package/Microsoft.ReactNative/Modules/SampleTurboModule.h +78 -0
  73. package/Microsoft.ReactNative/ReactCoreInjection.h +0 -1
  74. package/Microsoft.ReactNative/ReactHost/MsoReactContext.cpp +0 -7
  75. package/Microsoft.ReactNative/ReactHost/MsoReactContext.h +0 -5
  76. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +17 -1
  77. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.cpp +59 -0
  78. package/Microsoft.ReactNative/ReactInstanceSettingsBuilder.h +23 -0
  79. package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +179 -0
  80. package/Microsoft.ReactNative/ReactNativeAppBuilder.h +35 -0
  81. package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +69 -0
  82. package/Microsoft.ReactNative/ReactNativeIsland.idl +5 -0
  83. package/Microsoft.ReactNative/ReactNativeWin32App.cpp +82 -0
  84. package/Microsoft.ReactNative/ReactNativeWin32App.h +38 -0
  85. package/Microsoft.ReactNative/Timer.idl +1 -1
  86. package/Microsoft.ReactNative/packages.lock.json +0 -10
  87. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  88. package/PropertySheets/WinUI.props +1 -1
  89. package/Shared/Shared.vcxitems +43 -0
  90. package/Shared/Shared.vcxitems.filters +3 -0
  91. package/Shared/TurboModuleManager.cpp +0 -3
  92. package/just-task.js +1 -1
  93. package/package.json +3 -3
  94. package/templates/cpp-app/windows/MyApp/MyApp.cpp +1 -0
@@ -42,7 +42,7 @@ struct ScrollBarComponent {
42
42
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
43
43
  winrt::Microsoft::ReactNative::ReactContext const &reactContext,
44
44
  bool vertical)
45
- : m_outer(outer), m_compContext(compContext), m_reactContext(reactContext), m_vertical(vertical) {
45
+ : m_wkOuter(outer), m_compContext(compContext), m_reactContext(reactContext), m_vertical(vertical) {
46
46
  m_rootVisual = m_compContext.CreateSpriteVisual();
47
47
  m_trackVisual = m_compContext.CreateRoundedRectangleVisual();
48
48
  m_thumbVisual = m_compContext.CreateRoundedRectangleVisual();
@@ -73,9 +73,11 @@ struct ScrollBarComponent {
73
73
  updateHighlight(ScrollbarHitRegion::ArrowLast);
74
74
  updateHighlight(ScrollbarHitRegion::Thumb);
75
75
 
76
- m_trackVisual.Brush(
77
- winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::Theme>(m_outer.Theme())
78
- ->InternalPlatformBrush(L"ScrollBarTrackFill"));
76
+ if (auto outer = m_wkOuter.get()) {
77
+ m_trackVisual.Brush(
78
+ winrt::get_self<winrt::Microsoft::ReactNative::Composition::implementation::Theme>(outer.Theme())
79
+ ->InternalPlatformBrush(L"ScrollBarTrackFill"));
80
+ }
79
81
  }
80
82
 
81
83
  void ContentSize(winrt::Windows::Foundation::Size contentSize) noexcept {
@@ -293,19 +295,21 @@ struct ScrollBarComponent {
293
295
  }
294
296
 
295
297
  void OnPointerReleased(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
296
- if (!m_visible)
297
- return;
298
- auto pt = args.GetCurrentPoint(m_outer.Tag());
299
- if (m_nTrackInputOffset != -1 &&
300
- pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse &&
301
- pt.Properties().PointerUpdateKind() ==
302
- winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::LeftButtonReleased) {
303
- handleMoveThumb(args);
304
- stopTrackingThumb();
305
- m_outer.ReleasePointerCapture(args.Pointer());
306
-
307
- auto reg = HitTest(pt.Position());
308
- updateShy(reg == ScrollbarHitRegion::Unknown);
298
+ if (auto outer = m_wkOuter.get()) {
299
+ if (!m_visible)
300
+ return;
301
+ auto pt = args.GetCurrentPoint(outer.Tag());
302
+ if (m_nTrackInputOffset != -1 &&
303
+ pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse &&
304
+ pt.Properties().PointerUpdateKind() ==
305
+ winrt::Microsoft::ReactNative::Composition::Input::PointerUpdateKind::LeftButtonReleased) {
306
+ handleMoveThumb(args);
307
+ stopTrackingThumb();
308
+ outer.ReleasePointerCapture(args.Pointer());
309
+
310
+ auto reg = HitTest(pt.Position());
311
+ updateShy(reg == ScrollbarHitRegion::Unknown);
312
+ }
309
313
  }
310
314
  }
311
315
 
@@ -318,78 +322,85 @@ struct ScrollBarComponent {
318
322
  }
319
323
 
320
324
  void handleMoveThumb(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
321
- auto pt = args.GetCurrentPoint(m_outer.Tag());
322
- auto pos = pt.Position();
323
-
324
- auto newTrackingPosition = static_cast<int>((m_vertical ? pos.Y : pos.X) * m_scaleFactor) - m_nTrackInputOffset;
325
- winrt::get_self<ScrollViewComponentView>(m_outer)->scrollTo(
326
- m_vertical ? winrt::Windows::Foundation::Numerics::
327
- float3{m_offset.x, scrollOffsetFromThumbPos(newTrackingPosition), m_offset.z}
328
- : winrt::Windows::Foundation::Numerics::
329
- float3{scrollOffsetFromThumbPos(newTrackingPosition), m_offset.y, m_offset.z},
330
- false);
325
+ if (auto outer = m_wkOuter.get()) {
326
+ auto pt = args.GetCurrentPoint(outer.Tag());
327
+ auto pos = pt.Position();
328
+
329
+ auto newTrackingPosition = static_cast<int>((m_vertical ? pos.Y : pos.X) * m_scaleFactor) - m_nTrackInputOffset;
330
+ winrt::get_self<ScrollViewComponentView>(outer)->scrollTo(
331
+ m_vertical ? winrt::Windows::Foundation::Numerics::
332
+ float3{m_offset.x, scrollOffsetFromThumbPos(newTrackingPosition), m_offset.z}
333
+ : winrt::Windows::Foundation::Numerics::
334
+ float3{scrollOffsetFromThumbPos(newTrackingPosition), m_offset.y, m_offset.z},
335
+ false);
336
+ }
331
337
  args.Handled(true);
332
338
  }
333
339
 
334
340
  void OnPointerPressed(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
335
- if (!m_visible)
336
- return;
337
- auto pt = args.GetCurrentPoint(m_outer.Tag());
338
- if (pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
339
- auto pos = pt.Position();
340
- auto reg = HitTest(pos);
341
+ if (auto outer = m_wkOuter.get()) {
342
+ if (!m_visible)
343
+ return;
344
+ auto pt = args.GetCurrentPoint(outer.Tag());
345
+ if (pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
346
+ auto pos = pt.Position();
347
+ auto reg = HitTest(pos);
341
348
 
342
- switch (reg) {
343
- case ScrollbarHitRegion::ArrowFirst:
344
- if (m_vertical) {
345
- winrt::get_self<ScrollViewComponentView>(m_outer)->lineUp(false);
346
- } else {
347
- winrt::get_self<ScrollViewComponentView>(m_outer)->lineLeft(false);
348
- }
349
- args.Handled(true);
350
- break;
351
- case ScrollbarHitRegion::ArrowLast:
352
- if (m_vertical) {
353
- winrt::get_self<ScrollViewComponentView>(m_outer)->lineDown(false);
354
- } else {
355
- winrt::get_self<ScrollViewComponentView>(m_outer)->lineRight(false);
356
- }
357
- args.Handled(true);
358
- break;
359
- case ScrollbarHitRegion::PageUp:
360
- if (m_vertical) {
361
- winrt::get_self<ScrollViewComponentView>(m_outer)->pageUp(false);
362
- }
363
- args.Handled(true);
364
- break;
365
- case ScrollbarHitRegion::PageDown:
366
- if (m_vertical) {
367
- winrt::get_self<ScrollViewComponentView>(m_outer)->pageDown(false);
349
+ switch (reg) {
350
+ case ScrollbarHitRegion::ArrowFirst:
351
+ if (m_vertical) {
352
+ winrt::get_self<ScrollViewComponentView>(outer)->lineUp(false);
353
+ } else {
354
+ winrt::get_self<ScrollViewComponentView>(outer)->lineLeft(false);
355
+ }
356
+ args.Handled(true);
357
+ break;
358
+ case ScrollbarHitRegion::ArrowLast:
359
+ if (m_vertical) {
360
+ winrt::get_self<ScrollViewComponentView>(outer)->lineDown(false);
361
+ } else {
362
+ winrt::get_self<ScrollViewComponentView>(outer)->lineRight(false);
363
+ }
364
+ args.Handled(true);
365
+ break;
366
+ case ScrollbarHitRegion::PageUp:
367
+ if (m_vertical) {
368
+ winrt::get_self<ScrollViewComponentView>(outer)->pageUp(false);
369
+ }
370
+ args.Handled(true);
371
+ break;
372
+ case ScrollbarHitRegion::PageDown:
373
+ if (m_vertical) {
374
+ winrt::get_self<ScrollViewComponentView>(outer)->pageDown(false);
375
+ }
376
+ args.Handled(true);
377
+ break;
378
+ case ScrollbarHitRegion::Thumb: {
379
+ outer.CapturePointer(args.Pointer());
380
+ m_nTrackInputOffset = static_cast<int>((m_vertical ? pos.Y : pos.X) * m_scaleFactor) - m_thumbPos;
381
+ m_thumbVisual.AnimationClass(
382
+ winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::None);
383
+ handleMoveThumb(args);
368
384
  }
369
- args.Handled(true);
370
- break;
371
- case ScrollbarHitRegion::Thumb: {
372
- m_outer.CapturePointer(args.Pointer());
373
- m_nTrackInputOffset = static_cast<int>((m_vertical ? pos.Y : pos.X) * m_scaleFactor) - m_thumbPos;
374
- m_thumbVisual.AnimationClass(winrt::Microsoft::ReactNative::Composition::Experimental::AnimationClass::None);
375
- handleMoveThumb(args);
376
385
  }
377
386
  }
378
387
  }
379
388
  }
380
389
 
381
390
  void OnPointerMoved(const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) {
382
- if (!m_visible)
383
- return;
384
- auto pt = args.GetCurrentPoint(m_outer.Tag());
385
- if (pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
386
- if (m_nTrackInputOffset != -1) {
387
- handleMoveThumb(args);
388
- } else {
389
- auto pos = pt.Position();
390
- auto reg = HitTest(pos);
391
- updateShy(reg == ScrollbarHitRegion::Unknown);
392
- setHighlightedRegion(reg);
391
+ if (auto outer = m_wkOuter.get()) {
392
+ if (!m_visible)
393
+ return;
394
+ auto pt = args.GetCurrentPoint(outer.Tag());
395
+ if (pt.PointerDeviceType() == winrt::Microsoft::ReactNative::Composition::Input::PointerDeviceType::Mouse) {
396
+ if (m_nTrackInputOffset != -1) {
397
+ handleMoveThumb(args);
398
+ } else {
399
+ auto pos = pt.Position();
400
+ auto reg = HitTest(pos);
401
+ updateShy(reg == ScrollbarHitRegion::Unknown);
402
+ setHighlightedRegion(reg);
403
+ }
393
404
  }
394
405
  }
395
406
  }
@@ -427,122 +438,126 @@ struct ScrollBarComponent {
427
438
 
428
439
  // Renders the text into our composition surface
429
440
  void drawArrow(ScrollbarHitRegion region, bool disabled, bool hovered) noexcept {
430
- auto &drawingSurface =
431
- (region == ScrollbarHitRegion::ArrowFirst) ? m_arrowFirstDrawingSurface : m_arrowLastDrawingSurface;
432
- if (!drawingSurface) {
433
- drawingSurface = m_compContext.CreateDrawingSurfaceBrush(
434
- {m_arrowSize, m_arrowSize},
435
- winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
436
- winrt::Windows::Graphics::DirectX::DirectXAlphaMode::Premultiplied);
437
- }
441
+ if (auto outer = m_wkOuter.get()) {
442
+ auto &drawingSurface =
443
+ (region == ScrollbarHitRegion::ArrowFirst) ? m_arrowFirstDrawingSurface : m_arrowLastDrawingSurface;
444
+ if (!drawingSurface) {
445
+ drawingSurface = m_compContext.CreateDrawingSurfaceBrush(
446
+ {m_arrowSize, m_arrowSize},
447
+ winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
448
+ winrt::Windows::Graphics::DirectX::DirectXAlphaMode::Premultiplied);
449
+ }
438
450
 
439
- if (winrt::get_self<ScrollViewComponentView>(m_outer)->theme()->IsEmpty()) {
440
- return;
441
- }
451
+ if (winrt::get_self<ScrollViewComponentView>(outer)->theme()->IsEmpty()) {
452
+ return;
453
+ }
442
454
 
443
- winrt::com_ptr<IDWriteTextFormat> spTextFormat;
444
- winrt::check_hresult(::Microsoft::ReactNative::DWriteFactory()->CreateTextFormat(
445
- L"Segoe Fluent Icons",
446
- nullptr, // Font collection (nullptr sets it to use the system font collection).
447
- DWRITE_FONT_WEIGHT_REGULAR,
448
- DWRITE_FONT_STYLE_NORMAL,
449
- DWRITE_FONT_STRETCH_NORMAL,
450
- 8, // Xaml resource: ScrollBarButtonArrowIconFontSize
451
- L"",
452
- spTextFormat.put()));
453
-
454
- winrt::check_hresult(spTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
455
-
456
- winrt::com_ptr<IDWriteTextLayout> spTextLayout;
457
- winrt::check_hresult(::Microsoft::ReactNative::DWriteFactory()->CreateTextLayout(
458
- m_vertical ? ((region == ScrollbarHitRegion::ArrowFirst) ? L"\uEDDB" : L"\uEDDC")
459
- : ((region == ScrollbarHitRegion::ArrowFirst) ? L"\uEDD9" : L"\uEDDA"),
460
- 1, // The length of the string.
461
- spTextFormat.get(), // The text format to apply to the string (contains font information, etc).
462
- (m_arrowSize / m_scaleFactor), // The width of the layout box.
463
- (m_arrowSize / m_scaleFactor), // The height of the layout box.
464
- spTextLayout.put() // The IDWriteTextLayout interface pointer.
465
- ));
466
-
467
- POINT offset;
468
- {
469
- ::Microsoft::ReactNative::Composition::AutoDrawDrawingSurface autoDraw(drawingSurface, m_scaleFactor, &offset);
470
- if (auto d2dDeviceContext = autoDraw.GetRenderTarget()) {
471
- d2dDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
472
- assert(d2dDeviceContext->GetUnitMode() == D2D1_UNIT_MODE_DIPS);
473
-
474
- // Create a solid color brush for the text. A more sophisticated application might want
475
- // to cache and reuse a brush across all text elements instead, taking care to recreate
476
- // it in the event of device removed.
477
- winrt::com_ptr<ID2D1SolidColorBrush> brush;
478
-
479
- D2D1::ColorF color{0};
480
- if (disabled) {
481
- color = winrt::get_self<ScrollViewComponentView>(m_outer)->theme()->D2DPlatformColor(
482
- "ScrollBarButtonArrowForegroundDisabled");
483
- } else if (hovered) {
484
- color = winrt::get_self<ScrollViewComponentView>(m_outer)->theme()->D2DPlatformColor(
485
- "ScrollBarButtonArrowForegroundPointerOver");
486
- } else {
487
- color = winrt::get_self<ScrollViewComponentView>(m_outer)->theme()->D2DPlatformColor(
488
- "ScrollBarButtonArrowForeground");
489
- }
490
- winrt::check_hresult(d2dDeviceContext->CreateSolidColorBrush(color, brush.put()));
455
+ winrt::com_ptr<IDWriteTextFormat> spTextFormat;
456
+ winrt::check_hresult(::Microsoft::ReactNative::DWriteFactory()->CreateTextFormat(
457
+ L"Segoe Fluent Icons",
458
+ nullptr, // Font collection (nullptr sets it to use the system font collection).
459
+ DWRITE_FONT_WEIGHT_REGULAR,
460
+ DWRITE_FONT_STYLE_NORMAL,
461
+ DWRITE_FONT_STRETCH_NORMAL,
462
+ 8, // Xaml resource: ScrollBarButtonArrowIconFontSize
463
+ L"",
464
+ spTextFormat.put()));
465
+
466
+ winrt::check_hresult(spTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER));
467
+
468
+ winrt::com_ptr<IDWriteTextLayout> spTextLayout;
469
+ winrt::check_hresult(::Microsoft::ReactNative::DWriteFactory()->CreateTextLayout(
470
+ m_vertical ? ((region == ScrollbarHitRegion::ArrowFirst) ? L"\uEDDB" : L"\uEDDC")
471
+ : ((region == ScrollbarHitRegion::ArrowFirst) ? L"\uEDD9" : L"\uEDDA"),
472
+ 1, // The length of the string.
473
+ spTextFormat.get(), // The text format to apply to the string (contains font information, etc).
474
+ (m_arrowSize / m_scaleFactor), // The width of the layout box.
475
+ (m_arrowSize / m_scaleFactor), // The height of the layout box.
476
+ spTextLayout.put() // The IDWriteTextLayout interface pointer.
477
+ ));
478
+
479
+ POINT offset;
480
+ {
481
+ ::Microsoft::ReactNative::Composition::AutoDrawDrawingSurface autoDraw(drawingSurface, m_scaleFactor, &offset);
482
+ if (auto d2dDeviceContext = autoDraw.GetRenderTarget()) {
483
+ d2dDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));
484
+ assert(d2dDeviceContext->GetUnitMode() == D2D1_UNIT_MODE_DIPS);
485
+
486
+ // Create a solid color brush for the text. A more sophisticated application might want
487
+ // to cache and reuse a brush across all text elements instead, taking care to recreate
488
+ // it in the event of device removed.
489
+ winrt::com_ptr<ID2D1SolidColorBrush> brush;
490
+
491
+ D2D1::ColorF color{0};
492
+ if (disabled) {
493
+ color = winrt::get_self<ScrollViewComponentView>(outer)->theme()->D2DPlatformColor(
494
+ "ScrollBarButtonArrowForegroundDisabled");
495
+ } else if (hovered) {
496
+ color = winrt::get_self<ScrollViewComponentView>(outer)->theme()->D2DPlatformColor(
497
+ "ScrollBarButtonArrowForegroundPointerOver");
498
+ } else {
499
+ color = winrt::get_self<ScrollViewComponentView>(outer)->theme()->D2DPlatformColor(
500
+ "ScrollBarButtonArrowForeground");
501
+ }
502
+ winrt::check_hresult(d2dDeviceContext->CreateSolidColorBrush(color, brush.put()));
491
503
 
492
- {
493
- DWRITE_TEXT_METRICS dtm{};
494
- winrt::check_hresult(spTextLayout->GetMetrics(&dtm));
495
- offset.y += static_cast<int>((m_arrowSize - dtm.height) / 2.0f);
496
- }
504
+ {
505
+ DWRITE_TEXT_METRICS dtm{};
506
+ winrt::check_hresult(spTextLayout->GetMetrics(&dtm));
507
+ offset.y += static_cast<int>((m_arrowSize - dtm.height) / 2.0f);
508
+ }
497
509
 
498
- // Draw the line of text at the specified offset, which corresponds to the top-left
499
- // corner of our drawing surface. Notice we don't call BeginDraw on the D2D device
500
- // context; this has already been done for us by the composition API.
501
- d2dDeviceContext->DrawTextLayout(
502
- D2D1::Point2F(
503
- static_cast<FLOAT>((offset.x) / m_scaleFactor), static_cast<FLOAT>((offset.y) / m_scaleFactor)),
504
- spTextLayout.get(),
505
- brush.get(),
506
- D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT);
510
+ // Draw the line of text at the specified offset, which corresponds to the top-left
511
+ // corner of our drawing surface. Notice we don't call BeginDraw on the D2D device
512
+ // context; this has already been done for us by the composition API.
513
+ d2dDeviceContext->DrawTextLayout(
514
+ D2D1::Point2F(
515
+ static_cast<FLOAT>((offset.x) / m_scaleFactor), static_cast<FLOAT>((offset.y) / m_scaleFactor)),
516
+ spTextLayout.get(),
517
+ brush.get(),
518
+ D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT);
519
+ }
520
+ }
521
+ if (drawingSurface) {
522
+ drawingSurface.HorizontalAlignmentRatio(0.0f);
523
+ drawingSurface.VerticalAlignmentRatio(0.0f);
524
+ drawingSurface.Stretch(winrt::Microsoft::ReactNative::Composition::Experimental::CompositionStretch::None);
507
525
  }
508
- }
509
- if (drawingSurface) {
510
- drawingSurface.HorizontalAlignmentRatio(0.0f);
511
- drawingSurface.VerticalAlignmentRatio(0.0f);
512
- drawingSurface.Stretch(winrt::Microsoft::ReactNative::Composition::Experimental::CompositionStretch::None);
513
- }
514
526
 
515
- auto &arrowVisual = (region == ScrollbarHitRegion::ArrowFirst) ? m_arrowVisualFirst : m_arrowVisualLast;
516
- arrowVisual.Brush(drawingSurface);
527
+ auto &arrowVisual = (region == ScrollbarHitRegion::ArrowFirst) ? m_arrowVisualFirst : m_arrowVisualLast;
528
+ arrowVisual.Brush(drawingSurface);
529
+ }
517
530
  }
518
531
 
519
532
  void updateHighlight(ScrollbarHitRegion region) noexcept {
520
- switch (region) {
521
- case ScrollbarHitRegion::ArrowFirst:
522
- case ScrollbarHitRegion::ArrowLast: {
523
- auto disabled = !std::static_pointer_cast<const facebook::react::ScrollViewProps>(
524
- winrt::get_self<ScrollViewComponentView>(m_outer)->viewProps())
525
- ->scrollEnabled;
526
- drawArrow(region, disabled, m_highlightedRegion == region);
527
- }
528
- case ScrollbarHitRegion::Thumb: {
529
- if (!std::static_pointer_cast<const facebook::react::ScrollViewProps>(
530
- winrt::get_self<ScrollViewComponentView>(m_outer)->viewProps())
531
- ->scrollEnabled) {
532
- m_thumbVisual.Brush(
533
- winrt::get_self<Theme>(m_outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFillDisabled"));
534
- } else if (m_highlightedRegion == region) {
535
- m_thumbVisual.Brush(
536
- winrt::get_self<Theme>(m_outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFillPointerOver"));
537
- } else {
538
- m_thumbVisual.Brush(winrt::get_self<Theme>(m_outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFill"));
533
+ if (auto outer = m_wkOuter.get()) {
534
+ switch (region) {
535
+ case ScrollbarHitRegion::ArrowFirst:
536
+ case ScrollbarHitRegion::ArrowLast: {
537
+ auto disabled = !std::static_pointer_cast<const facebook::react::ScrollViewProps>(
538
+ winrt::get_self<ScrollViewComponentView>(outer)->viewProps())
539
+ ->scrollEnabled;
540
+ drawArrow(region, disabled, m_highlightedRegion == region);
541
+ }
542
+ case ScrollbarHitRegion::Thumb: {
543
+ if (!std::static_pointer_cast<const facebook::react::ScrollViewProps>(
544
+ winrt::get_self<ScrollViewComponentView>(outer)->viewProps())
545
+ ->scrollEnabled) {
546
+ m_thumbVisual.Brush(
547
+ winrt::get_self<Theme>(outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFillDisabled"));
548
+ } else if (m_highlightedRegion == region) {
549
+ m_thumbVisual.Brush(
550
+ winrt::get_self<Theme>(outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFillPointerOver"));
551
+ } else {
552
+ m_thumbVisual.Brush(winrt::get_self<Theme>(outer.Theme())->InternalPlatformBrush(L"ScrollBarThumbFill"));
553
+ }
539
554
  }
540
555
  }
541
556
  }
542
557
  }
543
558
 
544
559
  private:
545
- winrt::Microsoft::ReactNative::Composition::ScrollViewComponentView m_outer;
560
+ winrt::weak_ref<winrt::Microsoft::ReactNative::Composition::ScrollViewComponentView> m_wkOuter;
546
561
  winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext m_compContext;
547
562
  winrt::Microsoft::ReactNative::ReactContext m_reactContext;
548
563
  const bool m_vertical;
@@ -593,8 +608,7 @@ ScrollViewComponentView::ScrollViewComponentView(
593
608
  compContext,
594
609
  tag,
595
610
  reactContext,
596
- ComponentViewFeatures::Default & ~ComponentViewFeatures::Background,
597
- false) {
611
+ ComponentViewFeatures::Default & ~ComponentViewFeatures::Background) {
598
612
  // m_element.Content(m_contentPanel);
599
613
 
600
614
  /*
@@ -872,6 +886,12 @@ void ScrollViewComponentView::OnPointerPressed(
872
886
  m_verticalScrollbarComponent->OnPointerPressed(args);
873
887
  m_horizontalScrollbarComponent->OnPointerPressed(args);
874
888
  Super::OnPointerPressed(args);
889
+
890
+ if (!args.Handled()) {
891
+ auto f = args.Pointer();
892
+ auto g = f.PointerDeviceType();
893
+ m_scrollVisual.OnPointerPressed(args);
894
+ }
875
895
  }
876
896
 
877
897
  void ScrollViewComponentView::OnPointerReleased(
@@ -895,7 +915,6 @@ void ScrollViewComponentView::OnPointerCaptureLost() noexcept {
895
915
  }
896
916
 
897
917
  void ScrollViewComponentView::OnKeyDown(
898
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
899
918
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
900
919
  switch (args.Key()) {
901
920
  case winrt::Windows::System::VirtualKey::End:
@@ -924,7 +943,7 @@ void ScrollViewComponentView::OnKeyDown(
924
943
  break;
925
944
  }
926
945
 
927
- base_type::OnKeyDown(source, args);
946
+ base_type::OnKeyDown(args);
928
947
  }
929
948
 
930
949
  bool ScrollViewComponentView::scrollToEnd(bool animate) noexcept {
@@ -1032,13 +1051,16 @@ bool ScrollViewComponentView::scrollRight(float delta, bool animate) noexcept {
1032
1051
  return true;
1033
1052
  }
1034
1053
 
1035
- void ScrollViewComponentView::HandleCommand(
1036
- winrt::hstring commandName,
1037
- const winrt::Microsoft::ReactNative::IJSValueReader &args) noexcept {
1054
+ void ScrollViewComponentView::HandleCommand(const winrt::Microsoft::ReactNative::HandleCommandArgs &args) noexcept {
1055
+ Super::HandleCommand(args);
1056
+ if (args.Handled())
1057
+ return;
1058
+
1059
+ auto commandName = args.CommandName();
1038
1060
  if (commandName == L"scrollTo") {
1039
1061
  double x, y;
1040
1062
  bool animate;
1041
- winrt::Microsoft::ReactNative::ReadArgs(args, x, y, animate);
1063
+ winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), x, y, animate);
1042
1064
  scrollTo(
1043
1065
  {static_cast<float>(x) * m_layoutMetrics.pointScaleFactor,
1044
1066
  static_cast<float>(y) * m_layoutMetrics.pointScaleFactor,
@@ -1048,12 +1070,10 @@ void ScrollViewComponentView::HandleCommand(
1048
1070
  // No-op for now
1049
1071
  } else if (commandName == L"scrollToEnd") {
1050
1072
  bool animate;
1051
- winrt::Microsoft::ReactNative::ReadArgs(args, animate);
1073
+ winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), animate);
1052
1074
  scrollToEnd(animate);
1053
1075
  } else if (commandName == L"zoomToRect") {
1054
1076
  // No-op for now
1055
- } else {
1056
- Super::HandleCommand(commandName, args);
1057
1077
  }
1058
1078
  }
1059
1079
 
@@ -72,12 +72,9 @@ struct ScrollInteractionTrackerOwner : public winrt::implements<
72
72
  facebook::react::LayoutMetrics const &layoutMetrics,
73
73
  facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
74
74
  void prepareForRecycle() noexcept override;
75
- void OnKeyDown(
76
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
77
- const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
75
+ void OnKeyDown(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
78
76
 
79
- void HandleCommand(winrt::hstring commandName, const winrt::Microsoft::ReactNative::IJSValueReader &args) noexcept
80
- override;
77
+ void HandleCommand(const winrt::Microsoft::ReactNative::HandleCommandArgs &args) noexcept override;
81
78
  facebook::react::Tag hitTest(facebook::react::Point pt, facebook::react::Point &localPt, bool ignorePointerEvents)
82
79
  const noexcept override;
83
80
  facebook::react::Point getClientOffset() const noexcept override;
@@ -33,8 +33,7 @@ SwitchComponentView::SwitchComponentView(
33
33
  compContext,
34
34
  tag,
35
35
  reactContext,
36
- ComponentViewFeatures::Default & ~ComponentViewFeatures::Background,
37
- false) {}
36
+ ComponentViewFeatures::Default & ~ComponentViewFeatures::Background) {}
38
37
 
39
38
  winrt::Microsoft::ReactNative::ComponentView SwitchComponentView::Create(
40
39
  const winrt::Microsoft::ReactNative::Composition::Experimental::ICompositionContext &compContext,
@@ -57,14 +56,14 @@ void SwitchComponentView::UnmountChildComponentView(
57
56
  base_type::UnmountChildComponentView(childComponentView, index);
58
57
  }
59
58
 
60
- void SwitchComponentView::HandleCommand(
61
- winrt::hstring commandName,
62
- const winrt::Microsoft::ReactNative::IJSValueReader &args) noexcept {
59
+ void SwitchComponentView::HandleCommand(const winrt::Microsoft::ReactNative::HandleCommandArgs &args) noexcept {
60
+ Super::HandleCommand(args);
61
+ if (args.Handled())
62
+ return;
63
+ auto commandName = args.CommandName();
63
64
  if (commandName == L"setValue") {
64
65
  // TODO - Current implementation always aligns with JS value
65
66
  // This will be needed when we move to using WinUI controls
66
- } else {
67
- Super::HandleCommand(commandName, args);
68
67
  }
69
68
  }
70
69
 
@@ -262,7 +261,7 @@ void SwitchComponentView::OnPointerPressed(
262
261
  m_supressAnimationForNextFrame = true;
263
262
 
264
263
  if (auto root = rootComponentView()) {
265
- root->TrySetFocusedComponent(*get_strong());
264
+ root->TrySetFocusedComponent(*get_strong(), winrt::Microsoft::ReactNative::FocusNavigationDirection::None);
266
265
  }
267
266
 
268
267
  updateVisuals();
@@ -304,14 +303,13 @@ void SwitchComponentView::OnPointerExited(
304
303
  }
305
304
 
306
305
  void SwitchComponentView::OnKeyUp(
307
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
308
306
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
309
307
  if (args.Key() == winrt::Windows::System::VirtualKey::Space) {
310
308
  if (toggle()) {
311
309
  args.Handled(true);
312
310
  }
313
311
  }
314
- Super::OnKeyUp(source, args);
312
+ Super::OnKeyUp(args);
315
313
  }
316
314
 
317
315
  bool SwitchComponentView::toggle() noexcept {
@@ -341,4 +339,18 @@ const facebook::react::SwitchProps &SwitchComponentView::switchProps() const noe
341
339
  return *std::static_pointer_cast<const facebook::react::SwitchProps>(viewProps());
342
340
  }
343
341
 
342
+ // getToggleState method for IToggleProvider
343
+ ToggleState SwitchComponentView::getToggleState() noexcept {
344
+ if (switchProps().value) {
345
+ return ToggleState::ToggleState_On;
346
+ } else {
347
+ return ToggleState::ToggleState_Off;
348
+ }
349
+ }
350
+
351
+ // Toggle method for IToggleProvider
352
+ void SwitchComponentView::Toggle() noexcept {
353
+ toggle();
354
+ }
355
+
344
356
  } // namespace winrt::Microsoft::ReactNative::Composition::implementation
@@ -27,8 +27,7 @@ struct SwitchComponentView : SwitchComponentViewT<SwitchComponentView, ViewCompo
27
27
  void UnmountChildComponentView(
28
28
  const winrt::Microsoft::ReactNative::ComponentView &childComponentView,
29
29
  uint32_t index) noexcept override;
30
- void HandleCommand(winrt::hstring commandName, const winrt::Microsoft::ReactNative::IJSValueReader &args) noexcept
31
- override;
30
+ void HandleCommand(const winrt::Microsoft::ReactNative::HandleCommandArgs &args) noexcept override;
32
31
  void updateProps(facebook::react::Props::Shared const &props, facebook::react::Props::Shared const &oldProps) noexcept
33
32
  override;
34
33
  void updateState(facebook::react::State::Shared const &state, facebook::react::State::Shared const &oldState) noexcept
@@ -38,9 +37,7 @@ struct SwitchComponentView : SwitchComponentViewT<SwitchComponentView, ViewCompo
38
37
  facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
39
38
  void FinalizeUpdates(winrt::Microsoft::ReactNative::ComponentViewUpdateMask updateMask) noexcept override;
40
39
  void onThemeChanged() noexcept override;
41
- void OnKeyUp(
42
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
43
- const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
40
+ void OnKeyUp(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
44
41
  void OnPointerPressed(
45
42
  const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept override;
46
43
  void OnPointerReleased(
@@ -59,6 +56,8 @@ struct SwitchComponentView : SwitchComponentViewT<SwitchComponentView, ViewCompo
59
56
 
60
57
  static facebook::react::SharedViewProps defaultProps() noexcept;
61
58
  const facebook::react::SwitchProps &switchProps() const noexcept;
59
+ ToggleState getToggleState() noexcept override;
60
+ void Toggle() noexcept override;
62
61
  winrt::Microsoft::ReactNative::Composition::Experimental::IVisual createVisual() noexcept override;
63
62
 
64
63
  private:
@@ -16,7 +16,7 @@
16
16
  namespace winrt::Microsoft::ReactNative::Composition {
17
17
 
18
18
  void RenderText(
19
- ID2D1DeviceContext &deviceContext,
19
+ ID2D1RenderTarget &deviceContext,
20
20
  ::IDWriteTextLayout &textLayout,
21
21
  const facebook::react::AttributedString &attributedString,
22
22
  const facebook::react::TextAttributes &textAttributes,
@@ -26,7 +26,6 @@ void RenderText(
26
26
  float offsetX = offset.x / pointScaleFactor;
27
27
  float offsetY = offset.y / pointScaleFactor;
28
28
 
29
- assert(deviceContext.GetUnitMode() == D2D1_UNIT_MODE_DIPS);
30
29
  const auto dpi = pointScaleFactor * 96.0f;
31
30
  float oldDpiX, oldDpiY;
32
31
  deviceContext.GetDpi(&oldDpiX, &oldDpiY);