react-native-windows 0.75.1 → 0.75.3

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 (53) hide show
  1. package/Microsoft.ReactNative/ComponentView.idl +33 -32
  2. package/Microsoft.ReactNative/Composition.Input.idl +2 -0
  3. package/Microsoft.ReactNative/CompositionComponentView.idl +43 -24
  4. package/Microsoft.ReactNative/Fabric/AbiEventEmitter.cpp +21 -0
  5. package/Microsoft.ReactNative/Fabric/AbiEventEmitter.h +23 -0
  6. package/Microsoft.ReactNative/Fabric/AbiShadowNode.cpp +7 -0
  7. package/Microsoft.ReactNative/Fabric/AbiShadowNode.h +3 -0
  8. package/Microsoft.ReactNative/Fabric/ComponentView.cpp +318 -59
  9. package/Microsoft.ReactNative/Fabric/ComponentView.h +155 -33
  10. package/Microsoft.ReactNative/Fabric/Composition/ActivityIndicatorComponentView.cpp +2 -2
  11. package/Microsoft.ReactNative/Fabric/Composition/ComponentViewRegistry.cpp +3 -0
  12. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.cpp +25 -7
  13. package/Microsoft.ReactNative/Fabric/Composition/Composition.Input.h +22 -4
  14. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.cpp +43 -0
  15. package/Microsoft.ReactNative/Fabric/Composition/CompositionDynamicAutomationProvider.h +6 -1
  16. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +147 -119
  17. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +4 -8
  18. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +97 -101
  19. package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.h +28 -52
  20. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +133 -0
  21. package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +61 -0
  22. package/Microsoft.ReactNative/Fabric/Composition/DebuggingOverlayComponentView.cpp +1 -2
  23. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +1 -4
  24. package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +1 -2
  25. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.cpp +1 -6
  26. package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +0 -1
  27. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.cpp +108 -18
  28. package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +33 -5
  29. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +57 -1
  30. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +6 -0
  31. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.cpp +8 -2
  32. package/Microsoft.ReactNative/Fabric/Composition/RootComponentView.h +2 -0
  33. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +195 -182
  34. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.h +1 -3
  35. package/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.cpp +16 -4
  36. package/Microsoft.ReactNative/Fabric/Composition/SwitchComponentView.h +3 -3
  37. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +12 -17
  38. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +4 -11
  39. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.cpp +19 -0
  40. package/Microsoft.ReactNative/Fabric/Composition/UiaHelpers.h +4 -0
  41. package/Microsoft.ReactNative/Fabric/Composition/UnimplementedNativeViewComponentView.cpp +1 -2
  42. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +10 -7
  43. package/Microsoft.ReactNative/Fabric/WindowsComponentDescriptorRegistry.cpp +1 -3
  44. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.cpp +20 -1
  45. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewProps.h +3 -0
  46. package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +13 -3
  47. package/Microsoft.ReactNative/IReactViewComponentBuilder.idl +57 -4
  48. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -0
  49. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  50. package/PropertySheets/WinUI.props +1 -1
  51. package/Shared/Shared.vcxitems +7 -0
  52. package/just-task.js +1 -1
  53. package/package.json +3 -3
@@ -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
  /*
@@ -895,7 +909,6 @@ void ScrollViewComponentView::OnPointerCaptureLost() noexcept {
895
909
  }
896
910
 
897
911
  void ScrollViewComponentView::OnKeyDown(
898
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
899
912
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
900
913
  switch (args.Key()) {
901
914
  case winrt::Windows::System::VirtualKey::End:
@@ -924,7 +937,7 @@ void ScrollViewComponentView::OnKeyDown(
924
937
  break;
925
938
  }
926
939
 
927
- base_type::OnKeyDown(source, args);
940
+ base_type::OnKeyDown(args);
928
941
  }
929
942
 
930
943
  bool ScrollViewComponentView::scrollToEnd(bool animate) noexcept {
@@ -72,9 +72,7 @@ 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
77
  void HandleCommand(winrt::hstring commandName, const winrt::Microsoft::ReactNative::IJSValueReader &args) noexcept
80
78
  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,
@@ -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
@@ -38,9 +38,7 @@ struct SwitchComponentView : SwitchComponentViewT<SwitchComponentView, ViewCompo
38
38
  facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override;
39
39
  void FinalizeUpdates(winrt::Microsoft::ReactNative::ComponentViewUpdateMask updateMask) noexcept override;
40
40
  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;
41
+ void OnKeyUp(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept override;
44
42
  void OnPointerPressed(
45
43
  const winrt::Microsoft::ReactNative::Composition::Input::PointerRoutedEventArgs &args) noexcept override;
46
44
  void OnPointerReleased(
@@ -59,6 +57,8 @@ struct SwitchComponentView : SwitchComponentViewT<SwitchComponentView, ViewCompo
59
57
 
60
58
  static facebook::react::SharedViewProps defaultProps() noexcept;
61
59
  const facebook::react::SwitchProps &switchProps() const noexcept;
60
+ ToggleState getToggleState() noexcept override;
61
+ void Toggle() noexcept override;
62
62
  winrt::Microsoft::ReactNative::Composition::Experimental::IVisual createVisual() noexcept override;
63
63
 
64
64
  private:
@@ -491,8 +491,7 @@ WindowsTextInputComponentView::WindowsTextInputComponentView(
491
491
  compContext,
492
492
  tag,
493
493
  reactContext,
494
- ComponentViewFeatures::Default & ~ComponentViewFeatures::Background,
495
- false) {
494
+ ComponentViewFeatures::Default & ~ComponentViewFeatures::Background) {
496
495
  /*
497
496
  m_textChangedRevoker =
498
497
  m_element.TextChanged(winrt::auto_revoke, [this](auto sender, xaml::Controls::TextChangedEventArgs args) {
@@ -750,12 +749,11 @@ void WindowsTextInputComponentView::OnPointerMoved(
750
749
  }
751
750
 
752
751
  void WindowsTextInputComponentView::OnKeyDown(
753
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
754
752
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
755
753
  // Do not forward tab keys into the TextInput, since we want that to do the tab loop instead. This aligns with WinUI
756
754
  // behavior We do forward Ctrl+Tab to the textinput.
757
755
  if (args.Key() != winrt::Windows::System::VirtualKey::Tab ||
758
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
756
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
759
757
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down) {
760
758
  WPARAM wParam = static_cast<WPARAM>(args.Key());
761
759
  LPARAM lParam = 0;
@@ -776,16 +774,15 @@ void WindowsTextInputComponentView::OnKeyDown(
776
774
  }
777
775
  }
778
776
 
779
- Super::OnKeyDown(source, args);
777
+ Super::OnKeyDown(args);
780
778
  }
781
779
 
782
780
  void WindowsTextInputComponentView::OnKeyUp(
783
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
784
781
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
785
782
  // Do not forward tab keys into the TextInput, since we want that to do the tab loop instead. This aligns with WinUI
786
783
  // behavior We do forward Ctrl+Tab to the textinput.
787
784
  if (args.Key() != winrt::Windows::System::VirtualKey::Tab ||
788
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
785
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
789
786
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down) {
790
787
  WPARAM wParam = static_cast<WPARAM>(args.Key());
791
788
  LPARAM lParam = 1;
@@ -807,11 +804,10 @@ void WindowsTextInputComponentView::OnKeyUp(
807
804
  }
808
805
  }
809
806
 
810
- Super::OnKeyUp(source, args);
807
+ Super::OnKeyUp(args);
811
808
  }
812
809
 
813
810
  bool WindowsTextInputComponentView::ShouldSubmit(
814
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
815
811
  const winrt::Microsoft::ReactNative::Composition::Input::CharacterReceivedRoutedEventArgs &args) noexcept {
816
812
  bool shouldSubmit = true;
817
813
 
@@ -824,19 +820,19 @@ bool WindowsTextInputComponentView::ShouldSubmit(
824
820
  // If 'submitKeyEvents' are supplied, use them to determine whether to emit onSubmitEditing' for either
825
821
  // single-line or multi-line TextInput
826
822
  if (args.KeyCode() == '\r') {
827
- bool shiftDown = (source.GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
823
+ bool shiftDown = (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
828
824
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ==
829
825
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
830
- bool ctrlDown = (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
826
+ bool ctrlDown = (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
831
827
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ==
832
828
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
833
- bool altDown = (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
829
+ bool altDown = (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
834
830
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ==
835
831
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
836
- bool metaDown = (source.GetKeyState(winrt::Windows::System::VirtualKey::LeftWindows) &
832
+ bool metaDown = (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::LeftWindows) &
837
833
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ==
838
834
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down ||
839
- (source.GetKeyState(winrt::Windows::System::VirtualKey::RightWindows) &
835
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::RightWindows) &
840
836
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) ==
841
837
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
842
838
  return (submitKeyEvent.shiftKey && shiftDown) || (submitKeyEvent.ctrlKey && ctrlDown) ||
@@ -854,18 +850,17 @@ bool WindowsTextInputComponentView::ShouldSubmit(
854
850
  }
855
851
 
856
852
  void WindowsTextInputComponentView::OnCharacterReceived(
857
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
858
853
  const winrt::Microsoft::ReactNative::Composition::Input::CharacterReceivedRoutedEventArgs &args) noexcept {
859
854
  // Do not forward tab keys into the TextInput, since we want that to do the tab loop instead. This aligns with WinUI
860
855
  // behavior We do forward Ctrl+Tab to the textinput.
861
856
  if ((args.KeyCode() == '\t') &&
862
- ((source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
857
+ ((args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
863
858
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) != winrt::Microsoft::UI::Input::VirtualKeyStates::Down)) {
864
859
  return;
865
860
  }
866
861
 
867
862
  // Logic for submit events
868
- if (ShouldSubmit(source, args)) {
863
+ if (ShouldSubmit(args)) {
869
864
  // call onSubmitEditing event
870
865
  if (m_eventEmitter && !m_comingFromJS) {
871
866
  auto emitter = std::static_pointer_cast<const facebook::react::WindowsTextInputEventEmitter>(m_eventEmitter);