Docs update: Load Android Activity (Fragment) inside RN Native Component

8
closed
wilsolutions
wilsolutions
Posted 1 month ago

Docs update: Load Android Activity (Fragment) inside RN Native Component #32414

Description

I have a RN Native Component and I would like to load the Android Activity inside of it.

From the RN Docs I see that there is a way to load the RN App inside an Android Native App, I need the other way around and looks likes there are a bunch of other people looking for this, would be nice to update the docs with such info.

I know that is not possible to load the Activity inside the RN Native Component but do you know any workaround? Maybe using an Android Fragment? Convert the Activity code into a Fragment? Thoughts?

React Native version:

0.64

Steps To Reproduce

  1. Create a RN Native Component
  2. Try to load an Native Android Activity inside the new RN Native Component.

Expected Results

The Activity is initialized and displayed inside the Native Component or inside a RN View.

Snack, code example, screenshot, or link to a repository:

https://stackoverflow.com/questions/69562692/display-android-native-activity-into-react-native-view

ammarahm-ed
ammarahm-ed
Created 1 month ago

I don't think that will be possible. It's not possible even in native android to load an activity inside a View of another activity.

However you can use a fragment to achieve something like that.

wilsolutions
wilsolutions
Created 1 month ago

Yep, that's the direction I'm taking however how can developers proceed? Do we convert the Activity to Fragment? What are things that one should keep an eye on during the process?

Such information is not available in the docs, and per what I've seen there is a bunch of people looking for this.

ammarahm-ed
ammarahm-ed
Created 1 month ago

Yep, that's the direction I'm taking however how can developers proceed? Do we convert the Activity to Fragment? What are things that one should keep an eye on during the process?

Such information is not available in the docs, and per what I've seen there is a bunch of people looking for this.

You should look at the docs, how Native Components are built in android and iOS. Use that instead of an Activity.

wilsolutions
wilsolutions
Created 1 month ago

Yep, that's the direction I'm taking however how can developers proceed? Do we convert the Activity to Fragment? What are things that one should keep an eye on during the process? Such information is not available in the docs, and per what I've seen there is a bunch of people looking for this.

You should look at the docs, how Native Components are built in android and iOS. Use that instead of an Activity.

Hey, yep, I've a RN Native Component in place, it is working fine. What I need is to get the Android Native Code that exists in one Activity and make it work in the RN Native Component.

There is no information in th docs about it. Ther ei the other way around: getting RN to run inside an existing Android Native App.

ammarahm-ed
ammarahm-ed
Created 1 month ago

What does the activity you want to implement do in general?

wilsolutions
wilsolutions
Created 1 month ago

What does the activity you want to implement do in general?

It consumes a 3rd party SDK which based on a API response builds an UI.

As I've mentioned in the initial post url reference, it will work fine calling the Intent:

    ReactApplicationContext context = getReactApplicationContext();
    Intent intent = new Intent(context, SampleActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

But, I need to load it inside of my RN Native Component.

ammarahm-ed
ammarahm-ed
Created 1 month ago

You will need to rewrite the code in a Native Component and build the same UI using RN components.

wilsolutions
wilsolutions
Created 1 month ago

You will need to rewrite the code in a Native Component and build the same UI using RN components.

Yeah, I was trying to avoid this (cry mode on) lol but, how the Mandalorian would say: This is the way!

Thanks man