From ea7c9f2ad9a78b16234306932edc1d78b783ac27 Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Mon, 6 Jun 2022 15:44:13 -0700 Subject: [PATCH] Fix edge case when we enqueue a pending event to views on stopped surface Summary: This diff address an edge case when the pending events are enqueued when the surface is stopped. In this case we will reset map that holds view state to null, which will cause NPE. Changelog: [Android][Fixed] - Fix edge case when we enqueue a pending event to views on stopped surface Reviewed By: javache, gorodscy Differential Revision: D36912786 fbshipit-source-id: 3ae5a4b08a0a6bf55538d69ac80a101c2c3d899a --- .../react/fabric/mounting/SurfaceMountingManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java index 6a94f1e8b0e..66f11b1a873 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/SurfaceMountingManager.java @@ -1092,6 +1092,12 @@ public class SurfaceMountingManager { public void enqueuePendingEvent(int reactTag, ViewEvent viewEvent) { UiThreadUtil.assertOnUiThread(); + // When the surface stopped we will reset the view state map. We are not going to enqueue + // pending events as they are not expected to be dispatched anyways. + if (mTagToViewState == null) { + return; + } + ViewState viewState = mTagToViewState.get(reactTag); if (viewState == null) { // Cannot queue event without view state. Do nothing here.