Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
}
@mehdichamouma

This comment has been minimized.

Copy link

mehdichamouma commented Jul 7, 2016

Nice, thank you,
Shouldn't we call the super constructor in the "onActivityResult" method ?

@SudoPlz

This comment has been minimized.

Copy link

SudoPlz commented Jul 13, 2016

@mehdichamouma yes we should.

@frangeris

This comment has been minimized.

Copy link

frangeris commented Jul 15, 2016

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

This comment has been minimized.

Copy link
Owner Author

satya164 commented Jul 17, 2016

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

@kamek-pf

This comment has been minimized.

Copy link

kamek-pf commented Jul 21, 2016

@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

This comment has been minimized.

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

This comment has been minimized.

Copy link

thevishnupradeep commented Oct 16, 2016

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

This comment has been minimized.

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.

@ghost

This comment has been minimized.

Copy link

ghost 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
You can’t perform that action at this time.