mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 14:48:25 +00:00
Summary: We are writing a native navigation library. When there are more than a dozen `ReactRootView` in the application, the application will be very stuck. It doesn't improve much, even if we remove the invisible ReactRootView from the View hierarchy temporarily. After debugging, we found that we were not able to remove `OnGlobalLayoutListener` in `onDetachedFromWindow` because this listener was added twice. One is in `onAttachedToWindow` and the other is in `attachToReactInstanceManager`. We added the following code by inheriting ReactRootView. ```java Override protected void onAttachedToWindow() { try { Method method = ReactRootView.class.getDeclaredMethod("getCustomGlobalLayoutListener"); method.setAccessible(true); // remove duplicated GlobalLayoutListener if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { getViewTreeObserver().removeOnGlobalLayoutListener((ViewTreeObserver.OnGlobalLayoutListener) method.invoke(this)); } else { getViewTreeObserver().removeGlobalOnLayoutListener((ViewTreeObserver.OnGlobalLayoutListener) method.invoke(this)); } } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } super.onAttachedToWindow(); } ``` It turns out that there is no pressure even if opening hundreds of pages that contain ReactRootView (remove ReactRootView from the View hierarchy temporarily in the invisible pages). Changelog: ---------- [Android] [Fixed] - Remove duplicated `OnGlobalLayoutListener` to improve performance. Pull Request resolved: https://github.com/facebook/react-native/pull/22849 Differential Revision: D13682818 Pulled By: hramos fbshipit-source-id: 1f1bc8cd5fc4e01a1bc2f2a4784822b4eae92fdc
Building React Native for Android
See the docs on the website.
Running tests
When you submit a pull request CircleCI will automatically run all tests. To run tests locally, see Testing.