alinz / react-native-share-extension

react-native as an engine to drive share extension
MIT License
763 stars 398 forks source link

Usage problem with wix/react-native-navigation on Android #37

Open kristoff-it opened 7 years ago

kristoff-it commented 7 years ago

Hello, I've sucessfully used both libs together on react-native@0.38 but after upgrading to react-native@0.43, I encountered a new problem that I didn't have before:

To perform the upgrade I created a new react-native project in a separared directory, moved in the source files I wrote and reapplied all the manual integrations one by one (namely: rn-navigation, rn-share-extension and rn-swiss-knife), so we can assume there are no stale settings somewhere that didn't get properly updated. Also I used rn-share-extension@1.1.0 with rn@0.38 and rn-share-extension@1.1.1 with rn@0.43

Now the problem is as follows: For reasons that I don't fully understand, react-native-navigation changes the way the app is loaded by skipping the AppRegistry.registerComponent step and while before it didn't cause any problem, now "forcing" the execution of the main application makes the share extension crash.

myapp/MainActivity.java

import com.reactnativenavigation.controllers.SplashActivity;

public class MainActivity extends SplashActivity {

}

index.android.js

import { AppRegistry } from 'react-native'
import App from './src/app'
import Share from './src/share'

AppRegistry.registerComponent('MyShare', () => Share)

let app = new App()

The App instance, after some setup, calls Navigation.startSingleScreenApp and the main application starts. Without that line, the share extension works perfectly but the main application doesn't load (I get a white screen), but, with it, the share extension crashes.

On iOS this doesn't cause any problem even with the new version of react-native, it's something on android that has changed. EDIT: Apparently it keeps working on iOS when building in debug mode, when using the release scheme I get the same error and also in this case the "fix" is to delete the new App line.

Is there any way of checking "who" whats to call "what" and only instantiate App when the user wants the main application? Or anything else that can be done to obtain the previous convenient behavior?

For reference: myapp/MainApplication.java

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;
import com.reactnativenavigation.NavigationApplication;
import com.alinz.parkerdan.shareextension.SharePackage;
import com.github.alinz.rnsk.RNSKPackage;

public class MainApplication extends NavigationApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new SharePackage(),
          new RNSKPackage()
      );
    }
  };

  @Override
  public boolean isDebug() {
     // Make sure you are using BuildConfig from your own application
    return BuildConfig.DEBUG;
  }

  @Override
  public List<ReactPackage> createAdditionalReactPackages() {
     // Add the packages you require here.
     // No need to add RnnPackage and MainReactPackage
    return Arrays.<ReactPackage>asList(
          new RNSKPackage()
      );
  }

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}
rf1804 commented 6 years ago

Is it working with wix/reac-native-navigation???