Home > database >  Android Fragment not displayed in React Native App
Android Fragment not displayed in React Native App

Time:11-12

I have followed the RN docs to create an Android Native Fragment: enter image description here

So, what does it need to be done do to bring the CustomView to the Front?

I've tried calling: myFragment.customView.bringToFront(); but didn't work.

The commit() always returns -1:

activity.getSupportFragmentManager()
      .beginTransaction()
      .add(reactNativeViewId, myFragment, String.valueOf(reactNativeViewId))
      .commit();

I've followed the article, went back and forth into the instructions and everything is there.

I have created a repo to help debug the issue: https://github.com/wilsolutions/react-native-experiments

Any thoughts?

Thank you

CodePudding user response:

I wrote that part of the documentation. I added the missing parts (and also fixed an issue that caused layout to be unpredictable) in this PR:

https://github.com/facebook/react-native-website/pull/2599. Please let me know if you still miss something.

Answer wrapped up basically:

  • CustomView has to extend FrameLayout like in above PR
  • in your ViewManager's setupLayout method
ViewGroup parentView = (ViewGroup) root.findViewById(reactNativeViewId).getParent();

should be

ViewGroup parentView = (ViewGroup) root.findViewById(reactNativeViewId);
  • Related