Skip to content

Commit f59a6f9

Browse files
cortinicofacebook-github-bot
authored andcommitted
Do not crash inside getEncodedScreenSizeWithoutVerticalInsets if SurfaceMountingManager is null (#53752)
Summary: Pull Request resolved: #53752 Currently we `Objects.requireNotNull` on the `SurfaceMountingManager` inside the `getEncodedScreenSizeWithoutVerticalInsets` function. However the `SurfaceMountingManager` could be null. In that scenario, I'm returning 0 here (that will restore the old broken behavior, with the modal rendering on the top left corner for the first frame), instead of letting the app crash. Changelog: [Android] [Fixed] - Do not crash inside getEncodedScreenSizeWithoutVerticalInsets if SurfaceMountingManager is null Reviewed By: javache Differential Revision: D82225855 fbshipit-source-id: df84db612e77b6b981bc28afc0d293867b5d3b2e
1 parent 91d427f commit f59a6f9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
import java.util.HashSet;
100100
import java.util.List;
101101
import java.util.Map;
102-
import java.util.Objects;
103102
import java.util.Queue;
104103
import java.util.Set;
105104
import java.util.concurrent.CopyOnWriteArrayList;
@@ -738,11 +737,17 @@ public boolean getThemeData(int surfaceId, float[] defaultTextInputPadding) {
738737
* vertical insets.
739738
*/
740739
private long getEncodedScreenSizeWithoutVerticalInsets(int surfaceId) {
741-
SurfaceMountingManager surfaceMountingManager = mMountingManager.getSurfaceManager(surfaceId);
742-
Objects.requireNonNull(surfaceMountingManager);
743-
ThemedReactContext context = Objects.requireNonNull(surfaceMountingManager.getContext());
744-
return DisplayMetricsHolder.getEncodedScreenSizeWithoutVerticalInsets(
745-
context.getCurrentActivity());
740+
ThemedReactContext context =
741+
mMountingManager
742+
.getSurfaceManagerEnforced(surfaceId, "getEncodedScreenSizeWithoutVerticalInsets")
743+
.getContext();
744+
if (context == null) {
745+
FLog.w(TAG, "Couldn't get context from SurfaceMountingManager for surfaceId %d", surfaceId);
746+
return 0;
747+
} else {
748+
return DisplayMetricsHolder.getEncodedScreenSizeWithoutVerticalInsets(
749+
context.getCurrentActivity());
750+
}
746751
}
747752

748753
@Override

0 commit comments

Comments
 (0)