React-native inside a Fragment

后端 未结 3 1742
萌比男神i
萌比男神i 2020-12-08 03:03

How to Start react-native inside of a fragment? While putting react-native inside Fragment, onCreateView function is unable to return View from mReactRootView.

3条回答
  •  佛祖请我去吃肉
    2020-12-08 03:58

    There is now an official ReactFragment available here that can be used to host react native inside a fragment.

    Just make sure you have your react native host setup correctly, as the fragment tries to access the react native host on the application level, or overload it in a subclass:

    // inside the ReactFragment
    protected ReactNativeHost getReactNativeHost() {
        return ((ReactApplication) getActivity().getApplication()).getReactNativeHost();
    }
    

    you can then create the fragment using:

    val reactNativeProcessFragment = ReactFragment.Builder()
        .setComponentName("nameUsedIn_AppRegistry.registerComponent")
        .build()
    

提交回复
热议问题