简体   繁体   中英

react-native-maps integration issue with react-native 0.19.0

As per instructions of adding react-native-maps , adding to MainActivity:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
            .setApplication(getApplication())
            .setBundleAssetName("index.android.bundle")
            .setJSMainModuleName("index.android")
            .addPackage(new MainReactPackage())
            .addPackage(new AirPackage()) // <---- and This!
            .setUseDeveloperSupport(BuildConfig.DEBUG)
            .setInitialLifecycleState(LifecycleState.RESUMED)
            .build();

    mReactRootView.startReactApplication(mReactInstanceManager, "MelBike", null);

    setContentView(mReactRootView);

}

I encountered this exception:

java.lang.AssertionError: Attached DialogModule to host with pending alert but no FragmentManager (not attached to an Activity).
                                                           at com.facebook.infer.annotation.Assertions.assertNotNull(Assertions.java:28)
                                                           at com.facebook.react.modules.dialog.DialogModule.onHostResume(DialogModule.java:199)
                                                           at com.facebook.react.bridge.ReactContext.onResume(ReactContext.java:140)
                                                           at com.facebook.react.ReactInstanceManagerImpl.moveReactContextToCurrentLifecycleState(ReactInstanceManagerImpl.java:761)
                                                           at com.facebook.react.ReactInstanceManagerImpl.setupReactContext(ReactInstanceManagerImpl.java:599)
                                                           at com.facebook.react.ReactInstanceManagerImpl.access$700(ReactInstanceManagerImpl.java:84)
                                                           at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:187)
                                                           at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.onPostExecute(ReactInstanceManagerImpl.java:162)
                                                           at android.os.AsyncTask.finish(AsyncTask.java:651)
                                                           at android.os.AsyncTask.-wrap1(AsyncTask.java)
                                                           at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
                                                           at android.os.Handler.dispatchMessage(Handler.java:102)
                                                           at android.os.Looper.loop(Looper.java:148)
                                                           at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                           at java.lang.reflect.Method.invoke(Native Method)
                                                           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

This is the source of the exception in react native code, DialogModule class:

public void onHostResume() {
mIsInForeground = true;
// Check if a dialog has been created while the host was paused, so that we can show it now.
FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper();
Assertions.assertNotNull(
    fragmentManagerHelper,
    "Attached DialogModule to host with pending alert but no FragmentManager " +
    "(not attached to an Activity).");
fragmentManagerHelper.showPendingAlert();

I have tried to comment out the assertion in DialogModule class and run react-native run-android but it seems it was not reflected in compiled code that ran in my emulator.

Also tried to set the LifecycleState.RESUMED to LifecycleState.BEFORE_RESUME but then the app only loads blank screen and Dev menu wasn't functioning properly.

Am I missing something?

What does the rest of your activity look like? I ran into this but the problem was that I was not implementing DefaultHardwareBackBtnHandler in my activity.

Here is how they are implemented:

@Override
protected void onPause() {
    super.onPause();

    if (mReactInstanceManager != null) {
        mReactInstanceManager.onPause();
    }
}

@Override
protected void onResume() {
    super.onResume();

    if (mReactInstanceManager != null) {
        mReactInstanceManager.onResume( this, this );
    }
}

@Override
public void onBackPressed() {
    if (mReactInstanceManager != null) {
        mReactInstanceManager.onBackPressed();
    } else {
        super.onBackPressed();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM