react-native-navigation icon indicating copy to clipboard operation
react-native-navigation copied to clipboard

You cannot render into anything but top root

Open diennguyentien opened this issue 9 years ago • 59 comments

I get this error after update RN. The showLightBox is not shown


Environment

  • React Native Navigation version: 1.1.134
  • React Native version: 0.46.2
  • Platform(s) (iOS, Android, or both?): both
  • Device info (Simulator/Device? OS version? Debug/Release?): Release

diennguyentien avatar Jul 14 '17 03:07 diennguyentien

I have somewhat the same issue, one the 2 errors come when dismissing a LightBox on Android.

Environment

  • React Native Navigation version: 1.1.134
  • React Native version: 0.46.2
  • Platform(s) (iOS, Android, or both?): Android
  • Device info (Simulator/Device? OS version? Debug/Release?): *

screenshot_1500323207 screenshot_1500323299

Bhullnatik avatar Jul 17 '17 20:07 Bhullnatik

@diennguyentien @Bhullnatik

node_modules/react-native-navigation/android/app/src/main/java/com/reactnativenavigation/layouts/:

class SingleScreenLayout & BottomTabsLayout

rewrite function :


    @Override
    public void dismissLightBox() {
        if (lightBox != null) {
            lightBox.dismiss();
            // lightBox.hide();
            lightBox = null;
        }
    }

lipingruan avatar Jul 21 '17 01:07 lipingruan

@lipingruan thanks you

diennguyentien avatar Jul 21 '17 01:07 diennguyentien

Does @lipingruan workaround work for you guys?

rgommezz avatar Jul 23 '17 15:07 rgommezz

@lipingruan's workaround works.

sijad avatar Jul 23 '17 17:07 sijad

That will only work if you want to dismiss the lightbox from your screen, meaning by calling this.props.navigator.dismissLightBox() from your component.

However, if you wanna also close the lightbox by tapping in the background (common use case) using tapBackgroundToDismiss it will still break, i.e:

this.props.navigator.showLightBox({
  screen: screens.lightBox.sort,
  style: {
    backgroundBlur: 'dark',
    backgroundColor: 'rgba(0, 0, 0, 0.7)',
    tapBackgroundToDismiss: true,
  },
});

@lipingruan's workaround also removes entirely the animation on dismissal. My workaround works for all cases and keeps the animation, see https://github.com/rauliyohmc/react-native-navigation/commit/c15bde4899c9779d7be47670a7ed3f988c4b38af.

I am concerned if that would imply memory leaks though. @guyca do you have any thoughts on that? It'd likely break previous RN versions as well.

rgommezz avatar Jul 23 '17 20:07 rgommezz

@rauliyohmc hello, I found bug is 'tag', and solved in new workaround, but it need you custom build RN.

file1: node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java :

rewrite function:


  private void detachViewFromInstance(
      ReactRootView rootView,
      CatalystInstance catalystInstance) {
    UiThreadUtil.assertOnUiThread();

    // int tag = rootView.getId();
    int tag = rootView.getRootViewTag();

    catalystInstance.getJSModule(AppRegistry.class)
        .unmountApplicationComponentAtRootTag(tag);
  }

file2: node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeViewHierarchyManager.java :

rewrite function:

  protected synchronized void dropView(View view) {
    UiThreadUtil.assertOnUiThread();

    int tag;

    if ( view instanceof ReactRootView ) {

      tag = ((ReactRootView) view).getRootViewTag();
    } else {

      tag = view.getId();
    }

    if (!mRootTags.get( tag )) {
      // For non-root views we notify viewmanager with {@link ViewManager#onDropInstance}
      resolveViewManager( tag ).onDropViewInstance(view);
    }

    ViewManager viewManager = mTagsToViewManagers.get( tag );
    if (view instanceof ViewGroup && viewManager instanceof ViewGroupManager) {
      ViewGroup viewGroup = (ViewGroup) view;
      ViewGroupManager viewGroupManager = (ViewGroupManager) viewManager;
      for (int i = viewGroupManager.getChildCount(viewGroup) - 1; i >= 0; i--) {
        View child = viewGroupManager.getChildAt(viewGroup, i);
        if (mTagsToViews.get(child.getId()) != null) {
          dropView(child);
        }
      }
      viewGroupManager.removeAllViews(viewGroup);
    }
    mTagsToViews.remove( tag );
    mTagsToViewManagers.remove( tag );
  }

it's ok :)

detail message in : file: node_modules/react-native/Libraries/Renderer/ReactNativeStack-dev.js: 2040 function: unmountComponentAtNode & renderComponent

lipingruan avatar Jul 24 '17 05:07 lipingruan

Hey guys Can someone upload an example project where this issue reproduces? I understand it doesn't happen in RN 0.45

guyca avatar Jul 24 '17 06:07 guyca

@guyca Just change the version of react-native to 0.46.4, then run the example, this error will show when hiding light box.

coolerfall avatar Jul 31 '17 03:07 coolerfall

Any update @guyca? I'm using many lightboxes on my app mostly for loading popup indicator

yayanartha avatar Aug 09 '17 13:08 yayanartha

[using V2] not too sure how much help it is but i did some debugging and commenting out unmountReactApplication() in ReactContainerView.java stopped the error for me but it doesnt seem like that is a/the solution. @guyca

JPig avatar Aug 23 '17 12:08 JPig

I get this error in any way i want to close lighbox I get error when using : tapBackgroundToDismiss: true, or this.props.navigator.dismissLightBox() even when rewrite method :

@Override
    public void dismissLightBox() {
        if (lightBox != null) {
            lightBox.dismiss();
            // lightBox.hide();
            lightBox = null;
        }
    }

my react native version : "react-native": "0.47.2" please someone help to solve it

hemedani avatar Aug 30 '17 09:08 hemedani

This hacky by @rawrmaan fixed for me change the destroy method on node_modules/react-native-navigation/android/app/src/main/java/com/reactnativenavigation/views/LightBox.java

    public void destroy() {
        // content.unmountReactView();
        dismiss();
    }

tank you man

hemedani avatar Aug 30 '17 10:08 hemedani

It's trow error in some devices like lenovo tab3 ... please fixed this issues i needed for my app

hemedani avatar Sep 03 '17 07:09 hemedani

I encounter this with light box when using Android's back button. Also using tapBackgroundToDismiss: true

henrikra avatar Sep 11 '17 12:09 henrikra

I'm having the same issue

manishoo avatar Sep 18 '17 06:09 manishoo

Also getting this on android, is this being looked at ? Basically can't use lightboxes at all at the moment.

kyle-ssg avatar Sep 18 '17 10:09 kyle-ssg

As epic as this library is, it is making my app pretty much iOS only instead of cross platform. Please !!!!! fix this issue.

ODelibalta avatar Sep 19 '17 01:09 ODelibalta

@hemedani Thanks, your workaround works quite nice. But within my lightbox I'm dependent on the componentWillUnmount method beeing called. With your workaround this method is never called for my lightbox. So currently I have a really ugly hack for this:

    if (Platform.OS === 'android') {
      setTimeout(() => {
        this.componentWillUnmount()
      }, 800)
    }

davidruisinger avatar Sep 21 '17 14:09 davidruisinger

beyond two month for fixing a little and irritating bug ... please fixed.

hemedani avatar Sep 28 '17 10:09 hemedani