react-native-windows 0.74.0 → 0.74.2

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 (37) hide show
  1. package/Libraries/Components/Touchable/TouchableBounce.js +1 -0
  2. package/Libraries/Components/Touchable/TouchableOpacity.js +1 -0
  3. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +1 -0
  4. package/Libraries/Core/ReactNativeVersion.js +2 -2
  5. package/Microsoft.ReactNative/CompositionRootView.idl +4 -2
  6. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.cpp +6 -0
  7. package/Microsoft.ReactNative/Fabric/Composition/CompositionContextHelper.h +2 -0
  8. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +188 -141
  9. package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.h +1 -1
  10. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootView.cpp +41 -34
  11. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootView.h +5 -1
  12. package/Microsoft.ReactNative/Fabric/Composition/CompositionRootView_emptyimpl.cpp +7 -0
  13. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +26 -13
  14. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h +3 -2
  15. package/Microsoft.ReactNative/Fabric/Composition/ImageResponseImage.h +17 -0
  16. package/Microsoft.ReactNative/Fabric/Composition/Theme.cpp +28 -10
  17. package/Microsoft.ReactNative/Fabric/Composition/Theme.h +4 -3
  18. package/Microsoft.ReactNative/Fabric/Composition/Theme_emptyimpl.cpp +2 -6
  19. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +82 -0
  20. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.h +39 -0
  21. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager_emptyimpl.cpp +16 -0
  22. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +3 -0
  23. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +2 -0
  24. package/Microsoft.ReactNative/Fabric/ImageManager.cpp +3 -2
  25. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +102 -35
  26. package/Microsoft.ReactNative/Fabric/WindowsImageManager.h +6 -1
  27. package/Microsoft.ReactNative/Theme.idl +1 -2
  28. package/Microsoft.ReactNative/UriImageManager.idl +85 -0
  29. package/Microsoft.ReactNative.Cxx/AutoDraw.h +1 -0
  30. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  31. package/Shared/Shared.vcxitems +11 -0
  32. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +33 -21
  33. package/codegen/rnwcoreJSI-generated.cpp +18 -6
  34. package/codegen/rnwcoreJSI.h +27 -9
  35. package/package.json +14 -14
  36. package/src/private/featureflags/NativeReactNativeFeatureFlags.js +4 -2
  37. package/src/private/featureflags/ReactNativeFeatureFlags.js +16 -6
@@ -209,6 +209,7 @@ class TouchableBounce extends React.Component<Props, State> {
209
209
 
210
210
  componentWillUnmount(): void {
211
211
  this.state.pressability.reset();
212
+ this.state.scale.resetAnimation();
212
213
  }
213
214
  }
214
215
 
@@ -320,6 +320,7 @@ class TouchableOpacity extends React.Component<Props, State> {
320
320
 
321
321
  componentWillUnmount(): void {
322
322
  this.state.pressability.reset();
323
+ this.state.anim.resetAnimation();
323
324
  }
324
325
  }
325
326
 
@@ -335,6 +335,7 @@ class TouchableOpacity extends React.Component<Props, State> {
335
335
 
336
336
  componentWillUnmount(): void {
337
337
  this.state.pressability.reset();
338
+ this.state.anim.resetAnimation();
338
339
  }
339
340
  }
340
341
 
@@ -16,8 +16,8 @@ const version: $ReadOnly<{
16
16
  }> = {
17
17
  major: 0,
18
18
  minor: 74,
19
- patch: 0,
20
- prerelease: 'rc.9',
19
+ patch: 1,
20
+ prerelease: null,
21
21
  };
22
22
 
23
23
  module.exports = {version};
@@ -95,8 +95,10 @@ namespace Microsoft.ReactNative
95
95
 
96
96
  Object GetUiaProvider();
97
97
 
98
- DOC_STRING("Theme used for Platform colors within this RootView")
99
- Microsoft.ReactNative.Composition.Theme Theme;
98
+ DOC_STRING("Provides resources used for Platform colors within this RootView")
99
+ Microsoft.ReactNative.Composition.ICustomResourceLoader Resources;
100
+
101
+ Microsoft.ReactNative.Composition.Theme Theme { get; };
100
102
 
101
103
  #ifdef USE_WINUI3
102
104
  Microsoft.UI.Content.ContentIsland Island { get; };
@@ -1966,6 +1966,12 @@ winrt::Microsoft::UI::Composition::ICompositionSurface MicrosoftCompositionConte
1966
1966
  surface.try_as(s);
1967
1967
  return s ? s->Inner() : nullptr;
1968
1968
  }
1969
+
1970
+ winrt::Microsoft::ReactNative::Composition::Experimental::IBrush MicrosoftCompositionContextHelper::WrapBrush(
1971
+ const winrt::Microsoft::UI::Composition::CompositionBrush &brush) noexcept {
1972
+ return winrt::make<::Microsoft::ReactNative::Composition::Experimental::MicrosoftCompBrush>(brush);
1973
+ }
1974
+
1969
1975
  #endif
1970
1976
 
1971
1977
  } // namespace winrt::Microsoft::ReactNative::Composition::Experimental::implementation
@@ -45,6 +45,8 @@ struct MicrosoftCompositionContextHelper : MicrosoftCompositionContextHelperT<Mi
45
45
  static winrt::Microsoft::UI::Composition::DropShadow InnerDropShadow(IDropShadow shadow) noexcept;
46
46
  static winrt::Microsoft::UI::Composition::CompositionBrush InnerBrush(IBrush brush) noexcept;
47
47
  static winrt::Microsoft::UI::Composition::ICompositionSurface InnerSurface(IDrawingSurfaceBrush surface) noexcept;
48
+
49
+ static IBrush WrapBrush(const winrt::Microsoft::UI::Composition::CompositionBrush &brush) noexcept;
48
50
  };
49
51
  #endif
50
52
 
@@ -152,67 +152,78 @@ struct CompositionInputKeyboardSource : winrt::implements<
152
152
  CompositionEventHandler::CompositionEventHandler(
153
153
  const winrt::Microsoft::ReactNative::ReactContext &context,
154
154
  const winrt::Microsoft::ReactNative::CompositionRootView &CompositionRootView)
155
- : m_context(context) {
156
- m_compRootView = CompositionRootView;
157
-
155
+ : m_context(context), m_wkRootView(CompositionRootView) {
158
156
  #ifdef USE_WINUI3
159
- if (auto island = m_compRootView.Island()) {
157
+ if (auto island = CompositionRootView.Island()) {
160
158
  auto pointerSource = winrt::Microsoft::UI::Input::InputPointerSource::GetForIsland(island);
161
159
 
162
160
  m_pointerPressedToken =
163
161
  pointerSource.PointerPressed([this](
164
162
  winrt::Microsoft::UI::Input::InputPointerSource const &,
165
163
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
166
- if (SurfaceId() == -1)
167
- return;
164
+ if (auto strongRootView = m_wkRootView.get()) {
165
+ if (SurfaceId() == -1)
166
+ return;
168
167
 
169
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
170
- args.CurrentPoint(), m_compRootView.ScaleFactor());
171
- onPointerPressed(pp, args.KeyModifiers());
168
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
169
+ args.CurrentPoint(), strongRootView.ScaleFactor());
170
+ onPointerPressed(pp, args.KeyModifiers());
171
+ }
172
172
  });
173
173
 
174
174
  m_pointerReleasedToken =
175
175
  pointerSource.PointerReleased([this](
176
176
  winrt::Microsoft::UI::Input::InputPointerSource const &,
177
177
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
178
- if (SurfaceId() == -1)
179
- return;
178
+ if (auto strongRootView = m_wkRootView.get()) {
179
+ if (SurfaceId() == -1)
180
+ return;
180
181
 
181
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
182
- args.CurrentPoint(), m_compRootView.ScaleFactor());
183
- onPointerReleased(pp, args.KeyModifiers());
182
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
183
+ args.CurrentPoint(), strongRootView.ScaleFactor());
184
+ onPointerReleased(pp, args.KeyModifiers());
185
+ }
184
186
  });
185
187
 
186
188
  m_pointerMovedToken = pointerSource.PointerMoved([this](
187
189
  winrt::Microsoft::UI::Input::InputPointerSource const &,
188
190
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
189
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
190
- args.CurrentPoint(), m_compRootView.ScaleFactor());
191
- onPointerMoved(pp, args.KeyModifiers());
191
+ if (auto strongRootView = m_wkRootView.get()) {
192
+ if (SurfaceId() == -1)
193
+ return;
194
+
195
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
196
+ args.CurrentPoint(), strongRootView.ScaleFactor());
197
+ onPointerMoved(pp, args.KeyModifiers());
198
+ }
192
199
  });
193
200
 
194
201
  m_pointerCaptureLostToken =
195
202
  pointerSource.PointerCaptureLost([this](
196
203
  winrt::Microsoft::UI::Input::InputPointerSource const &,
197
204
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
198
- if (SurfaceId() == -1)
199
- return;
205
+ if (auto strongRootView = m_wkRootView.get()) {
206
+ if (SurfaceId() == -1)
207
+ return;
200
208
 
201
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
202
- args.CurrentPoint(), m_compRootView.ScaleFactor());
203
- onPointerCaptureLost(pp, args.KeyModifiers());
209
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
210
+ args.CurrentPoint(), strongRootView.ScaleFactor());
211
+ onPointerCaptureLost(pp, args.KeyModifiers());
212
+ }
204
213
  });
205
214
 
206
215
  m_pointerWheelChangedToken =
207
216
  pointerSource.PointerWheelChanged([this](
208
217
  winrt::Microsoft::UI::Input::InputPointerSource const &,
209
218
  winrt::Microsoft::UI::Input::PointerEventArgs const &args) {
210
- if (SurfaceId() == -1)
211
- return;
219
+ if (auto strongRootView = m_wkRootView.get()) {
220
+ if (SurfaceId() == -1)
221
+ return;
212
222
 
213
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
214
- args.CurrentPoint(), m_compRootView.ScaleFactor());
215
- onPointerWheelChanged(pp, args.KeyModifiers());
223
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
224
+ args.CurrentPoint(), strongRootView.ScaleFactor());
225
+ onPointerWheelChanged(pp, args.KeyModifiers());
226
+ }
216
227
  });
217
228
 
218
229
  auto keyboardSource = winrt::Microsoft::UI::Input::InputKeyboardSource::GetForIsland(island);
@@ -220,61 +231,71 @@ CompositionEventHandler::CompositionEventHandler(
220
231
  m_keyDownToken = keyboardSource.KeyDown([this](
221
232
  winrt::Microsoft::UI::Input::InputKeyboardSource const &source,
222
233
  winrt::Microsoft::UI::Input::KeyEventArgs const &args) {
223
- if (SurfaceId() == -1)
224
- return;
225
-
226
- auto focusedComponent = RootComponentView().GetFocusedComponent();
227
- auto keyArgs = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
228
- focusedComponent
229
- ? focusedComponent.Tag()
230
- : static_cast<facebook::react::Tag>(
231
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(m_compRootView)
232
- ->GetTag()),
233
- args);
234
- auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
235
- onKeyDown(keyboardSource, keyArgs);
236
- winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
234
+ if (auto strongRootView = m_wkRootView.get()) {
235
+ if (SurfaceId() == -1)
236
+ return;
237
+
238
+ auto focusedComponent = RootComponentView().GetFocusedComponent();
239
+ auto keyArgs =
240
+ winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
241
+ focusedComponent
242
+ ? focusedComponent.Tag()
243
+ : static_cast<facebook::react::Tag>(
244
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
245
+ strongRootView)
246
+ ->GetTag()),
247
+ args);
248
+ auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
249
+ onKeyDown(keyboardSource, keyArgs);
250
+ winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
251
+ }
237
252
  });
238
253
 
239
254
  m_keyUpToken = keyboardSource.KeyUp([this](
240
255
  winrt::Microsoft::UI::Input::InputKeyboardSource const &source,
241
256
  winrt::Microsoft::UI::Input::KeyEventArgs const &args) {
242
- if (SurfaceId() == -1)
243
- return;
244
-
245
- auto focusedComponent = RootComponentView().GetFocusedComponent();
246
- auto keyArgs = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
247
- focusedComponent
248
- ? focusedComponent.Tag()
249
- : static_cast<facebook::react::Tag>(
250
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(m_compRootView)
251
- ->GetTag()),
252
- args);
253
- auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
254
- onKeyUp(keyboardSource, keyArgs);
255
- winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
257
+ if (auto strongRootView = m_wkRootView.get()) {
258
+ if (SurfaceId() == -1)
259
+ return;
260
+
261
+ auto focusedComponent = RootComponentView().GetFocusedComponent();
262
+ auto keyArgs =
263
+ winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
264
+ focusedComponent
265
+ ? focusedComponent.Tag()
266
+ : static_cast<facebook::react::Tag>(
267
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
268
+ strongRootView)
269
+ ->GetTag()),
270
+ args);
271
+ auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
272
+ onKeyUp(keyboardSource, keyArgs);
273
+ winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
274
+ }
256
275
  });
257
276
 
258
277
  m_characterReceivedToken =
259
278
  keyboardSource.CharacterReceived([this](
260
279
  winrt::Microsoft::UI::Input::InputKeyboardSource const &source,
261
280
  winrt::Microsoft::UI::Input::CharacterReceivedEventArgs const &args) {
262
- if (SurfaceId() == -1)
263
- return;
264
-
265
- auto focusedComponent = RootComponentView().GetFocusedComponent();
266
- auto charArgs = winrt::make<
267
- winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
268
- focusedComponent
269
- ? focusedComponent.Tag()
270
- : static_cast<facebook::react::Tag>(
271
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
272
- m_compRootView)
273
- ->GetTag()),
274
- args);
275
- auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
276
- onCharacterReceived(keyboardSource, charArgs);
277
- winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
281
+ if (auto strongRootView = m_wkRootView.get()) {
282
+ if (SurfaceId() == -1)
283
+ return;
284
+
285
+ auto focusedComponent = RootComponentView().GetFocusedComponent();
286
+ auto charArgs = winrt::make<
287
+ winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
288
+ focusedComponent
289
+ ? focusedComponent.Tag()
290
+ : static_cast<facebook::react::Tag>(
291
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
292
+ strongRootView)
293
+ ->GetTag()),
294
+ args);
295
+ auto keyboardSource = winrt::make<CompositionInputKeyboardSource>(source);
296
+ onCharacterReceived(keyboardSource, charArgs);
297
+ winrt::get_self<CompositionInputKeyboardSource>(keyboardSource)->Disconnect();
298
+ }
278
299
  });
279
300
  }
280
301
  #endif
@@ -282,24 +303,29 @@ CompositionEventHandler::CompositionEventHandler(
282
303
 
283
304
  CompositionEventHandler::~CompositionEventHandler() {
284
305
  #ifdef USE_WINUI3
285
- if (auto island = m_compRootView.Island()) {
286
- auto pointerSource = winrt::Microsoft::UI::Input::InputPointerSource::GetForIsland(island);
287
- pointerSource.PointerPressed(m_pointerPressedToken);
288
- pointerSource.PointerReleased(m_pointerReleasedToken);
289
- pointerSource.PointerMoved(m_pointerMovedToken);
290
- pointerSource.PointerCaptureLost(m_pointerCaptureLostToken);
291
- pointerSource.PointerWheelChanged(m_pointerWheelChangedToken);
292
- auto keyboardSource = winrt::Microsoft::UI::Input::InputKeyboardSource::GetForIsland(island);
293
- keyboardSource.KeyDown(m_keyDownToken);
294
- keyboardSource.KeyUp(m_keyUpToken);
295
- keyboardSource.CharacterReceived(m_characterReceivedToken);
306
+ if (auto strongRootView = m_wkRootView.get()) {
307
+ if (auto island = strongRootView.Island()) {
308
+ auto pointerSource = winrt::Microsoft::UI::Input::InputPointerSource::GetForIsland(island);
309
+ pointerSource.PointerPressed(m_pointerPressedToken);
310
+ pointerSource.PointerReleased(m_pointerReleasedToken);
311
+ pointerSource.PointerMoved(m_pointerMovedToken);
312
+ pointerSource.PointerCaptureLost(m_pointerCaptureLostToken);
313
+ pointerSource.PointerWheelChanged(m_pointerWheelChangedToken);
314
+ auto keyboardSource = winrt::Microsoft::UI::Input::InputKeyboardSource::GetForIsland(island);
315
+ keyboardSource.KeyDown(m_keyDownToken);
316
+ keyboardSource.KeyUp(m_keyUpToken);
317
+ keyboardSource.CharacterReceived(m_characterReceivedToken);
318
+ }
296
319
  }
297
320
  #endif
298
321
  }
299
322
 
300
323
  facebook::react::SurfaceId CompositionEventHandler::SurfaceId() const noexcept {
301
- return static_cast<facebook::react::SurfaceId>(
302
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(m_compRootView)->GetTag());
324
+ if (auto strongRootView = m_wkRootView.get()) {
325
+ return static_cast<facebook::react::SurfaceId>(
326
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(strongRootView)->GetTag());
327
+ }
328
+ return -1;
303
329
  }
304
330
 
305
331
  winrt::Microsoft::ReactNative::Composition::implementation::RootComponentView &
@@ -369,86 +395,104 @@ winrt::Windows::System::VirtualKeyModifiers GetKeyModifiers(uint64_t wParam) {
369
395
  int64_t CompositionEventHandler::SendMessage(HWND hwnd, uint32_t msg, uint64_t wParam, int64_t lParam) noexcept {
370
396
  switch (msg) {
371
397
  case WM_LBUTTONDOWN: {
372
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
373
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
374
- onPointerPressed(pp, GetKeyModifiers(wParam));
398
+ if (auto strongRootView = m_wkRootView.get()) {
399
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
400
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
401
+ onPointerPressed(pp, GetKeyModifiers(wParam));
402
+ }
375
403
  return 0;
376
404
  }
377
405
  case WM_POINTERDOWN: {
378
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
379
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
380
- onPointerPressed(pp, GetKeyModifiers(wParam));
406
+ if (auto strongRootView = m_wkRootView.get()) {
407
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
408
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
409
+ onPointerPressed(pp, GetKeyModifiers(wParam));
410
+ }
381
411
  return 0;
382
412
  }
383
413
  case WM_LBUTTONUP: {
384
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
385
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
386
- onPointerReleased(pp, GetKeyModifiers(wParam));
414
+ if (auto strongRootView = m_wkRootView.get()) {
415
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
416
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
417
+ onPointerReleased(pp, GetKeyModifiers(wParam));
418
+ }
387
419
  return 0;
388
420
  }
389
421
  case WM_POINTERUP: {
390
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
391
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
392
- onPointerReleased(pp, GetKeyModifiers(wParam));
422
+ if (auto strongRootView = m_wkRootView.get()) {
423
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
424
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
425
+ onPointerReleased(pp, GetKeyModifiers(wParam));
426
+ }
393
427
  return 0;
394
428
  }
395
429
  case WM_MOUSEMOVE: {
396
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
397
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
398
- onPointerMoved(pp, GetKeyModifiers(wParam));
430
+ if (auto strongRootView = m_wkRootView.get()) {
431
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
432
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
433
+ onPointerMoved(pp, GetKeyModifiers(wParam));
434
+ }
399
435
  return 0;
400
436
  }
401
437
  case WM_CAPTURECHANGED: {
402
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
403
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
404
- onPointerCaptureLost(pp, winrt::Windows::System::VirtualKeyModifiers::None);
438
+ if (auto strongRootView = m_wkRootView.get()) {
439
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
440
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
441
+ onPointerCaptureLost(pp, winrt::Windows::System::VirtualKeyModifiers::None);
442
+ }
405
443
  return 0;
406
444
  }
407
445
  case WM_MOUSEWHEEL: {
408
- auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
409
- hwnd, msg, wParam, lParam, m_compRootView.ScaleFactor());
410
- onPointerWheelChanged(pp, GetKeyModifiers(wParam));
446
+ if (auto strongRootView = m_wkRootView.get()) {
447
+ auto pp = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::PointerPoint>(
448
+ hwnd, msg, wParam, lParam, strongRootView.ScaleFactor());
449
+ onPointerWheelChanged(pp, GetKeyModifiers(wParam));
450
+ }
411
451
  break;
412
452
  }
413
453
  case WM_CHAR:
414
454
  case WM_SYSCHAR: {
415
- auto focusedComponent = RootComponentView().GetFocusedComponent();
416
- auto args = winrt::make<
417
- winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
418
- focusedComponent
419
- ? focusedComponent.Tag()
420
- : static_cast<facebook::react::Tag>(
421
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(m_compRootView)
422
- ->GetTag()),
423
- msg,
424
- wParam,
425
- lParam);
426
- auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
427
- onCharacterReceived(keyboardSource, args);
428
- winrt::get_self<CompositionKeyboardSource>(keyboardSource)->Disconnect();
455
+ if (auto strongRootView = m_wkRootView.get()) {
456
+ auto focusedComponent = RootComponentView().GetFocusedComponent();
457
+ auto args = winrt::make<
458
+ winrt::Microsoft::ReactNative::Composition::Input::implementation::CharacterReceivedRoutedEventArgs>(
459
+ focusedComponent ? focusedComponent.Tag()
460
+ : static_cast<facebook::react::Tag>(
461
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
462
+ strongRootView)
463
+ ->GetTag()),
464
+ msg,
465
+ wParam,
466
+ lParam);
467
+ auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
468
+ onCharacterReceived(keyboardSource, args);
469
+ winrt::get_self<CompositionKeyboardSource>(keyboardSource)->Disconnect();
470
+ }
429
471
  break;
430
472
  }
431
473
  case WM_KEYDOWN:
432
474
  case WM_KEYUP:
433
475
  case WM_SYSKEYDOWN:
434
476
  case WM_SYSKEYUP: {
435
- auto focusedComponent = RootComponentView().GetFocusedComponent();
436
- auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
437
- focusedComponent
438
- ? focusedComponent.Tag()
439
- : static_cast<facebook::react::Tag>(
440
- winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(m_compRootView)
441
- ->GetTag()),
442
- msg,
443
- wParam,
444
- lParam);
445
- auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
446
- if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
447
- onKeyDown(keyboardSource, args);
448
- } else {
449
- onKeyUp(keyboardSource, args);
477
+ if (auto strongRootView = m_wkRootView.get()) {
478
+ auto focusedComponent = RootComponentView().GetFocusedComponent();
479
+ auto args = winrt::make<winrt::Microsoft::ReactNative::Composition::Input::implementation::KeyRoutedEventArgs>(
480
+ focusedComponent ? focusedComponent.Tag()
481
+ : static_cast<facebook::react::Tag>(
482
+ winrt::get_self<winrt::Microsoft::ReactNative::implementation::CompositionRootView>(
483
+ strongRootView)
484
+ ->GetTag()),
485
+ msg,
486
+ wParam,
487
+ lParam);
488
+ auto keyboardSource = winrt::make<CompositionKeyboardSource>(this);
489
+ if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
490
+ onKeyDown(keyboardSource, args);
491
+ } else {
492
+ onKeyUp(keyboardSource, args);
493
+ }
494
+ winrt::get_self<CompositionKeyboardSource>(keyboardSource)->Disconnect();
450
495
  }
451
- winrt::get_self<CompositionKeyboardSource>(keyboardSource)->Disconnect();
452
496
  break;
453
497
  }
454
498
  }
@@ -571,9 +615,9 @@ void CompositionEventHandler::HandleIncomingPointerEvent(
571
615
 
572
616
  // We only want to emit events to JS if there is a view that is currently listening to said event
573
617
  // so we only send those event to the JS side if the element which has been entered is itself listening,
574
- // or if one of its parents is listening in case those listeners care about the capturing phase. Adding the ability
575
- // for native to distinguish between capturing listeners and not could be an optimization to further reduce the
576
- // number of events we send to JS
618
+ // or if one of its parents is listening in case those listeners care about the capturing phase. Adding the
619
+ // ability for native to distinguish between capturing listeners and not could be an optimization to further
620
+ // reduce the number of events we send to JS
577
621
  bool hasParentEnterListener = false;
578
622
  bool emittedNativeEnteredEvent = false;
579
623
 
@@ -673,7 +717,8 @@ void CompositionEventHandler::HandleIncomingPointerEvent(
673
717
  }
674
718
 
675
719
  for (auto itComponentView = viewsToEmitJSLeaveEventsTo.rbegin(); itComponentView != viewsToEmitJSLeaveEventsTo.rend();
676
- itComponentView++) { // for (UIView *componentView in [viewsToEmitJSLeaveEventsTo reverseObjectEnumerator]) {
720
+ itComponentView++) { // for (UIView *componentView in [viewsToEmitJSLeaveEventsTo
721
+ // reverseObjectEnumerator]) {
677
722
  auto componentView = *itComponentView;
678
723
 
679
724
  const auto eventEmitter =
@@ -769,8 +814,10 @@ void CompositionEventHandler::getTargetPointerArgs(
769
814
  auto targetComponentView = fabricuiManager->GetViewRegistry().componentViewDescriptorWithTag(tag).view;
770
815
  auto clientRect = winrt::get_self<winrt::Microsoft::ReactNative::implementation::ComponentView>(targetComponentView)
771
816
  ->getClientRect();
772
- ptLocal.x = ptScaled.x - (clientRect.left / m_compRootView.ScaleFactor());
773
- ptLocal.y = ptScaled.y - (clientRect.top / m_compRootView.ScaleFactor());
817
+ if (auto strongRootView = m_wkRootView.get()) {
818
+ ptLocal.x = ptScaled.x - (clientRect.left / strongRootView.ScaleFactor());
819
+ ptLocal.y = ptScaled.y - (clientRect.top / strongRootView.ScaleFactor());
820
+ }
774
821
  } else {
775
822
  tag = RootComponentView().hitTest(ptScaled, ptLocal);
776
823
  }
@@ -154,7 +154,7 @@ class CompositionEventHandler {
154
154
  PointerId m_touchId = 0;
155
155
 
156
156
  std::map<PointerId, std::vector<ReactTaggedView>> m_currentlyHoveredViewsPerPointer;
157
- winrt::Microsoft::ReactNative::CompositionRootView m_compRootView{nullptr};
157
+ winrt::weak_ref<winrt::Microsoft::ReactNative::CompositionRootView> m_wkRootView;
158
158
  winrt::Microsoft::ReactNative::ReactContext m_context;
159
159
 
160
160
  facebook::react::Tag m_pointerCapturingComponentTag{-1}; // Component that has captured input