/** * Returns the descendant of the given view which is the root of the React Native views */ @Nullable private View findRootView(ViewGroup parent) { for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); if (child instanceof RootView) { return child; } else if (child instanceof ViewGroup) { child = findRootView((ViewGroup) child); if (child != null) { return child; } } } return null; }