使用react-native-navigation设置InitialProps

时间:2017-09-20 08:18:55

标签: android android-intent react-native react-native-navigation

我想在react-native-navigation的帮助下设置我从android中的intent.ACTION_SEND获得的initialProps。

MainActivity.java

public class MainActivity extends SplashActivity {

String sharedText;
Uri sharedImage;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    if(Intent.ACTION_SEND.equals(action) && type != null){
        if(type.startsWith("text/")){
            handleSendText(intent);
        }else if(type.startsWith("image/")){
            handleSendImage(intent);
        }
    }
}



void handleSendText(Intent intent){
    sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}

void handleSendImage(Intent intent){
    sharedImage = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
}


/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */


 @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Intent intent = new Intent("onConfigurationChanged");
    intent.putExtra("newConfig", newConfig);
    this.sendBroadcast(intent);

}

protected String getMainComponentName() {
    return "Atmiyo";
}
}

MainApplication.java

public class MainApplication extends NavigationApplication {

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

protected List<ReactPackage> getPackages() {
         // Add additional packages you require here
         // No need to add RnnPackage and MainReactPackage
         return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
        new ReactNativeContacts(),
        new SyncAdapterPackage(),
        new RNSoundPackage(),
        new OrientationPackage(),
        new ReactNativeOneSignalPackage(),
        new BlurViewPackage(),
        new Interactable(),
        new SvgPackage(),
        new RNGooglePlacesPackage(),
        new RNVideoProcessingPackage(),
        new A0Auth0Package(),
            new RNFirebaseAdMobPackage(),
            new LinearGradientPackage(),
            new RNSpinkitPackage(),
            new ReactVideoPackage(),
            new RNReactNativeLinkPreviewPackage()

         );
     }

     @Nullable
     @Override
     public List<ReactPackage> createAdditionalReactPackages() {
         return getPackages();
     }

@Override
public void onCreate() {
    super.onCreate();
    setActivityCallbacks(new ActivityCallbacks(){


        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            super.onActivityCreated(activity, savedInstanceState);
            activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        }


        @Override
        public void onActivityStarted(Activity activity) {
            super.onActivityStarted(activity);
        }

        @Override
        public void onActivityResumed(Activity activity) {
            super.onActivityResumed(activity);
        }

        @Override
        public void onActivityPaused(Activity activity) {
            super.onActivityPaused(activity);
        }

        @Override
        public void onActivityStopped(Activity activity) {
            super.onActivityStopped(activity);
        }

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
        }

        @Override
        public void onActivityDestroyed(Activity activity) {
            super.onActivityDestroyed(activity);
        }
    });
}

你可以看到我可以从MainActivity.java中的intent.ACTION_SEND获取意图数据, 但我无法弄清楚如何在app.android.js中传递这些值。

任何人都可以帮我这个吗?

0 个答案:

没有答案