Skip to content

Commit

Permalink
Resolve android crash on display modal (#35380)
Browse files Browse the repository at this point in the history
Summary:
From exception logging, found crashes due to `Attempt to invoke virtual method 'int android.view.ViewGroup.getChildCount()' on a null object reference`. Tracing through the stack, it appears the constructor for `ViewGroup` conditionally calls `initializeScrollbarsInternal()`, which in turn calls `getChildCount()`.  However `ReactModalHostView` overrides `getChildCount()`, so `getChildCount()` is called before `ReactModalHostView` constructor completes, resulting in null reference when accessing `mHostView` from `getChildCount()`.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Fixed] - Fix crash on initialize modal

Pull Request resolved: #35380

Test Plan: In the rn-tester project, display a modal.

Reviewed By: javache, cipolleschi

Differential Revision: D41392235

Pulled By: ryancat

fbshipit-source-id: ce78e4d458ad41769e78139ea0a8a038384e830d
  • Loading branch information
alpha0010 authored and facebook-github-bot committed Nov 18, 2022
1 parent 4d7ddd4 commit 1565634
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public void addView(View child, int index) {

@Override
public int getChildCount() {
return mHostView.getChildCount();
// This method may be called by the parent constructor
// before mHostView is initialized.
return mHostView == null ? 0 : mHostView.getChildCount();
}

@Override
Expand Down

0 comments on commit 1565634

Please sign in to comment.