I am trying to use RNN V2 alongside react-native-fbsdk, which requires the onActivityResult event.
For V1 the solution was to use the setActivityCallbacks method as explained in the V1 docs and https://github.com/wix/react-native-navigation/issues/373#issuecomment-270015677
With V2 however com.reactnativenavigation.controllers.ActivityCallbacks no longer exists, and I can't find anything which offers the same functionality in the V2 code. I see NavigationActivity now has some onResume() and similar hooks but I don't know if that covers it?
Code I attempted to use:
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
// Facebook
setActivityCallbacks(new ActivityCallbacks() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
});
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
super.getReactGateway().onActivityCreated();
}
2.0.22460.55.2ActivityCallbacks are no longer needed in v2 as your Activity extends NavigationActivity.
Ah... Had tried that but wasn't working for me, now that I've tried again it does in fact work. Sorry!
@Slessi I have same problem.
Can you share your solotion? Thanks
setActivityCallbacks(new ActivityCallbacks() {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
mCallbackManager.onActivityResult(requestCode, resultCode, data);
}
});
// MainActivity.java
package com.your.app;
import android.content.Intent;
import com.reactnativenavigation.NavigationActivity;
public class MainActivity extends NavigationActivity {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
}
@Slessi Can you share MainActivity and MainApplication as callback for Facebook has to be called as
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new FBSDKPackage(mCallbackManager)
);
}
@rf1804 I haven't touched this since April, refer to previous comment
Can you @Slessi provide MainActivity and MainApplication code or if you can explain a little bit like as you shared the code is of MainActivity but callback manager is required to be included in MainApplication
@rf1804 You need a static method to access to the instance of the callbackManager:
public class MainApplication extends NavigationApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
Then you can use this code in the MainActivity class: https://github.com/wix/react-native-navigation/issues/3102#issuecomment-421543597
Most helpful comment
ActivityCallbacks are no longer needed in v2 as your Activity extends NavigationActivity.