React Native : add fragment to mainactivity using Android Native Modules
Asked Answered
I

0

8

I have a specific Android native library to integrate the camera features. The library provides the Fragment with the all it features. I just want to integrate that with Mainactivity in React Native app.

I have followed the link "Add fragment into react-native view"

Also i have gone through many tutorials. But I am stuck up at the place where we add the fragment into the Mainactivity container layout of React native app.

Update:

React Component (JS file):

export default class MyCustomView extends Component {
render() {
   return (
      <View >
       {
        MyLayout.openBlankFragment(12345)

       }
      </View>
   );
  }
  }
 const MyLayout = NativeModules.MyModule;

MyModule (Java Code):

@ReactMethod
    private void openBlankFragment(final int viewId) {
//        Log.v("View Tag", "View ID: "+viewId); it prints tag 12345
        UIManagerModule uiManager = getReactApplicationContext().getNativeModule(UIManagerModule.class);

                uiManager.addUIBlock(new UIBlock() {
            @Override
            public void execute(NativeViewHierarchyManager nativeViewHierarchyManager) {
                View view = nativeViewHierarchyManager.resolveView(viewId);

                final Activity activity = getCurrentActivity();
                BlankFragment fragment = new BlankFragment();
                FragmentTransaction transaction = ((MainActivity)activity).getSupportFragmentManager().beginTransaction();
                transaction.add(view.getId(), fragment);
                transaction.commit();

            }
        });
    }

view.getId() is not recognized. Need help here. If i set the activity root view id like "transaction.add(android.R.id.content, fragment);". Its working fine and i can my fragment. But i need to setup my fragment as view in React screen like a frame.

Inextirpable answered 24/11, 2017 at 20:47 Comment(2)
What is the meaning of stuck? Errors? Logs? Problems? Code?Juglandaceous
@sfratini I have updated my code. Need to get the react native view code at android native module. i stuck up there. :(Inextirpable

© 2022 - 2024 — McMap. All rights reserved.