react-native-windows 0.74.19 → 0.74.21

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 (76) 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/ReactHost/ReactInstanceWin.cpp +14 -32
  49. package/Microsoft.ReactNative/ReactNativeIsland.idl +3 -0
  50. package/PropertySheets/External/Microsoft.ReactNative.Composition.Package.props +1 -0
  51. package/PropertySheets/External/Microsoft.ReactNative.Composition.Package.targets +4 -0
  52. package/PropertySheets/External/Microsoft.ReactNative.Cpp.PackageReferences.props +14 -4
  53. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  54. package/PropertySheets/WinUI.props +1 -1
  55. package/Scripts/Microsoft.ReactNative.VersionCheck.targets +2 -0
  56. package/Shared/Shared.vcxitems +7 -0
  57. package/Shared/Shared.vcxitems.filters +1 -0
  58. package/just-task.js +1 -1
  59. package/package.json +3 -3
  60. package/template/cpp-app/proj/MyApp.sln +19 -19
  61. package/template/cpp-lib/proj/MyLib.sln +19 -19
  62. package/template/cs-app/proj/MyApp.sln +21 -21
  63. package/template/cs-lib/proj/MyLib.sln +21 -21
  64. package/template/metro.config.js +13 -2
  65. package/templates/cpp-app/NuGet_Config +13 -0
  66. package/templates/cpp-app/template.config.js +11 -1
  67. package/templates/cpp-app/windows/ExperimentalFeatures.props +1 -0
  68. package/templates/cpp-app/windows/MyApp.sln +29 -19
  69. package/templates/cpp-lib/NuGet_Config +13 -0
  70. package/templates/cpp-lib/example/NuGet_Config +6 -0
  71. package/templates/cpp-lib/template.config.js +11 -1
  72. package/templates/cpp-lib/windows/ExperimentalFeatures.props +1 -0
  73. package/templates/cpp-lib/windows/MyLib.sln +35 -25
  74. package/templates/old/generateWrapper.js +7 -4
  75. package/templates/templateUtils.js +3 -1
  76. package/template/metro.devMode.config.js +0 -56
@@ -140,149 +140,170 @@ struct CompositionInputKeyboardSource : winrt::implements<
140
140
  CompositionEventHandler::CompositionEventHandler(
141
141
  const winrt::Microsoft::ReactNative::ReactContext &context,
142
142
  const winrt::Microsoft::ReactNative::ReactNativeIsland &reactNativeIsland)
143
- : m_context(context), m_wkRootView(reactNativeIsland) {
143
+ : m_context(context), m_wkRootView(reactNativeIsland) {}
144
+
145
+ void CompositionEventHandler::Initialize() noexcept {
144
146
  #ifdef USE_WINUI3
145
- if (auto island = reactNativeIsland.Island()) {
147
+ if (auto island = m_wkRootView.get().Island()) {
146
148
  auto pointerSource = winrt::Microsoft::UI::Input::InputPointerSource::GetForIsland(island);
147
149
 
148
150
  m_pointerPressedToken =
149
- pointerSource.PointerPressed([this](
151
+ pointerSource.PointerPressed([wkThis = weak_from_this()](
150
152
  winrt::Microsoft::UI::Input::InputPointerSource const &,
151
153
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
152
- if (auto strongRootView = m_wkRootView.get()) {
153
- if (SurfaceId() == -1)
154
- return;
155
-
156
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
157
- args.CurrentPoint(), strongRootView.ScaleFactor());
158
- onPointerPressed(pp, args.KeyModifiers());
154
+ if (auto strongThis = wkThis.lock()) {
155
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
156
+ if (strongThis->SurfaceId() == -1)
157
+ return;
158
+
159
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
160
+ args.CurrentPoint(), strongRootView.ScaleFactor());
161
+ strongThis->onPointerPressed(pp, args.KeyModifiers());
162
+ }
159
163
  }
160
164
  });
161
165
 
162
166
  m_pointerReleasedToken =
163
- pointerSource.PointerReleased([this](
167
+ pointerSource.PointerReleased([wkThis = weak_from_this()](
164
168
  winrt::Microsoft::UI::Input::InputPointerSource const &,
165
169
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
166
- if (auto strongRootView = m_wkRootView.get()) {
167
- if (SurfaceId() == -1)
168
- return;
169
-
170
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
171
- args.CurrentPoint(), strongRootView.ScaleFactor());
172
- onPointerReleased(pp, args.KeyModifiers());
170
+ if (auto strongThis = wkThis.lock()) {
171
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
172
+ if (strongThis->SurfaceId() == -1)
173
+ return;
174
+
175
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
176
+ args.CurrentPoint(), strongRootView.ScaleFactor());
177
+ strongThis->onPointerReleased(pp, args.KeyModifiers());
178
+ }
173
179
  }
174
180
  });
175
181
 
176
- m_pointerMovedToken = pointerSource.PointerMoved([this](
182
+ m_pointerMovedToken = pointerSource.PointerMoved([wkThis = weak_from_this()](
177
183
  winrt::Microsoft::UI::Input::InputPointerSource const &,
178
184
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
179
- if (auto strongRootView = m_wkRootView.get()) {
180
- if (SurfaceId() == -1)
181
- return;
182
-
183
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
184
- args.CurrentPoint(), strongRootView.ScaleFactor());
185
- onPointerMoved(pp, args.KeyModifiers());
185
+ if (auto strongThis = wkThis.lock()) {
186
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
187
+ if (strongThis->SurfaceId() == -1)
188
+ return;
189
+
190
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
191
+ args.CurrentPoint(), strongRootView.ScaleFactor());
192
+ strongThis->onPointerMoved(pp, args.KeyModifiers());
193
+ }
186
194
  }
187
195
  });
188
196
 
189
197
  m_pointerCaptureLostToken =
190
- pointerSource.PointerCaptureLost([this](
198
+ pointerSource.PointerCaptureLost([wkThis = weak_from_this()](
191
199
  winrt::Microsoft::UI::Input::InputPointerSource const &,
192
200
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
193
- if (auto strongRootView = m_wkRootView.get()) {
194
- if (SurfaceId() == -1)
195
- return;
196
-
197
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
198
- args.CurrentPoint(), strongRootView.ScaleFactor());
199
- onPointerCaptureLost(pp, args.KeyModifiers());
201
+ if (auto strongThis = wkThis.lock()) {
202
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
203
+ if (strongThis->SurfaceId() == -1)
204
+ return;
205
+
206
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
207
+ args.CurrentPoint(), strongRootView.ScaleFactor());
208
+ strongThis->onPointerCaptureLost(pp, args.KeyModifiers());
209
+ }
200
210
  }
201
211
  });
202
212
 
203
213
  m_pointerWheelChangedToken =
204
- pointerSource.PointerWheelChanged([this](
214
+ pointerSource.PointerWheelChanged([wkThis = weak_from_this()](
205
215
  winrt::Microsoft::UI::Input::InputPointerSource const &,
206
216
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
207
- if (auto strongRootView = m_wkRootView.get()) {
208
- if (SurfaceId() == -1)
209
- return;
210
-
211
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
212
- args.CurrentPoint(), strongRootView.ScaleFactor());
213
- onPointerWheelChanged(pp, args.KeyModifiers());
217
+ if (auto strongThis = wkThis.lock()) {
218
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
219
+ if (strongThis->SurfaceId() == -1)
220
+ return;
221
+
222
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
223
+ args.CurrentPoint(), strongRootView.ScaleFactor());
224
+ strongThis->onPointerWheelChanged(pp, args.KeyModifiers());
225
+ }
214
226
  }
215
227
  });
216
228
 
217
229
  auto keyboardSource = winrt::Microsoft::UI::Input::InputKeyboardSource::GetForIsland(island);
218
230
 
219
- m_keyDownToken = keyboardSource.KeyDown([this](
231
+ m_keyDownToken = keyboardSource.KeyDown([wkThis = weak_from_this()](
220
232
  winrt::Microsoft::UI::Input::InputKeyboardSource const &source,
221
233
  winrt::Microsoft::UI::Input::KeyEventArgs const &args) {
222
- if (auto strongRootView = m_wkRootView.get()) {
223
- if (SurfaceId() == -1)
224
- return;
225
-
226
- auto focusedComponent = RootComponentView().GetFocusedComponent();
227
- auto keyArgs =
228
- winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
229
- focusedComponent
230
- ? focusedComponent.Tag()
231
- : static_cast<facebook::react::Tag>(
232
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(
233
- strongRootView)
234
- ->RootTag()),
235
- args);
236
- auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
237
- onKeyDown(keyboardSource, keyArgs);
238
- winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
234
+ if (auto strongThis = wkThis.lock()) {
235
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
236
+ if (strongThis->SurfaceId() == -1)
237
+ return;
238
+
239
+ auto focusedComponent = strongThis->RootComponentView().GetFocusedComponent();
240
+ auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
241
+ auto keyArgs =
242
+ winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
243
+ focusedComponent
244
+ ? focusedComponent.Tag()
245
+ : static_cast<facebook::react::Tag>(
246
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(
247
+ strongRootView)
248
+ ->RootTag()),
249
+ args,
250
+ keyboardSource);
251
+ strongThis->onKeyDown(keyArgs);
252
+ winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
253
+ }
239
254
  }
240
255
  });
241
256
 
242
- m_keyUpToken = keyboardSource.KeyUp([this](
257
+ m_keyUpToken = keyboardSource.KeyUp([wkThis = weak_from_this()](
243
258
  winrt::Microsoft::UI::Input::InputKeyboardSource const &source,
244
259
  winrt::Microsoft::UI::Input::KeyEventArgs const &args) {
245
- if (auto strongRootView = m_wkRootView.get()) {
246
- if (SurfaceId() == -1)
247
- return;
248
-
249
- auto focusedComponent = RootComponentView().GetFocusedComponent();
250
- auto keyArgs =
251
- winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
252
- focusedComponent
253
- ? focusedComponent.Tag()
254
- : static_cast<facebook::react::Tag>(
255
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(
256
- strongRootView)
257
- ->RootTag()),
258
- args);
259
- auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
260
- onKeyUp(keyboardSource, keyArgs);
261
- winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
260
+ if (auto strongThis = wkThis.lock()) {
261
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
262
+ if (strongThis->SurfaceId() == -1)
263
+ return;
264
+
265
+ auto focusedComponent = strongThis->RootComponentView().GetFocusedComponent();
266
+ auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
267
+ auto keyArgs =
268
+ winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
269
+ focusedComponent
270
+ ? focusedComponent.Tag()
271
+ : static_cast<facebook::react::Tag>(
272
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(
273
+ strongRootView)
274
+ ->RootTag()),
275
+ args,
276
+ keyboardSource);
277
+ strongThis->onKeyUp(keyArgs);
278
+ winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
279
+ }
262
280
  }
263
281
  });
264
282
 
265
283
  m_characterReceivedToken =
266
- keyboardSource.CharacterReceived([this](
284
+ keyboardSource.CharacterReceived([wkThis = weak_from_this()](
267
285
  winrt::Microsoft::UI::Input::InputKeyboardSource const &source,
268
286
  winrt::Microsoft::UI::Input::CharacterReceivedEventArgs const &args) {
269
- if (auto strongRootView = m_wkRootView.get()) {
270
- if (SurfaceId() == -1)
271
- return;
272
-
273
- auto focusedComponent = RootComponentView().GetFocusedComponent();
274
- auto charArgs = winrt::make<
275
- winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
276
- focusedComponent
277
- ? focusedComponent.Tag()
278
- : static_cast<facebook::react::Tag>(
279
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(
280
- strongRootView)
281
- ->RootTag()),
282
- args);
283
- auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
284
- onCharacterReceived(keyboardSource, charArgs);
285
- winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
287
+ if (auto strongThis = wkThis.lock()) {
288
+ if (auto strongRootView = strongThis->m_wkRootView.get()) {
289
+ if (strongThis->SurfaceId() == -1)
290
+ return;
291
+
292
+ auto focusedComponent = strongThis->RootComponentView().GetFocusedComponent();
293
+ auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
294
+ auto charArgs = winrt::make<
295
+ winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
296
+ focusedComponent
297
+ ? focusedComponent.Tag()
298
+ : static_cast<facebook::react::Tag>(
299
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ReactNativeIsland>(
300
+ strongRootView)
301
+ ->RootTag()),
302
+ args,
303
+ keyboardSource);
304
+ strongThis->onCharacterReceived(charArgs);
305
+ winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
306
+ }
286
307
  }
287
308
  });
288
309
  }
@@ -344,7 +365,8 @@ void CompositionEventHandler::onPointerWheelChanged(
344
365
  auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerRoutedEventArgs>(
345
366
  m_context, tag, pointerPoint, keyModifiers);
346
367
 
347
- targetComponentView.OnPointerWheelChanged(args);
368
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
369
+ ->OnPointerWheelChanged(args);
348
370
  }
349
371
  }
350
372
 
@@ -441,6 +463,7 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
441
463
  case WM_SYSCHAR: {
442
464
  if (auto strongRootView = m_wkRootView.get()) {
443
465
  auto focusedComponent = RootComponentView().GetFocusedComponent();
466
+ auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
444
467
  auto args = winrt::make<
445
468
  winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
446
469
  focusedComponent
@@ -450,9 +473,9 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
450
473
  ->RootTag()),
451
474
  msg,
452
475
  wParam,
453
- lParam);
454
- auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
455
- onCharacterReceived(keyboardSource, args);
476
+ lParam,
477
+ keyboardSource);
478
+ onCharacterReceived(args);
456
479
  winrt::get_self<CompositionKeyboardSource>(keyboardSource)->Disconnect();
457
480
  }
458
481
  break;
@@ -463,6 +486,7 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
463
486
  case WM_SYSKEYUP: {
464
487
  if (auto strongRootView = m_wkRootView.get()) {
465
488
  auto focusedComponent = RootComponentView().GetFocusedComponent();
489
+ auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
466
490
  auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
467
491
  focusedComponent
468
492
  ? focusedComponent.Tag()
@@ -471,12 +495,12 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
471
495
  ->RootTag()),
472
496
  msg,
473
497
  wParam,
474
- lParam);
475
- auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
498
+ lParam,
499
+ keyboardSource);
476
500
  if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
477
- onKeyDown(keyboardSource, args);
501
+ onKeyDown(args);
478
502
  } else {
479
- onKeyUp(keyboardSource, args);
503
+ onKeyUp(args);
480
504
  }
481
505
  winrt::get_self<CompositionKeyboardSource>(keyboardSource)->Disconnect();
482
506
  }
@@ -488,20 +512,19 @@ int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t w
488
512
  }
489
513
 
490
514
  void CompositionEventHandler::onKeyDown(
491
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
492
515
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
493
516
  if (auto focusedComponent = RootComponentView().GetFocusedComponent()) {
494
- focusedComponent.OnKeyDown(source, args);
517
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(focusedComponent)->OnKeyDown(args);
495
518
 
496
519
  if (args.Handled())
497
520
  return;
498
521
  }
499
522
 
500
523
  bool fShift =
501
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
524
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Shift) &
502
525
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
503
526
  bool fCtrl =
504
- (source.GetKeyState(winrt::Windows::System::VirtualKey::Control) &
527
+ (args.KeyboardSource().GetKeyState(winrt::Windows::System::VirtualKey::Control) &
505
528
  winrt::Microsoft::UI::Input::VirtualKeyStates::Down) == winrt::Microsoft::UI::Input::VirtualKeyStates::Down;
506
529
 
507
530
  if (fShift && fCtrl && args.Key() == static_cast<winrt::Windows::System::VirtualKey>(VkKeyScanA('d')) &&
@@ -522,10 +545,9 @@ void CompositionEventHandler::onKeyDown(
522
545
  }
523
546
 
524
547
  void CompositionEventHandler::onKeyUp(
525
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
526
548
  const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept {
527
549
  if (auto focusedComponent = RootComponentView().GetFocusedComponent()) {
528
- focusedComponent.OnKeyUp(source, args);
550
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(focusedComponent)->OnKeyUp(args);
529
551
 
530
552
  if (args.Handled())
531
553
  return;
@@ -533,10 +555,10 @@ void CompositionEventHandler::onKeyUp(
533
555
  }
534
556
 
535
557
  void CompositionEventHandler::onCharacterReceived(
536
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
537
558
  const winrt::Microsoft::ReactNative::Composition::Input::CharacterReceivedRoutedEventArgs &args) noexcept {
538
559
  if (auto focusedComponent = RootComponentView().GetFocusedComponent()) {
539
- focusedComponent.OnCharacterReceived(source, args);
560
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(focusedComponent)
561
+ ->OnCharacterReceived(args);
540
562
 
541
563
  if (args.Handled())
542
564
  return;
@@ -624,7 +646,8 @@ void CompositionEventHandler::HandleIncomingPointerEvent(
624
646
  auto args =
625
647
  winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerRoutedEventArgs>(
626
648
  m_context, componentView.Tag(), pointerPoint, keyModifiers);
627
- componentView.OnPointerEntered(args);
649
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(componentView)
650
+ ->OnPointerEntered(args);
628
651
 
629
652
  if (shouldEmitEvent) {
630
653
  const auto eventEmitter =
@@ -702,7 +725,7 @@ void CompositionEventHandler::HandleIncomingPointerEvent(
702
725
 
703
726
  auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerRoutedEventArgs>(
704
727
  m_context, componentView.Tag(), pointerPoint, keyModifiers);
705
- componentView.OnPointerExited(args);
728
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(componentView)->OnPointerExited(args);
706
729
  }
707
730
 
708
731
  for (auto itComponentView = viewsToEmitJSLeaveEventsTo.rbegin(); itComponentView != viewsToEmitJSLeaveEventsTo.rend();
@@ -853,7 +876,8 @@ void CompositionEventHandler::onPointerMoved(
853
876
  m_context, tag, pointerPoint, keyModifiers);
854
877
  auto targetComponentView = fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(tag).view;
855
878
 
856
- targetComponentView.OnPointerMoved(args);
879
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
880
+ ->OnPointerMoved(args);
857
881
 
858
882
  auto targetView = FindClosestFabricManagedTouchableView(
859
883
  fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(tag).view);
@@ -907,7 +931,8 @@ void CompositionEventHandler::onPointerPressed(
907
931
  auto targetComponentView = fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(tag).view;
908
932
  auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerRoutedEventArgs>(
909
933
  m_context, tag, pointerPoint, keyModifiers);
910
- targetComponentView.OnPointerPressed(args);
934
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
935
+ ->OnPointerPressed(args);
911
936
 
912
937
  ActiveTouch activeTouch{0};
913
938
  activeTouch.touchType = UITouchType::Mouse;
@@ -968,7 +993,8 @@ void CompositionEventHandler::onPointerReleased(
968
993
  auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerRoutedEventArgs>(
969
994
  m_context, tag, pointerPoint, keyModifiers);
970
995
 
971
- targetComponentView.OnPointerReleased(args);
996
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
997
+ ->OnPointerReleased(args);
972
998
 
973
999
  UpdateActiveTouch(activeTouch->second, ptScaled, ptLocal);
974
1000
  DispatchTouchEvent(TouchEventType::End, pointerId, pointerPoint, keyModifiers);
@@ -987,7 +1013,8 @@ bool CompositionEventHandler::CapturePointer(
987
1013
  auto targetComponentView =
988
1014
  fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(m_pointerCapturingComponentTag).view;
989
1015
 
990
- targetComponentView.OnPointerCaptureLost();
1016
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
1017
+ ->OnPointerCaptureLost();
991
1018
  }
992
1019
  }
993
1020
 
@@ -1018,7 +1045,8 @@ bool CompositionEventHandler::releasePointerCapture(PointerId pointerId, faceboo
1018
1045
  auto targetComponentView =
1019
1046
  fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(m_pointerCapturingComponentTag).view;
1020
1047
 
1021
- targetComponentView.OnPointerCaptureLost();
1048
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
1049
+ ->OnPointerCaptureLost();
1022
1050
  }
1023
1051
 
1024
1052
  if (m_capturedPointers.size() == 0) {
@@ -27,13 +27,14 @@ struct FabricUIManager;
27
27
  struct winrt::Microsoft::ReactNative::implementation::ComponentView;
28
28
  typedef int PointerId;
29
29
 
30
- class CompositionEventHandler {
30
+ class CompositionEventHandler : public std::enable_shared_from_this<CompositionEventHandler> {
31
31
  public:
32
32
  CompositionEventHandler(
33
33
  const winrt::Microsoft::ReactNative::ReactContext &context,
34
34
  const winrt::Microsoft::ReactNative::ReactNativeIsland &ReactNativeIsland);
35
35
  virtual ~CompositionEventHandler();
36
36
 
37
+ void Initialize() noexcept;
37
38
  int64_t SendMessage(HWND hwnd, uint32_t msg, uint64_t wParam, int64_t lParam) noexcept;
38
39
  void RemoveTouchHandlers();
39
40
  winrt::Microsoft::UI::Input::VirtualKeyStates GetKeyState(winrt::Windows::System::VirtualKey key) noexcept;
@@ -62,14 +63,9 @@ class CompositionEventHandler {
62
63
  void onPointerCaptureLost(
63
64
  const winrt::Microsoft::ReactNative::Composition::Input::PointerPoint &pointerPoint,
64
65
  winrt::Windows::System::VirtualKeyModifiers keyModifiers) noexcept;
65
- void onKeyDown(
66
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
67
- const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept;
68
- void onKeyUp(
69
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
70
- const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept;
66
+ void onKeyDown(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept;
67
+ void onKeyUp(const winrt::Microsoft::ReactNative::Composition::Input::KeyRoutedEventArgs &args) noexcept;
71
68
  void onCharacterReceived(
72
- const winrt::Microsoft::ReactNative::Composition::Input::KeyboardSource &source,
73
69
  const winrt::Microsoft::ReactNative::Composition::Input::CharacterReceivedRoutedEventArgs &args) noexcept;
74
70
 
75
71
  void getTargetPointerArgs(