Skip to content

Instantly share code, notes, and snippets.

@satya164
Last active December 2, 2016 20:03
Show Gist options
  • Save satya164/bc9e6f16f2d86a622e82ea795cc8292b to your computer and use it in GitHub Desktop.
Save satya164/bc9e6f16f2d86a622e82ea795cc8292b to your computer and use it in GitHub Desktop.
react-native-fbsdk in React Native 0.29.+
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "MyApp";
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
}
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager = new CallbackManager.Factory().create();
@Override
public void onCreate() {
FacebookSdk.sdkInitialize(this);
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new FBSDKPackage(mCallbackManager),
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
}
@SudoPlz
Copy link

SudoPlz commented Jul 13, 2016

@mehdichamouma yes we should.

@frangeris
Copy link

Thanks, works like a charm!

@mehdichamouma, @SudoPlz something like this?

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

@satya164
Copy link
Author

@mehdichamouma I think we don't need to. React Native doesn't do that internally either.

@kamek-pf
Copy link

@satya164 Turns out you absolutely need to. I lost a whole day because of this.
I'm using the react-native-google-signin package, they are firing a startActivityForResult.
If the call to super is omitted here, the onActivityResult on their side is never called and Google signin doesn't work.

I'm no sure why this happens, my Java is a little rusty, I'd definitely be interested in an explanation, if anyone can provide any :p

Anyway, the react-native-fbsdk docs are up to date now, hopefully no one else will stumble on this.

@berkayk
Copy link

berkayk commented Aug 8, 2016

Thanks for this gist, everything works fine but FBSDKPackage cannot be found. Is there any way to import that package? Thanks.

@thevishnupradeep
Copy link

Hi,
I am getting a strange error. Could anyone please help?

Native module AppStateModule tried to override AppStateModule for module name AppState. If this was your intention, return true from AppStateModule#canOverrideExistingModule()

page1

@thevishnupradeep
Copy link

thevishnupradeep commented Oct 16, 2016

Figured it out! It was my mistake. I tried to import MainReactPackage twice.

return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativePushNotificationPackage(),
new MainReactPackage(),
new FBSDKPackage(mCallbackManager)
);

Just gonna leave it here for anyone who runs into the same mistake.

@tetherit
Copy link

tetherit commented Dec 2, 2016

Thank you, that was helpful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment