mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix crash when dispatching cancel events to reparented views (#55273)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55273 Changelog: [Internal] When `FloatingView` reparents its content to a `SurfaceControlViewHost` (for z-offset elevation), the child views are no longer descendants of the main React root view hierarchy. If a pointer cancel event is dispatched while the view is in this state, `JSPointerDispatcher.getChildOffsetRelativeToRoot()` calls `offsetDescendantRectToMyCoords()` which throws `IllegalArgumentException: parameter must be a descendant of this view`. This fix makes `getChildOffsetRelativeToRoot()` return `null` when the view is not a descendant (catching only the specific "descendant" exception), and skips dispatching the cancel event in that case while still cleaning up internal pointer state. This crash was occurring in IGVR when scrolling through story pogs with thumbstick input, as each pog uses `FloatingView` with elevation. Reviewed By: javache Differential Revision: D90988373 fbshipit-source-id: 77b9e007d542b729ae0be0a5af1d25a22b99d32c
This commit is contained in:
1 parent
3c7b4881dd
commit
8544a6803f
1 file changed
+6
+6
@@ -678,6 +678,12 @@ public class JSPointerDispatcher {
|
||||
|
||||
// returns child (0, 0) relative to root coordinate system
|
||||
private int[] getChildOffsetRelativeToRoot(View childView) {
|
||||
if (childView.getRootView() != mRootViewGroup.getRootView()) {
|
||||
// NOTE: if we are here it means the target view has been reparented, so we can't call
|
||||
// mRootViewGroup.offsetDescendantRectToMyCoords because an exception will be thrown.
|
||||
// We still return (0, 0) to ensure the cancel event is dispatched.
|
||||
return new int[] {0, 0};
|
||||
}
|
||||
Rect childCoords = new Rect(0, 0, 1, 1);
|
||||
mRootViewGroup.offsetDescendantRectToMyCoords(childView, childCoords);
|
||||
return new int[] {childCoords.top, childCoords.left};
|
||||
|
||||
Reference in new issue
Block a user