Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with complicated native app #6

Closed
anky21 opened this issue Oct 23, 2017 · 5 comments
Closed

Issue with complicated native app #6

anky21 opened this issue Oct 23, 2017 · 5 comments

Comments

@anky21
Copy link

anky21 commented Oct 23, 2017

Hi Petter,

I tried your demo and tried your code with a simple native android app (react native demo). I was able to call a native activity from react native. However, when I tried to apply it to a more complicated native app, it started give me this error:
Cannot read property 'dialNumber' of undefined
I've tried really everything. I made the package.json file almost the same as yours. I changed the setttings in build.gradle as yours as well.

I just tried another not-too-complicated app and it didn't work.
https://github.com/anky21/Integrate-React-Native-in-Android

Is it possible that some libraries are interfering with React Native? Or the project has to be created through react-native init? What do you think the problem can be?

Cheers

@petterh
Copy link
Owner

petterh commented Oct 23, 2017

Your problem is that you don't add the ActivityStarterReactPackage to your ReactInstanceManager. In ReactActivity.onCreate, add this line:

mReactInstanceManager = ReactInstanceManager.builder()
        .setApplication(getApplication())
        .setBundleAssetName("index.android.bundle")
        .setJSMainModuleName("index.android")
        .addPackage(new MainReactPackage())
        .addPackage(new ActivityStarterReactPackage()) // <== ADD THIS LINE
        .setUseDeveloperSupport(BuildConfig.DEBUG)
        .setInitialLifecycleState(mLifecycleState)
        .build();

Another problem occurs if you don't already have the overlay permission -- after starting the Settings.ACTION_MANAGE_OVERLAY_PERMISSION, you still go ahead and create the react native window. Better to refactor this into its own method, which you then call from onCreate if you don't have to ask for overlay permissions, and from onActivityResult otherwise. (Provided you got the permission.)

(The overlay permission thing only applies to debug builds, but still.)

On a side note, it's quite a bit warmer in Brisbane than in Oslo this time of year...

@petterh petterh closed this as completed Oct 23, 2017
@anky21
Copy link
Author

anky21 commented Oct 23, 2017

Thanks a lot. It solved the problem. Thank you so much.
Brisbane is a lot hotter for sure. Come down to Gold Coast sometimes. It's quite nice.

@DenisLebedinsky
Copy link

DenisLebedinsky commented Jun 10, 2019

I have a problem with adding ActivityStarterModule:

.addPackage(new ActivityStarterModule())

i not give reactContect, but i haven't this context in

mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setCurrentActivity(this) .setBundleAssetName("index.android.bundle") .setJSMainModulePath("index") .addPackage(new MainReactPackage()) .addPackage(new ActivityStarterModule()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build();

@petterh
Copy link
Owner

petterh commented Jun 10, 2019

ActivityStarterModule is not a react package. Try ActivityStarterReactPackage instead.

@DenisLebedinsky
Copy link

DenisLebedinsky commented Jun 10, 2019

Thank you for fast answer, but i found resolve in your stack's answer. =)

https://stackoverflow.com/questions/42253397/call-android-activity-from-react-native-code/56522460#56522460

I create ActivityStarterReactPackage, and it resolved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants